Debian Codegraph @

RSPiX/Src/GREEN/Video/Win95/sampapp.cpp

raw
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2016 RWS Inc, All Rights Reserved
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of version 2 of the GNU General Public License as published by
7 // the Free Software Foundation
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19 // Sample/Test application for Video Library.
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "System.h"
23
24 #include "Blue.h"
25
26 #include "video.h"
27
28 #include "hot.h"
29
30 #include "wdisplay.h"
31
32 #define VIDEO_FILE "\\\\METRO\\PROJECTS\\MUPPETS\\BEAKER\\TEMPASSETS\\LOSER1.AVI"
33 #define CURSOR_FILE "\\\\METRO\\PROJECTS\\MUPPETS\\BEAKER\\TEMPASSETS\\HOTPTR.CUR"
34
35 ///////////////////////////////////////////////////////////////////////////////
36 //
37 // Hooks Blue's Display's Window Proc. Return non-zero to have Blue return
38 // your *plResult.
39 //
40 ///////////////////////////////////////////////////////////////////////////////
41 int16_t WinProcHook(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam,
42 LRESULT* plResult)
43 {
44 int16_t sRes = 0; // Assume normal processing.
45
46 switch (uiMsg)
47 {
48 case WM_SETCURSOR:
49 // TRACE("WinProcHook(): WM_SETCURSOR.\n");
50 // sRes = TRUE;
51 // *plResult = TRUE;
52 break;
53 }
54
55 return sRes;
56 }
57
58 ///////////////////////////////////////////////////////////////////////////////
59 //
60 // Waits for a mouse click (down, then up) on sButton { MOUSE_BUTTON_LEFT,
61 // MOUSE_BUTTON_RIGHT }.
62 //
63 ///////////////////////////////////////////////////////////////////////////////
64 static void WaitClick(int16_t sButton)
65 {
66 while (Blu_GetMouseButton(sButton) == MOUSE_BUTTON_UP)
67 {
68 Blu_System();
69 }
70
71 while (Blu_GetMouseButton(sButton) == MOUSE_BUTTON_DOWN)
72 {
73 Blu_System();
74 }
75 }
76
77 ///////////////////////////////////////////////////////////////////////////////
78 //
79 // Attempt to start or stop a video.
80 // Returns 0 on success.
81 //
82 ///////////////////////////////////////////////////////////////////////////////
83 #define MCI_TIME_OUT 500
84 #define MCI_RETRIES 3
85 static int16_t ToggleVideo(CVideo* pvideo)
86 {
87 int16_t sRes = 0; // Assume success.
88
89 Blu_HookWinProc(WinProcHook);
90
91 if (pvideo->IsPlaying() == TRUE)
92 {
93 pvideo->Stop();
94
95 if (pvideo->IsPlaying() == TRUE)
96 {
97 TRACE("ToggleVideo(): Video did not stop yet.\n");
98 sRes = -1;
99 }
100 else
101 {
102 pvideo->Close();
103 }
104 }
105 else
106 {
107 if (pvideo->Open(VIDEO_FILE, 0, 0, 1, 1, 0) == VIDEO_SUCCESS)
108 {
109 int16_t sRetries;
110 int32_t lEndTime = 0L;
111 for ( sRetries = 0;
112 sRetries < MCI_RETRIES && sRes == 0 && pvideo->IsPlaying() == FALSE;
113 )
114 {
115 if (lEndTime < Blu_GetTime())
116 {
117 if (++sRetries == MCI_RETRIES)
118 {
119 TRACE("ToggleVideo(): Exceeded max retries.\n");
120 }
121 else
122 {
123 if (pvideo->Play() == VIDEO_SUCCESS)
124 {
125 // Set next time.
126 lEndTime = Blu_GetTime() + MCI_TIME_OUT;
127 }
128 else
129 {
130 TRACE("ToggleVideo(): Play returned error.\n");
131 sRes = -2;
132 }
133 }
134 }
135
136 Blu_System();
137 }
138
139 if (pvideo->IsPlaying() == TRUE)
140 {
141 TRACE("ToggleVideo(): Took %d tries to start.\n", sRetries);
142 }
143 }
144 else
145 {
146 Blu_MsgBox(MB_ICN_STOP | MB_BUT_OK, "Sux!", "Unable to open <%s>.", VIDEO_FILE);
147 }
148 }
149
150 return sRes;
151 }
152
153 ///////////////////////////////////////////////////////////////////////////////
154 //
155 // Test video library functionality.
156 //
157 ///////////////////////////////////////////////////////////////////////////////
158 int16_t AppMain(void)
159 {
160 CVideo video;
161
162 if (Blu_CreateDisplay(640, 400, (int16_t)Blu_GetDisplayInfo(DI_MONITOR_COLORDEPTH))
163 == 0)
164 {
165 int16_t sButtonDn = FALSE;
166 CHot hot;
167
168 if (hot.Create(0, 0,
169 Blu_GetDisplayInfo(DI_MONITOR_WIDTH), Blu_GetDisplayInfo(DI_MONITOR_HEIGHT),
170 CURSOR_FILE) == 0)
171 {
172 hot.SetActive(TRUE);
173 }
174 else
175 {
176 TRACE("AppMain(): Unable to create hotbox.\n");
177 }
178
179 while (Blu_GetMouseButton(MOUSE_BUTTON_RIGHT) == MOUSE_BUTTON_UP)
180 {
181 if (Blu_GetMouseButton(MOUSE_BUTTON_LEFT) == MOUSE_BUTTON_DOWN)
182 {
183 sButtonDn = TRUE;
184 }
185 else
186 {
187 if (sButtonDn == TRUE)
188 {
189 ToggleVideo(&video);
190 sButtonDn = FALSE;
191 }
192 }
193
194 Blu_System();
195 }
196
197 while (Blu_GetMouseButton(MOUSE_BUTTON_RIGHT) == MOUSE_BUTTON_DOWN)
198 {
199 Blu_System();
200 }
201 }
202 else
203 {
204 Blu_MsgBox(MB_ICN_INFO | MB_BUT_OK, "Sux!", "Unable to create display.");
205 }
206
207 return 0;
208 }
209
210 ///////////////////////////////////////////////////////////////////////////////
211 // EOF.
212 ///////////////////////////////////////////////////////////////////////////////