1 | diff -rN scummvm-0.12.0/backends/platform/motoezx/events.cpp scummvm-0.12.0-a1200/backends/platform/motoezx/events.cpp
|
---|
2 | 0a1,583
|
---|
3 | > /* ScummVM - Graphic Adventure Engine
|
---|
4 | > *
|
---|
5 | > * ScummVM is the legal property of its developers, whose names
|
---|
6 | > * are too numerous to list here. Please refer to the COPYRIGHT
|
---|
7 | > * file distributed with this source distribution.
|
---|
8 | > *
|
---|
9 | > * This program is free software; you can redistribute it and/or
|
---|
10 | > * modify it under the terms of the GNU General Public License
|
---|
11 | > * as published by the Free Software Foundation; either version 2
|
---|
12 | > * of the License, or (at your option) any later version.
|
---|
13 | >
|
---|
14 | > * This program is distributed in the hope that it will be useful,
|
---|
15 | > * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | > * GNU General Public License for more details.
|
---|
18 | >
|
---|
19 | > * You should have received a copy of the GNU General Public License
|
---|
20 | > * along with this program; if not, write to the Free Software
|
---|
21 | > * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
---|
22 | > *
|
---|
23 | > * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-0-12-0/backends/platform/sdl/events.cpp $
|
---|
24 | > * $Id: events.cpp 32540 2008-06-04 17:20:25Z lordhoto $
|
---|
25 | > *
|
---|
26 | > */
|
---|
27 | >
|
---|
28 | > #include "backends/platform/motoezx/sdl.h"
|
---|
29 | > #include "common/util.h"
|
---|
30 | > #include "common/events.h"
|
---|
31 | >
|
---|
32 | > // FIXME move joystick defines out and replace with confile file options
|
---|
33 | > // we should really allow users to map any key to a joystick button
|
---|
34 | > #define JOY_DEADZONE 3200
|
---|
35 | >
|
---|
36 | > #ifndef __SYMBIAN32__ // Symbian wants dialog joystick i.e cursor for movement/selection
|
---|
37 | > #define JOY_ANALOG
|
---|
38 | > #endif
|
---|
39 | >
|
---|
40 | > // #define JOY_INVERT_Y
|
---|
41 | > #define JOY_XAXIS 0
|
---|
42 | > #define JOY_YAXIS 1
|
---|
43 | > // buttons
|
---|
44 | > #define JOY_BUT_LMOUSE 0
|
---|
45 | > #define JOY_BUT_RMOUSE 2
|
---|
46 | > #define JOY_BUT_ESCAPE 3
|
---|
47 | > #define JOY_BUT_PERIOD 1
|
---|
48 | > #define JOY_BUT_SPACE 4
|
---|
49 | > #define JOY_BUT_F5 5
|
---|
50 | >
|
---|
51 | >
|
---|
52 | >
|
---|
53 | >
|
---|
54 | > static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode)
|
---|
55 | > {
|
---|
56 | > if (key >= SDLK_F1 && key <= SDLK_F9) {
|
---|
57 | > return key - SDLK_F1 + Common::ASCII_F1;
|
---|
58 | > } else if (key >= SDLK_KP0 && key <= SDLK_KP9) {
|
---|
59 | > return key - SDLK_KP0 + '0';
|
---|
60 | > } else if (key >= SDLK_UP && key <= SDLK_PAGEDOWN) {
|
---|
61 | > return key;
|
---|
62 | > } else if (unicode) {
|
---|
63 | > return unicode;
|
---|
64 | > } else if (key >= 'a' && key <= 'z' && (mod & KMOD_SHIFT)) {
|
---|
65 | > return key & ~0x20;
|
---|
66 | > } else if (key >= SDLK_NUMLOCK && key <= SDLK_EURO) {
|
---|
67 | > return 0;
|
---|
68 | > }
|
---|
69 | > return key;
|
---|
70 | > }
|
---|
71 | >
|
---|
72 | > void OSystem_SDL::fillMouseEvent(Common::Event &event, int x, int y) {
|
---|
73 | > event.mouse.x = x;
|
---|
74 | > event.mouse.y = y;
|
---|
75 | >
|
---|
76 | > // Update the "keyboard mouse" coords
|
---|
77 | > _km.x = x;
|
---|
78 | > _km.y = y;
|
---|
79 | >
|
---|
80 | > // Adjust for the screen scaling
|
---|
81 | > if (!_overlayVisible) {
|
---|
82 | > event.mouse.x /= _scaleFactor;
|
---|
83 | > event.mouse.y /= _scaleFactor;
|
---|
84 | > if (_adjustAspectRatio)
|
---|
85 | > event.mouse.y = aspect2Real(event.mouse.y);
|
---|
86 | > }
|
---|
87 | > }
|
---|
88 | >
|
---|
89 | > void OSystem_SDL::handleKbdMouse() {
|
---|
90 | > uint32 curTime = getMillis();
|
---|
91 | > if (curTime >= _km.last_time + _km.delay_time) {
|
---|
92 | > _km.last_time = curTime;
|
---|
93 | > if (_km.x_down_count == 1) {
|
---|
94 | > _km.x_down_time = curTime;
|
---|
95 | > _km.x_down_count = 2;
|
---|
96 | > }
|
---|
97 | > if (_km.y_down_count == 1) {
|
---|
98 | > _km.y_down_time = curTime;
|
---|
99 | > _km.y_down_count = 2;
|
---|
100 | > }
|
---|
101 | >
|
---|
102 | > if (_km.x_vel || _km.y_vel) {
|
---|
103 | > if (_km.x_down_count) {
|
---|
104 | > if (curTime > _km.x_down_time + _km.delay_time * 12) {
|
---|
105 | > if (_km.x_vel > 0)
|
---|
106 | > _km.x_vel++;
|
---|
107 | > else
|
---|
108 | > _km.x_vel--;
|
---|
109 | > } else if (curTime > _km.x_down_time + _km.delay_time * 8) {
|
---|
110 | > if (_km.x_vel > 0)
|
---|
111 | > _km.x_vel = 5;
|
---|
112 | > else
|
---|
113 | > _km.x_vel = -5;
|
---|
114 | > }
|
---|
115 | > }
|
---|
116 | > if (_km.y_down_count) {
|
---|
117 | > if (curTime > _km.y_down_time + _km.delay_time * 12) {
|
---|
118 | > if (_km.y_vel > 0)
|
---|
119 | > _km.y_vel++;
|
---|
120 | > else
|
---|
121 | > _km.y_vel--;
|
---|
122 | > } else if (curTime > _km.y_down_time + _km.delay_time * 8) {
|
---|
123 | > if (_km.y_vel > 0)
|
---|
124 | > _km.y_vel = 5;
|
---|
125 | > else
|
---|
126 | > _km.y_vel = -5;
|
---|
127 | > }
|
---|
128 | > }
|
---|
129 | >
|
---|
130 | > _km.x += _km.x_vel;
|
---|
131 | > _km.y += _km.y_vel;
|
---|
132 | >
|
---|
133 | > if (_km.x < 0) {
|
---|
134 | > _km.x = 0;
|
---|
135 | > _km.x_vel = -1;
|
---|
136 | > _km.x_down_count = 1;
|
---|
137 | > } else if (_km.x > _km.x_max) {
|
---|
138 | > _km.x = _km.x_max;
|
---|
139 | > _km.x_vel = 1;
|
---|
140 | > _km.x_down_count = 1;
|
---|
141 | > }
|
---|
142 | >
|
---|
143 | > if (_km.y < 0) {
|
---|
144 | > _km.y = 0;
|
---|
145 | > _km.y_vel = -1;
|
---|
146 | > _km.y_down_count = 1;
|
---|
147 | > } else if (_km.y > _km.y_max) {
|
---|
148 | > _km.y = _km.y_max;
|
---|
149 | > _km.y_vel = 1;
|
---|
150 | > _km.y_down_count = 1;
|
---|
151 | > }
|
---|
152 | >
|
---|
153 | > SDL_WarpMouse((Uint16)_km.x, (Uint16)_km.y);
|
---|
154 | > }
|
---|
155 | > }
|
---|
156 | > }
|
---|
157 | >
|
---|
158 | > static byte SDLModToOSystemKeyFlags(SDLMod mod) {
|
---|
159 | > byte b = 0;
|
---|
160 | > #ifdef LINUPY
|
---|
161 | > // Yopy has no ALT key, steal the SHIFT key
|
---|
162 | > // (which isn't used much anyway)
|
---|
163 | > if (mod & KMOD_SHIFT)
|
---|
164 | > b |= Common::KBD_ALT;
|
---|
165 | > #else
|
---|
166 | > if (mod & KMOD_SHIFT)
|
---|
167 | > b |= Common::KBD_SHIFT;
|
---|
168 | > if (mod & KMOD_ALT)
|
---|
169 | > b |= Common::KBD_ALT;
|
---|
170 | > #endif
|
---|
171 | > if (mod & KMOD_CTRL)
|
---|
172 | > b |= Common::KBD_CTRL;
|
---|
173 | >
|
---|
174 | > return b;
|
---|
175 | > }
|
---|
176 | >
|
---|
177 | > bool OSystem_SDL::pollEvent(Common::Event &event) {
|
---|
178 | > SDL_Event ev;
|
---|
179 | > int axis;
|
---|
180 | > byte b = 0;
|
---|
181 | >
|
---|
182 | > handleKbdMouse();
|
---|
183 | >
|
---|
184 | > // If the screen mode changed, send an Common::EVENT_SCREEN_CHANGED
|
---|
185 | > if (_modeChanged) {
|
---|
186 | > _modeChanged = false;
|
---|
187 | > event.type = Common::EVENT_SCREEN_CHANGED;
|
---|
188 | > _screenChangeCount++;
|
---|
189 | > return true;
|
---|
190 | > }
|
---|
191 | >
|
---|
192 | > while (mySDL_PollEvent(&ev)) {
|
---|
193 | > switch (ev.type) {
|
---|
194 | > case SDL_KEYDOWN:{
|
---|
195 | > b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState());
|
---|
196 | >
|
---|
197 | > // Alt-Return and Alt-Enter toggle full screen mode
|
---|
198 | > if (b == Common::KBD_ALT && (ev.key.keysym.sym == SDLK_RETURN
|
---|
199 | > || ev.key.keysym.sym == SDLK_KP_ENTER)) {
|
---|
200 | > setFullscreenMode(!_fullscreen);
|
---|
201 | > #ifdef USE_OSD
|
---|
202 | > if (_fullscreen)
|
---|
203 | > displayMessageOnOSD("Fullscreen mode");
|
---|
204 | > else
|
---|
205 | > displayMessageOnOSD("Windowed mode");
|
---|
206 | > #endif
|
---|
207 | >
|
---|
208 | > break;
|
---|
209 | > }
|
---|
210 | >
|
---|
211 | > // Alt-S: Create a screenshot
|
---|
212 | > if (b == Common::KBD_ALT && ev.key.keysym.sym == 's') {
|
---|
213 | > char filename[20];
|
---|
214 | >
|
---|
215 | > for (int n = 0;; n++) {
|
---|
216 | > SDL_RWops *file;
|
---|
217 | >
|
---|
218 | > sprintf(filename, "scummvm%05d.bmp", n);
|
---|
219 | > file = SDL_RWFromFile(filename, "r");
|
---|
220 | > if (!file)
|
---|
221 | > break;
|
---|
222 | > SDL_RWclose(file);
|
---|
223 | > }
|
---|
224 | > if (saveScreenshot(filename))
|
---|
225 | > printf("Saved '%s'\n", filename);
|
---|
226 | > else
|
---|
227 | > printf("Could not save screenshot!\n");
|
---|
228 | > break;
|
---|
229 | > }
|
---|
230 | >
|
---|
231 | > // Ctrl-m toggles mouse capture
|
---|
232 | > if (b == Common::KBD_CTRL && ev.key.keysym.sym == 'm') {
|
---|
233 | > toggleMouseGrab();
|
---|
234 | > break;
|
---|
235 | > }
|
---|
236 | >
|
---|
237 | > #if defined(MACOSX)
|
---|
238 | > // On Macintosh', Cmd-Q quits
|
---|
239 | > if ((ev.key.keysym.mod & KMOD_META) && ev.key.keysym.sym == 'q') {
|
---|
240 | > event.type = Common::EVENT_QUIT;
|
---|
241 | > return true;
|
---|
242 | > }
|
---|
243 | > #elif defined(UNIX)
|
---|
244 | > // On other unices, Control-Q quits
|
---|
245 | > if ((ev.key.keysym.mod & KMOD_CTRL) && ev.key.keysym.sym == 'q') {
|
---|
246 | > event.type = Common::EVENT_QUIT;
|
---|
247 | > return true;
|
---|
248 | > }
|
---|
249 | > #else
|
---|
250 | > // Ctrl-z and Alt-X quit
|
---|
251 | > if ((b == Common::KBD_CTRL && ev.key.keysym.sym == 'z') || (b == Common::KBD_ALT && ev.key.keysym.sym == 'x')) {
|
---|
252 | > event.type = Common::EVENT_QUIT;
|
---|
253 | > return true;
|
---|
254 | > }
|
---|
255 | > #endif
|
---|
256 | >
|
---|
257 | > // Ctrl-Alt-<key> will change the GFX mode
|
---|
258 | > if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) {
|
---|
259 | >
|
---|
260 | > handleScalerHotkeys(ev.key);
|
---|
261 | > break;
|
---|
262 | > }
|
---|
263 | > const bool event_complete = remapKey(ev, event);
|
---|
264 | >
|
---|
265 | > if (event_complete)
|
---|
266 | > return true;
|
---|
267 | >
|
---|
268 | > event.type = Common::EVENT_KEYDOWN;
|
---|
269 | > event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym;
|
---|
270 | > event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
|
---|
271 | >
|
---|
272 | > return true;
|
---|
273 | > }
|
---|
274 | > case SDL_KEYUP:
|
---|
275 | > {
|
---|
276 | > const bool event_complete = remapKey(ev,event);
|
---|
277 | >
|
---|
278 | > if (event_complete)
|
---|
279 | > return true;
|
---|
280 | >
|
---|
281 | > event.type = Common::EVENT_KEYUP;
|
---|
282 | > event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym;
|
---|
283 | > event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
|
---|
284 | > b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState());
|
---|
285 | >
|
---|
286 | > // Ctrl-Alt-<key> will change the GFX mode
|
---|
287 | > if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) {
|
---|
288 | > // Swallow these key up events
|
---|
289 | > break;
|
---|
290 | > }
|
---|
291 | >
|
---|
292 | > return true;
|
---|
293 | > }
|
---|
294 | > case SDL_MOUSEMOTION:
|
---|
295 | > event.type = Common::EVENT_MOUSEMOVE;
|
---|
296 | > fillMouseEvent(event, ev.motion.x, ev.motion.y);
|
---|
297 | >
|
---|
298 | > setMousePos(event.mouse.x, event.mouse.y);
|
---|
299 | > return true;
|
---|
300 | >
|
---|
301 | > case SDL_MOUSEBUTTONDOWN:
|
---|
302 | > if (ev.button.button == SDL_BUTTON_LEFT)
|
---|
303 | > event.type = Common::EVENT_LBUTTONDOWN;
|
---|
304 | > else if (ev.button.button == SDL_BUTTON_RIGHT)
|
---|
305 | > event.type = Common::EVENT_RBUTTONDOWN;
|
---|
306 | > #if defined(SDL_BUTTON_WHEELUP) && defined(SDL_BUTTON_WHEELDOWN)
|
---|
307 | > else if (ev.button.button == SDL_BUTTON_WHEELUP)
|
---|
308 | > event.type = Common::EVENT_WHEELUP;
|
---|
309 | > else if (ev.button.button == SDL_BUTTON_WHEELDOWN)
|
---|
310 | > event.type = Common::EVENT_WHEELDOWN;
|
---|
311 | > #endif
|
---|
312 | > #if defined(SDL_BUTTON_MIDDLE)
|
---|
313 | > else if (ev.button.button == SDL_BUTTON_MIDDLE)
|
---|
314 | > event.type = Common::EVENT_MBUTTONDOWN;
|
---|
315 | > #endif
|
---|
316 | > else
|
---|
317 | > break;
|
---|
318 | >
|
---|
319 | > fillMouseEvent(event, ev.button.x, ev.button.y);
|
---|
320 | >
|
---|
321 | > return true;
|
---|
322 | >
|
---|
323 | > case SDL_MOUSEBUTTONUP:
|
---|
324 | > if (ev.button.button == SDL_BUTTON_LEFT)
|
---|
325 | > event.type = Common::EVENT_LBUTTONUP;
|
---|
326 | > else if (ev.button.button == SDL_BUTTON_RIGHT)
|
---|
327 | > event.type = Common::EVENT_RBUTTONUP;
|
---|
328 | > #if defined(SDL_BUTTON_MIDDLE)
|
---|
329 | > else if (ev.button.button == SDL_BUTTON_MIDDLE)
|
---|
330 | > event.type = Common::EVENT_MBUTTONUP;
|
---|
331 | > #endif
|
---|
332 | > else
|
---|
333 | > break;
|
---|
334 | > fillMouseEvent(event, ev.button.x, ev.button.y);
|
---|
335 | >
|
---|
336 | > return true;
|
---|
337 | >
|
---|
338 | > case SDL_JOYBUTTONDOWN:
|
---|
339 | > if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
---|
340 | > event.type = Common::EVENT_LBUTTONDOWN;
|
---|
341 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
342 | > } else if (ev.jbutton.button == JOY_BUT_RMOUSE) {
|
---|
343 | > event.type = Common::EVENT_RBUTTONDOWN;
|
---|
344 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
345 | > } else {
|
---|
346 | > event.type = Common::EVENT_KEYDOWN;
|
---|
347 | > switch (ev.jbutton.button) {
|
---|
348 | > case JOY_BUT_ESCAPE:
|
---|
349 | > event.kbd.keycode = Common::KEYCODE_ESCAPE;
|
---|
350 | > event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0);
|
---|
351 | > break;
|
---|
352 | > case JOY_BUT_PERIOD:
|
---|
353 | > event.kbd.keycode = Common::KEYCODE_PERIOD;
|
---|
354 | > event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0);
|
---|
355 | > break;
|
---|
356 | > case JOY_BUT_SPACE:
|
---|
357 | > event.kbd.keycode = Common::KEYCODE_SPACE;
|
---|
358 | > event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0);
|
---|
359 | > break;
|
---|
360 | > case JOY_BUT_F5:
|
---|
361 | > event.kbd.keycode = Common::KEYCODE_F5;
|
---|
362 | > event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
|
---|
363 | > break;
|
---|
364 | > }
|
---|
365 | > }
|
---|
366 | > return true;
|
---|
367 | >
|
---|
368 | > case SDL_JOYBUTTONUP:
|
---|
369 | > if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
---|
370 | > event.type = Common::EVENT_LBUTTONUP;
|
---|
371 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
372 | > } else if (ev.jbutton.button == JOY_BUT_RMOUSE) {
|
---|
373 | > event.type = Common::EVENT_RBUTTONUP;
|
---|
374 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
375 | > } else {
|
---|
376 | > event.type = Common::EVENT_KEYUP;
|
---|
377 | > switch (ev.jbutton.button) {
|
---|
378 | > case JOY_BUT_ESCAPE:
|
---|
379 | > event.kbd.keycode = Common::KEYCODE_ESCAPE;
|
---|
380 | > event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0);
|
---|
381 | > break;
|
---|
382 | > case JOY_BUT_PERIOD:
|
---|
383 | > event.kbd.keycode = Common::KEYCODE_PERIOD;
|
---|
384 | > event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0);
|
---|
385 | > break;
|
---|
386 | > case JOY_BUT_SPACE:
|
---|
387 | > event.kbd.keycode = Common::KEYCODE_SPACE;
|
---|
388 | > event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0);
|
---|
389 | > break;
|
---|
390 | > case JOY_BUT_F5:
|
---|
391 | > event.kbd.keycode = Common::KEYCODE_F5;
|
---|
392 | > event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
|
---|
393 | > break;
|
---|
394 | > }
|
---|
395 | > }
|
---|
396 | > return true;
|
---|
397 | >
|
---|
398 | > case SDL_JOYAXISMOTION:
|
---|
399 | > axis = ev.jaxis.value;
|
---|
400 | > if ( axis > JOY_DEADZONE) {
|
---|
401 | > axis -= JOY_DEADZONE;
|
---|
402 | > event.type = Common::EVENT_MOUSEMOVE;
|
---|
403 | > } else if ( axis < -JOY_DEADZONE ) {
|
---|
404 | > axis += JOY_DEADZONE;
|
---|
405 | > event.type = Common::EVENT_MOUSEMOVE;
|
---|
406 | > } else
|
---|
407 | > axis = 0;
|
---|
408 | >
|
---|
409 | > if ( ev.jaxis.axis == JOY_XAXIS) {
|
---|
410 | > #ifdef JOY_ANALOG
|
---|
411 | > _km.x_vel = axis/2000;
|
---|
412 | > _km.x_down_count = 0;
|
---|
413 | > #else
|
---|
414 | > if (axis != 0) {
|
---|
415 | > _km.x_vel = (axis > 0) ? 1:-1;
|
---|
416 | > _km.x_down_count = 1;
|
---|
417 | > } else {
|
---|
418 | > _km.x_vel = 0;
|
---|
419 | > _km.x_down_count = 0;
|
---|
420 | > }
|
---|
421 | > #endif
|
---|
422 | >
|
---|
423 | > } else if (ev.jaxis.axis == JOY_YAXIS) {
|
---|
424 | > #ifndef JOY_INVERT_Y
|
---|
425 | > axis = -axis;
|
---|
426 | > #endif
|
---|
427 | > #ifdef JOY_ANALOG
|
---|
428 | > _km.y_vel = -axis / 2000;
|
---|
429 | > _km.y_down_count = 0;
|
---|
430 | > #else
|
---|
431 | > if (axis != 0) {
|
---|
432 | > _km.y_vel = (-axis > 0) ? 1: -1;
|
---|
433 | > _km.y_down_count = 1;
|
---|
434 | > } else {
|
---|
435 | > _km.y_vel = 0;
|
---|
436 | > _km.y_down_count = 0;
|
---|
437 | > }
|
---|
438 | > #endif
|
---|
439 | > }
|
---|
440 | >
|
---|
441 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
442 | >
|
---|
443 | > return true;
|
---|
444 | >
|
---|
445 | > case SDL_VIDEOEXPOSE:
|
---|
446 | > _forceFull = true;
|
---|
447 | > break;
|
---|
448 | >
|
---|
449 | > case SDL_QUIT:
|
---|
450 | > event.type = Common::EVENT_QUIT;
|
---|
451 | > return true;
|
---|
452 | > }
|
---|
453 | > }
|
---|
454 | > return false;
|
---|
455 | > }
|
---|
456 | >
|
---|
457 | > bool OSystem_SDL::remapKey(SDL_Event &ev, Common::Event &event) {
|
---|
458 | > // Quit on MOD+Camera Key on A1200
|
---|
459 | > if (ev.key.keysym.sym == SDLK_e) {
|
---|
460 | > event.type = Common::EVENT_QUIT;
|
---|
461 | > return true;
|
---|
462 | > }
|
---|
463 | > // '1' Bypass security protection - MOD+Call key
|
---|
464 | > if (ev.key.keysym.sym == SDLK_f) {
|
---|
465 | > ev.key.keysym.sym=SDLK_1;
|
---|
466 | > }
|
---|
467 | > // F5 Game Menu - Call key
|
---|
468 | > else if (ev.key.keysym.sym == SDLK_SPACE) {
|
---|
469 | > ev.key.keysym.sym=SDLK_F5;
|
---|
470 | > }
|
---|
471 | > // '3' - Mod+Up key
|
---|
472 | > else if (ev.key.keysym.sym == SDLK_j) {
|
---|
473 | > ev.key.keysym.sym=SDLK_3;
|
---|
474 | > }
|
---|
475 | > // '6' - Mod+Down key
|
---|
476 | > else if (ev.key.keysym.sym == SDLK_i) {
|
---|
477 | > ev.key.keysym.sym=SDLK_6;
|
---|
478 | > // 'y' - Mod+Right key
|
---|
479 | > }
|
---|
480 | > else if (ev.key.keysym.sym == SDLK_g) {
|
---|
481 | > ev.key.keysym.sym=SDLK_y;
|
---|
482 | > }
|
---|
483 | > // 'n' - Mod+Left key
|
---|
484 | > else if (ev.key.keysym.sym == SDLK_h) {
|
---|
485 | > ev.key.keysym.sym=SDLK_n;
|
---|
486 | > }
|
---|
487 | > // A1200 Joystick to Mouse
|
---|
488 | > else if( ev.key.keysym.sym == SDLK_LEFT ) {
|
---|
489 | > if( ev.type == SDL_KEYDOWN ) {
|
---|
490 | > _km.x_vel = -1;
|
---|
491 | > _km.x_down_count = 1;
|
---|
492 | > }
|
---|
493 | > else {
|
---|
494 | > _km.x_vel = 0;
|
---|
495 | > _km.x_down_count = 0;
|
---|
496 | > }
|
---|
497 | >
|
---|
498 | > event.type = Common::EVENT_MOUSEMOVE;
|
---|
499 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
500 | > return true;
|
---|
501 | > }
|
---|
502 | > else if( ev.key.keysym.sym == SDLK_RIGHT ) {
|
---|
503 | > if( ev.type == SDL_KEYDOWN ) {
|
---|
504 | > _km.x_vel = 1;
|
---|
505 | > _km.x_down_count = 1;
|
---|
506 | > }
|
---|
507 | > else {
|
---|
508 | > _km.x_vel = 0;
|
---|
509 | > _km.x_down_count = 0;
|
---|
510 | > }
|
---|
511 | >
|
---|
512 | > event.type = Common::EVENT_MOUSEMOVE;
|
---|
513 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
514 | > return true;
|
---|
515 | > }
|
---|
516 | > else if( ev.key.keysym.sym == SDLK_DOWN ) {
|
---|
517 | > if( ev.type == SDL_KEYDOWN ) {
|
---|
518 | > _km.y_vel = 1;
|
---|
519 | > _km.y_down_count = 1;
|
---|
520 | > }
|
---|
521 | > else {
|
---|
522 | > _km.y_vel = 0;
|
---|
523 | > _km.y_down_count = 0;
|
---|
524 | > }
|
---|
525 | >
|
---|
526 | > event.type = Common::EVENT_MOUSEMOVE;
|
---|
527 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
528 | > return true;
|
---|
529 | > }
|
---|
530 | > else if( ev.key.keysym.sym == SDLK_UP ) {
|
---|
531 | > if( ev.type == SDL_KEYDOWN ) {
|
---|
532 | > _km.y_vel = -1;
|
---|
533 | > _km.y_down_count = 1;
|
---|
534 | > }
|
---|
535 | > else {
|
---|
536 | > _km.y_vel = 0;
|
---|
537 | > _km.y_down_count = 0;
|
---|
538 | > }
|
---|
539 | >
|
---|
540 | > event.type = Common::EVENT_MOUSEMOVE;
|
---|
541 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
542 | > return true;
|
---|
543 | > }
|
---|
544 | > // Volume Up to pressing Right Mouse
|
---|
545 | > else if ( ev.key.keysym.sym == SDLK_PLUS) {
|
---|
546 | > _km.y_vel = 0;
|
---|
547 | > _km.y_down_count = 0;
|
---|
548 | > event.type = Common::EVENT_RBUTTONDOWN;
|
---|
549 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
550 | > return true;
|
---|
551 | > }
|
---|
552 | > // Volume down to releasing right mouse
|
---|
553 | > else if ( ev.key.keysym.sym == SDLK_MINUS) {
|
---|
554 | > _km.y_vel = 0;
|
---|
555 | > _km.y_down_count = 0;
|
---|
556 | > event.type = Common::EVENT_RBUTTONUP;
|
---|
557 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
558 | > return true;
|
---|
559 | > }
|
---|
560 | > // MOD+Volume UP to releasing Right Mouse
|
---|
561 | > else if ( ev.key.keysym.sym == SDLK_c) {
|
---|
562 | > _km.y_vel = 0;
|
---|
563 | > _km.y_down_count = 0;
|
---|
564 | > event.type = Common::EVENT_RBUTTONUP;
|
---|
565 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
566 | > return true;
|
---|
567 | > }
|
---|
568 | > // Camera to releasing Left Mouse
|
---|
569 | > else if ( ev.key.keysym.sym == SDLK_PAUSE) {
|
---|
570 | > _km.y_vel = 0;
|
---|
571 | > _km.y_down_count = 0;
|
---|
572 | > event.type = Common::EVENT_LBUTTONUP;
|
---|
573 | > fillMouseEvent(event, _km.x, _km.y);
|
---|
574 | > return true;
|
---|
575 | > } else {
|
---|
576 | > // Let the events fall through if we didn't change them, this may not be the best way to
|
---|
577 | > // set it up, but i'm not sure how sdl would like it if we let if fall through then redid it though.
|
---|
578 | > // and yes i have an huge terminal size so i dont wrap soon enough.
|
---|
579 | > event.type = Common::EVENT_KEYDOWN;
|
---|
580 | > event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym;
|
---|
581 | > event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
|
---|
582 | > }
|
---|
583 | > return false;
|
---|
584 | > }
|
---|
585 | >
|
---|
586 | diff -rN scummvm-0.12.0/backends/platform/motoezx/graphics.cpp scummvm-0.12.0-a1200/backends/platform/motoezx/graphics.cpp
|
---|
587 | 0a1,1746
|
---|
588 | > /* ScummVM - Graphic Adventure Engine
|
---|
589 | > *
|
---|
590 | > * ScummVM is the legal property of its developers, whose names
|
---|
591 | > * are too numerous to list here. Please refer to the COPYRIGHT
|
---|
592 | > * file distributed with this source distribution.
|
---|
593 | > *
|
---|
594 | > * This program is free software; you can redistribute it and/or
|
---|
595 | > * modify it under the terms of the GNU General Public License
|
---|
596 | > * as published by the Free Software Foundation; either version 2
|
---|
597 | > * of the License, or (at your option) any later version.
|
---|
598 | >
|
---|
599 | > * This program is distributed in the hope that it will be useful,
|
---|
600 | > * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
601 | > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
602 | > * GNU General Public License for more details.
|
---|
603 | >
|
---|
604 | > * You should have received a copy of the GNU General Public License
|
---|
605 | > * along with this program; if not, write to the Free Software
|
---|
606 | > * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
---|
607 | > *
|
---|
608 | > * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-0-12-0/backends/platform/sdl/graphics.cpp $
|
---|
609 | > * $Id: graphics.cpp 31244 2008-03-26 19:29:33Z fingolfin $
|
---|
610 | > *
|
---|
611 | > */
|
---|
612 | >
|
---|
613 | > #include "backends/platform/motoezx/sdl.h"
|
---|
614 | > #include "common/util.h"
|
---|
615 | > #include "graphics/font.h"
|
---|
616 | > #include "graphics/fontman.h"
|
---|
617 | > #include "graphics/scaler.h"
|
---|
618 | > #include "graphics/surface.h"
|
---|
619 | >
|
---|
620 | > static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
|
---|
621 | > {"1x", "Normal (no scaling)", GFX_NORMAL},
|
---|
622 | > {"2x", "2x", GFX_DOUBLESIZE},
|
---|
623 | > {"3x", "3x", GFX_TRIPLESIZE},
|
---|
624 | > {"2xsai", "2xSAI", GFX_2XSAI},
|
---|
625 | > {"super2xsai", "Super2xSAI", GFX_SUPER2XSAI},
|
---|
626 | > {"supereagle", "SuperEagle", GFX_SUPEREAGLE},
|
---|
627 | > {"advmame2x", "AdvMAME2x", GFX_ADVMAME2X},
|
---|
628 | > {"advmame3x", "AdvMAME3x", GFX_ADVMAME3X},
|
---|
629 | > #ifndef DISABLE_HQ_SCALERS
|
---|
630 | > {"hq2x", "HQ2x", GFX_HQ2X},
|
---|
631 | > {"hq3x", "HQ3x", GFX_HQ3X},
|
---|
632 | > #endif
|
---|
633 | > {"tv2x", "TV2x", GFX_TV2X},
|
---|
634 | > {"dotmatrix", "DotMatrix", GFX_DOTMATRIX},
|
---|
635 | > {0, 0, 0}
|
---|
636 | > };
|
---|
637 | >
|
---|
638 | > // Table of relative scalers magnitudes
|
---|
639 | > // [definedScale - 1][_scaleFactor - 1]
|
---|
640 | > static ScalerProc *scalersMagn[3][3] = {
|
---|
641 | > #ifndef DISABLE_SCALERS
|
---|
642 | > { Normal1x, AdvMame2x, AdvMame3x },
|
---|
643 | > { Normal1x, Normal1x, Normal1o5x },
|
---|
644 | > { Normal1x, Normal1x, Normal1x }
|
---|
645 | > #else // remove dependencies on other scalers
|
---|
646 | > { Normal1x, Normal1x, Normal1x },
|
---|
647 | > { Normal1x, Normal1x, Normal1x },
|
---|
648 | > { Normal1x, Normal1x, Normal1x }
|
---|
649 | > #endif
|
---|
650 | > };
|
---|
651 | >
|
---|
652 | > static const int s_gfxModeSwitchTable[][4] = {
|
---|
653 | > { GFX_NORMAL, GFX_DOUBLESIZE, GFX_TRIPLESIZE, -1 },
|
---|
654 | > { GFX_NORMAL, GFX_ADVMAME2X, GFX_ADVMAME3X, -1 },
|
---|
655 | > { GFX_NORMAL, GFX_HQ2X, GFX_HQ3X, -1 },
|
---|
656 | > { GFX_NORMAL, GFX_2XSAI, -1, -1 },
|
---|
657 | > { GFX_NORMAL, GFX_SUPER2XSAI, -1, -1 },
|
---|
658 | > { GFX_NORMAL, GFX_SUPEREAGLE, -1, -1 },
|
---|
659 | > { GFX_NORMAL, GFX_TV2X, -1, -1 },
|
---|
660 | > { GFX_NORMAL, GFX_DOTMATRIX, -1, -1 }
|
---|
661 | > };
|
---|
662 | >
|
---|
663 | > #ifndef DISABLE_SCALERS
|
---|
664 | > static int cursorStretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY);
|
---|
665 | > #endif
|
---|
666 | >
|
---|
667 | > const OSystem::GraphicsMode *OSystem_SDL::getSupportedGraphicsModes() const {
|
---|
668 | > return s_supportedGraphicsModes;
|
---|
669 | > }
|
---|
670 | >
|
---|
671 | > int OSystem_SDL::getDefaultGraphicsMode() const {
|
---|
672 | > return GFX_DOUBLESIZE;
|
---|
673 | > }
|
---|
674 | >
|
---|
675 | > void OSystem_SDL::beginGFXTransaction(void) {
|
---|
676 | > assert (_transactionMode == kTransactionNone);
|
---|
677 | >
|
---|
678 | > _transactionMode = kTransactionActive;
|
---|
679 | >
|
---|
680 | > _transactionDetails.modeChanged = false;
|
---|
681 | > _transactionDetails.sizeChanged = false;
|
---|
682 | > _transactionDetails.arChanged = false;
|
---|
683 | > _transactionDetails.fsChanged = false;
|
---|
684 | >
|
---|
685 | > _transactionDetails.needHotswap = false;
|
---|
686 | > _transactionDetails.needUpdatescreen = false;
|
---|
687 | > _transactionDetails.needUnload = false;
|
---|
688 | >
|
---|
689 | > _transactionDetails.normal1xScaler = false;
|
---|
690 | > }
|
---|
691 | >
|
---|
692 | > void OSystem_SDL::endGFXTransaction(void) {
|
---|
693 | > // for each engine we run initCommonGFX() as first thing in the transaction
|
---|
694 | > // and initSize() is called later. If user runs launcher at 320x200 with
|
---|
695 | > // 2x overlay, setting to Nomral1x sclaler in that case will be suppressed
|
---|
696 | > // and backend is forced to 2x
|
---|
697 | > //
|
---|
698 | > // This leads to bad results such as 1280x960 window for 640x480 engines.
|
---|
699 | > // To prevent that we rerun setGraphicsMode() if there was 1x scaler request
|
---|
700 | > if (_transactionDetails.normal1xScaler)
|
---|
701 | > setGraphicsMode(GFX_NORMAL);
|
---|
702 | >
|
---|
703 | > assert (_transactionMode == kTransactionActive);
|
---|
704 | >
|
---|
705 | > _transactionMode = kTransactionCommit;
|
---|
706 | > if (_transactionDetails.modeChanged)
|
---|
707 | > setGraphicsMode(_transactionDetails.mode);
|
---|
708 | >
|
---|
709 | > if (_transactionDetails.sizeChanged)
|
---|
710 | > initSize(_transactionDetails.w, _transactionDetails.h);
|
---|
711 | >
|
---|
712 | > if (_transactionDetails.arChanged)
|
---|
713 | > setAspectRatioCorrection(_transactionDetails.ar);
|
---|
714 | >
|
---|
715 | > if (_transactionDetails.needUnload) {
|
---|
716 | > unloadGFXMode();
|
---|
717 | > loadGFXMode();
|
---|
718 | > clearOverlay();
|
---|
719 | > } else {
|
---|
720 | > if (!_transactionDetails.fsChanged) {
|
---|
721 | > if (_transactionDetails.needHotswap)
|
---|
722 | > hotswapGFXMode();
|
---|
723 | > else if (_transactionDetails.needUpdatescreen)
|
---|
724 | > internUpdateScreen();
|
---|
725 | > }
|
---|
726 | > }
|
---|
727 | >
|
---|
728 | > if (_transactionDetails.fsChanged)
|
---|
729 | > setFullscreenMode(_transactionDetails.fs);
|
---|
730 | >
|
---|
731 | > _transactionMode = kTransactionNone;
|
---|
732 | > }
|
---|
733 | >
|
---|
734 | > bool OSystem_SDL::setGraphicsMode(int mode) {
|
---|
735 | > Common::StackLock lock(_graphicsMutex);
|
---|
736 | >
|
---|
737 | > int newScaleFactor = 1;
|
---|
738 | > ScalerProc *newScalerProc;
|
---|
739 | >
|
---|
740 | > switch(mode) {
|
---|
741 | > case GFX_NORMAL:
|
---|
742 | > newScaleFactor = 1;
|
---|
743 | > newScalerProc = Normal1x;
|
---|
744 | > break;
|
---|
745 | > #ifndef DISABLE_SCALERS
|
---|
746 | > case GFX_DOUBLESIZE:
|
---|
747 | > newScaleFactor = 2;
|
---|
748 | > newScalerProc = Normal2x;
|
---|
749 | > break;
|
---|
750 | > case GFX_TRIPLESIZE:
|
---|
751 | > newScaleFactor = 3;
|
---|
752 | > newScalerProc = Normal3x;
|
---|
753 | > break;
|
---|
754 | >
|
---|
755 | > case GFX_2XSAI:
|
---|
756 | > newScaleFactor = 2;
|
---|
757 | > newScalerProc = _2xSaI;
|
---|
758 | > break;
|
---|
759 | > case GFX_SUPER2XSAI:
|
---|
760 | > newScaleFactor = 2;
|
---|
761 | > newScalerProc = Super2xSaI;
|
---|
762 | > break;
|
---|
763 | > case GFX_SUPEREAGLE:
|
---|
764 | > newScaleFactor = 2;
|
---|
765 | > newScalerProc = SuperEagle;
|
---|
766 | > break;
|
---|
767 | > case GFX_ADVMAME2X:
|
---|
768 | > newScaleFactor = 2;
|
---|
769 | > newScalerProc = AdvMame2x;
|
---|
770 | > break;
|
---|
771 | > case GFX_ADVMAME3X:
|
---|
772 | > newScaleFactor = 3;
|
---|
773 | > newScalerProc = AdvMame3x;
|
---|
774 | > break;
|
---|
775 | > #ifndef DISABLE_HQ_SCALERS
|
---|
776 | > case GFX_HQ2X:
|
---|
777 | > newScaleFactor = 2;
|
---|
778 | > newScalerProc = HQ2x;
|
---|
779 | > break;
|
---|
780 | > case GFX_HQ3X:
|
---|
781 | > newScaleFactor = 3;
|
---|
782 | > newScalerProc = HQ3x;
|
---|
783 | > break;
|
---|
784 | > #endif
|
---|
785 | > case GFX_TV2X:
|
---|
786 | > newScaleFactor = 2;
|
---|
787 | > newScalerProc = TV2x;
|
---|
788 | > break;
|
---|
789 | > case GFX_DOTMATRIX:
|
---|
790 | > newScaleFactor = 2;
|
---|
791 | > newScalerProc = DotMatrix;
|
---|
792 | > break;
|
---|
793 | > #endif // DISABLE_SCALERS
|
---|
794 | >
|
---|
795 | > default:
|
---|
796 | > warning("unknown gfx mode %d", mode);
|
---|
797 | > return false;
|
---|
798 | > }
|
---|
799 | >
|
---|
800 | > _transactionDetails.normal1xScaler = (mode == GFX_NORMAL);
|
---|
801 | >
|
---|
802 | > _mode = mode;
|
---|
803 | > _scalerProc = newScalerProc;
|
---|
804 | >
|
---|
805 | > if (_transactionMode == kTransactionActive) {
|
---|
806 | > _transactionDetails.mode = mode;
|
---|
807 | > _transactionDetails.modeChanged = true;
|
---|
808 | >
|
---|
809 | > if (newScaleFactor != _scaleFactor) {
|
---|
810 | > _transactionDetails.needHotswap = true;
|
---|
811 | > _scaleFactor = newScaleFactor;
|
---|
812 | > }
|
---|
813 | >
|
---|
814 | > _transactionDetails.needUpdatescreen = true;
|
---|
815 | >
|
---|
816 | > return true;
|
---|
817 | > }
|
---|
818 | >
|
---|
819 | > // NOTE: This should not be executed at transaction commit
|
---|
820 | > // Otherwise there is some unsolicited setGraphicsMode() call
|
---|
821 | > // which should be properly removed
|
---|
822 | > if (newScaleFactor != _scaleFactor) {
|
---|
823 | > assert(_transactionMode != kTransactionCommit);
|
---|
824 | >
|
---|
825 | > _scaleFactor = newScaleFactor;
|
---|
826 | > hotswapGFXMode();
|
---|
827 | > }
|
---|
828 | >
|
---|
829 | > // Determine the "scaler type", i.e. essentially an index into the
|
---|
830 | > // s_gfxModeSwitchTable array defined in events.cpp.
|
---|
831 | > if (_mode != GFX_NORMAL) {
|
---|
832 | > for (int i = 0; i < ARRAYSIZE(s_gfxModeSwitchTable); i++) {
|
---|
833 | > if (s_gfxModeSwitchTable[i][1] == _mode || s_gfxModeSwitchTable[i][2] == _mode) {
|
---|
834 | > _scalerType = i;
|
---|
835 | > break;
|
---|
836 | > }
|
---|
837 | > }
|
---|
838 | > }
|
---|
839 | >
|
---|
840 | > if (!_screen)
|
---|
841 | > return true;
|
---|
842 | >
|
---|
843 | > // Blit everything to the screen
|
---|
844 | > _forceFull = true;
|
---|
845 | >
|
---|
846 | > // Even if the old and new scale factors are the same, we may have a
|
---|
847 | > // different scaler for the cursor now.
|
---|
848 | > blitCursor();
|
---|
849 | >
|
---|
850 | > if (_transactionMode != kTransactionCommit)
|
---|
851 | > internUpdateScreen();
|
---|
852 | >
|
---|
853 | > // Make sure that an Common::EVENT_SCREEN_CHANGED gets sent later
|
---|
854 | > _modeChanged = true;
|
---|
855 | >
|
---|
856 | > return true;
|
---|
857 | > }
|
---|
858 | >
|
---|
859 | > int OSystem_SDL::getGraphicsMode() const {
|
---|
860 | > assert (_transactionMode == kTransactionNone);
|
---|
861 | > return _mode;
|
---|
862 | > }
|
---|
863 | >
|
---|
864 | > void OSystem_SDL::initSize(uint w, uint h) {
|
---|
865 | > // Avoid redundant res changes
|
---|
866 | > if ((int)w == _screenWidth && (int)h == _screenHeight &&
|
---|
867 | > _transactionMode != kTransactionCommit)
|
---|
868 | > return;
|
---|
869 | >
|
---|
870 | > _screenWidth = w;
|
---|
871 | > _screenHeight = h;
|
---|
872 | >
|
---|
873 | > _cksumNum = (_screenWidth * _screenHeight / (8 * 8));
|
---|
874 | >
|
---|
875 | > if (_transactionMode == kTransactionActive) {
|
---|
876 | > _transactionDetails.w = w;
|
---|
877 | > _transactionDetails.h = h;
|
---|
878 | > _transactionDetails.sizeChanged = true;
|
---|
879 | >
|
---|
880 | > _transactionDetails.needUnload = true;
|
---|
881 | >
|
---|
882 | > return;
|
---|
883 | > }
|
---|
884 | >
|
---|
885 | > free(_dirtyChecksums);
|
---|
886 | > _dirtyChecksums = (uint32 *)calloc(_cksumNum * 2, sizeof(uint32));
|
---|
887 | >
|
---|
888 | > if (_transactionMode != kTransactionCommit) {
|
---|
889 | > unloadGFXMode();
|
---|
890 | > loadGFXMode();
|
---|
891 | >
|
---|
892 | > // if initSize() gets called in the middle, overlay is not transparent
|
---|
893 | > clearOverlay();
|
---|
894 | > }
|
---|
895 | > }
|
---|
896 | >
|
---|
897 | > void OSystem_SDL::loadGFXMode() {
|
---|
898 | > assert(_inited);
|
---|
899 | > _forceFull = true;
|
---|
900 | >
|
---|
901 | > int hwW, hwH;
|
---|
902 | >
|
---|
903 | > #ifndef __MAEMO__
|
---|
904 | > _overlayWidth = _screenWidth * _scaleFactor;
|
---|
905 | > _overlayHeight = _screenHeight * _scaleFactor;
|
---|
906 | >
|
---|
907 | > if (_screenHeight != 200 && _screenHeight != 400)
|
---|
908 | > _adjustAspectRatio = false;
|
---|
909 | >
|
---|
910 | > if (_adjustAspectRatio)
|
---|
911 | > _overlayHeight = real2Aspect(_overlayHeight);
|
---|
912 | >
|
---|
913 | > hwW = _screenWidth * _scaleFactor;
|
---|
914 | > hwH = effectiveScreenHeight();
|
---|
915 | > #else
|
---|
916 | > hwW = _overlayWidth;
|
---|
917 | > hwH = _overlayHeight;
|
---|
918 | > #endif
|
---|
919 | >
|
---|
920 | > //
|
---|
921 | > // Create the surface that contains the 8 bit game data
|
---|
922 | > //
|
---|
923 | > _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth, _screenHeight, 8, 0, 0, 0, 0);
|
---|
924 | > if (_screen == NULL)
|
---|
925 | > error("allocating _screen failed");
|
---|
926 | >
|
---|
927 | > //
|
---|
928 | > // Create the surface that contains the scaled graphics in 16 bit mode
|
---|
929 | > //
|
---|
930 | >
|
---|
931 | > _hwscreen = SDL_SetVideoMode(hwW, hwH, 16,
|
---|
932 | > _fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
|
---|
933 | > );
|
---|
934 | > if (_hwscreen == NULL) {
|
---|
935 | > // DON'T use error(), as this tries to bring up the debug
|
---|
936 | > // console, which WON'T WORK now that _hwscreen is hosed.
|
---|
937 | >
|
---|
938 | > // FIXME: We should be able to continue the game without
|
---|
939 | > // shutting down or bringing up the debug console, but at
|
---|
940 | > // this point we've already screwed up all our member vars.
|
---|
941 | > // We need to find a way to call SDL_SetVideoMode *before*
|
---|
942 | > // that happens and revert to all the old settings if we
|
---|
943 | > // can't pull off the switch to the new settings.
|
---|
944 | > //
|
---|
945 | > // Fingolfin says: the "easy" way to do that is not to modify
|
---|
946 | > // the member vars before we are sure everything is fine. Think
|
---|
947 | > // of "transactions, commit, rollback" style... we use local vars
|
---|
948 | > // in place of the member vars, do everything etc. etc.. In case
|
---|
949 | > // of a failure, rollback is trivial. Only if everything worked fine
|
---|
950 | > // do we "commit" the changed values to the member vars.
|
---|
951 | > warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError());
|
---|
952 | > quit();
|
---|
953 | > }
|
---|
954 | >
|
---|
955 | > //
|
---|
956 | > // Create the surface used for the graphics in 16 bit before scaling, and also the overlay
|
---|
957 | > //
|
---|
958 | >
|
---|
959 | > // Distinguish 555 and 565 mode
|
---|
960 | > if (_hwscreen->format->Rmask == 0x7C00)
|
---|
961 | > InitScalers(555);
|
---|
962 | > else
|
---|
963 | > InitScalers(565);
|
---|
964 | >
|
---|
965 | > // Need some extra bytes around when using 2xSaI
|
---|
966 | > _tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth + 3, _screenHeight + 3,
|
---|
967 | > 16,
|
---|
968 | > _hwscreen->format->Rmask,
|
---|
969 | > _hwscreen->format->Gmask,
|
---|
970 | > _hwscreen->format->Bmask,
|
---|
971 | > _hwscreen->format->Amask);
|
---|
972 | >
|
---|
973 | > if (_tmpscreen == NULL)
|
---|
974 | > error("allocating _tmpscreen failed");
|
---|
975 | >
|
---|
976 | > _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight,
|
---|
977 | > 16,
|
---|
978 | > _hwscreen->format->Rmask,
|
---|
979 | > _hwscreen->format->Gmask,
|
---|
980 | > _hwscreen->format->Bmask,
|
---|
981 | > _hwscreen->format->Amask);
|
---|
982 | >
|
---|
983 | > if (_overlayscreen == NULL)
|
---|
984 | > error("allocating _overlayscreen failed");
|
---|
985 | >
|
---|
986 | > _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth + 3, _overlayHeight + 3,
|
---|
987 | > 16,
|
---|
988 | > _hwscreen->format->Rmask,
|
---|
989 | > _hwscreen->format->Gmask,
|
---|
990 | > _hwscreen->format->Bmask,
|
---|
991 | > _hwscreen->format->Amask);
|
---|
992 | >
|
---|
993 | > if (_tmpscreen2 == NULL)
|
---|
994 | > error("allocating _tmpscreen2 failed");
|
---|
995 | >
|
---|
996 | > #ifdef USE_OSD
|
---|
997 | > _osdSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
|
---|
998 | > _hwscreen->w,
|
---|
999 | > _hwscreen->h,
|
---|
1000 | > 16,
|
---|
1001 | > _hwscreen->format->Rmask,
|
---|
1002 | > _hwscreen->format->Gmask,
|
---|
1003 | > _hwscreen->format->Bmask,
|
---|
1004 | > _hwscreen->format->Amask);
|
---|
1005 | > if (_osdSurface == NULL)
|
---|
1006 | > error("allocating _osdSurface failed");
|
---|
1007 | > SDL_SetColorKey(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kOSDColorKey);
|
---|
1008 | > #endif
|
---|
1009 | >
|
---|
1010 | > // keyboard cursor control, some other better place for it?
|
---|
1011 | > _km.x_max = _screenWidth * _scaleFactor - 1;
|
---|
1012 | > _km.y_max = effectiveScreenHeight() - 1;
|
---|
1013 | > _km.delay_time = 25;
|
---|
1014 | > _km.last_time = 0;
|
---|
1015 | > }
|
---|
1016 | >
|
---|
1017 | > void OSystem_SDL::unloadGFXMode() {
|
---|
1018 | > if (_screen) {
|
---|
1019 | > SDL_FreeSurface(_screen);
|
---|
1020 | > _screen = NULL;
|
---|
1021 | > }
|
---|
1022 | >
|
---|
1023 | > if (_hwscreen) {
|
---|
1024 | > SDL_FreeSurface(_hwscreen);
|
---|
1025 | > _hwscreen = NULL;
|
---|
1026 | > }
|
---|
1027 | >
|
---|
1028 | > if (_tmpscreen) {
|
---|
1029 | > SDL_FreeSurface(_tmpscreen);
|
---|
1030 | > _tmpscreen = NULL;
|
---|
1031 | > }
|
---|
1032 | >
|
---|
1033 | > if (_tmpscreen2) {
|
---|
1034 | > SDL_FreeSurface(_tmpscreen2);
|
---|
1035 | > _tmpscreen2 = NULL;
|
---|
1036 | > }
|
---|
1037 | >
|
---|
1038 | > if (_overlayscreen) {
|
---|
1039 | > SDL_FreeSurface(_overlayscreen);
|
---|
1040 | > _overlayscreen = NULL;
|
---|
1041 | > }
|
---|
1042 | >
|
---|
1043 | > #ifdef USE_OSD
|
---|
1044 | > if (_osdSurface) {
|
---|
1045 | > SDL_FreeSurface(_osdSurface);
|
---|
1046 | > _osdSurface = NULL;
|
---|
1047 | > }
|
---|
1048 | > #endif
|
---|
1049 | > DestroyScalers();
|
---|
1050 | > }
|
---|
1051 | >
|
---|
1052 | > void OSystem_SDL::hotswapGFXMode() {
|
---|
1053 | > if (!_screen)
|
---|
1054 | > return;
|
---|
1055 | >
|
---|
1056 | > // Keep around the old _screen & _overlayscreen so we can restore the screen data
|
---|
1057 | > // after the mode switch.
|
---|
1058 | > SDL_Surface *old_screen = _screen;
|
---|
1059 | > SDL_Surface *old_overlayscreen = _overlayscreen;
|
---|
1060 | >
|
---|
1061 | > // Release the HW screen surface
|
---|
1062 | > SDL_FreeSurface(_hwscreen);
|
---|
1063 | >
|
---|
1064 | > SDL_FreeSurface(_tmpscreen);
|
---|
1065 | > SDL_FreeSurface(_tmpscreen2);
|
---|
1066 | >
|
---|
1067 | > #ifdef USE_OSD
|
---|
1068 | > // Release the OSD surface
|
---|
1069 | > SDL_FreeSurface(_osdSurface);
|
---|
1070 | > #endif
|
---|
1071 | >
|
---|
1072 | > // Setup the new GFX mode
|
---|
1073 | > loadGFXMode();
|
---|
1074 | >
|
---|
1075 | > // reset palette
|
---|
1076 | > SDL_SetColors(_screen, _currentPalette, 0, 256);
|
---|
1077 | >
|
---|
1078 | > // Restore old screen content
|
---|
1079 | > SDL_BlitSurface(old_screen, NULL, _screen, NULL);
|
---|
1080 | > SDL_BlitSurface(old_overlayscreen, NULL, _overlayscreen, NULL);
|
---|
1081 | >
|
---|
1082 | > // Free the old surfaces
|
---|
1083 | > SDL_FreeSurface(old_screen);
|
---|
1084 | > SDL_FreeSurface(old_overlayscreen);
|
---|
1085 | >
|
---|
1086 | > // Update cursor to new scale
|
---|
1087 | > blitCursor();
|
---|
1088 | >
|
---|
1089 | > // Blit everything to the screen
|
---|
1090 | > internUpdateScreen();
|
---|
1091 | >
|
---|
1092 | > // Make sure that an Common::EVENT_SCREEN_CHANGED gets sent later
|
---|
1093 | > _modeChanged = true;
|
---|
1094 | > }
|
---|
1095 | >
|
---|
1096 | > void OSystem_SDL::updateScreen() {
|
---|
1097 | > assert (_transactionMode == kTransactionNone);
|
---|
1098 | >
|
---|
1099 | > Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends
|
---|
1100 | >
|
---|
1101 | > internUpdateScreen();
|
---|
1102 | > }
|
---|
1103 | >
|
---|
1104 | > void OSystem_SDL::internUpdateScreen() {
|
---|
1105 | > SDL_Surface *srcSurf, *origSurf;
|
---|
1106 | > int height, width;
|
---|
1107 | > ScalerProc *scalerProc;
|
---|
1108 | > int scale1;
|
---|
1109 | >
|
---|
1110 | > #if defined (DEBUG) && ! defined(_WIN32_WCE) // definitions not available for non-DEBUG here. (needed this to compile in SYMBIAN32 & linux?)
|
---|
1111 | > assert(_hwscreen != NULL);
|
---|
1112 | > assert(_hwscreen->map->sw_data != NULL);
|
---|
1113 | > #endif
|
---|
1114 | >
|
---|
1115 | > // If the shake position changed, fill the dirty area with blackness
|
---|
1116 | > if (_currentShakePos != _newShakePos) {
|
---|
1117 | > SDL_Rect blackrect = {0, 0, _screenWidth * _scaleFactor, _newShakePos * _scaleFactor};
|
---|
1118 | >
|
---|
1119 | > if (_adjustAspectRatio && !_overlayVisible)
|
---|
1120 | > blackrect.h = real2Aspect(blackrect.h - 1) + 1;
|
---|
1121 | >
|
---|
1122 | > SDL_FillRect(_hwscreen, &blackrect, 0);
|
---|
1123 | >
|
---|
1124 | > _currentShakePos = _newShakePos;
|
---|
1125 | >
|
---|
1126 | > _forceFull = true;
|
---|
1127 | > }
|
---|
1128 | >
|
---|
1129 | > // Check whether the palette was changed in the meantime and update the
|
---|
1130 | > // screen surface accordingly.
|
---|
1131 | > if (_screen && _paletteDirtyEnd != 0) {
|
---|
1132 | > SDL_SetColors(_screen, _currentPalette + _paletteDirtyStart,
|
---|
1133 | > _paletteDirtyStart,
|
---|
1134 | > _paletteDirtyEnd - _paletteDirtyStart);
|
---|
1135 | >
|
---|
1136 | > _paletteDirtyEnd = 0;
|
---|
1137 | >
|
---|
1138 | > _forceFull = true;
|
---|
1139 | > }
|
---|
1140 | >
|
---|
1141 | > #ifdef USE_OSD
|
---|
1142 | > // OSD visible (i.e. non-transparent)?
|
---|
1143 | > if (_osdAlpha != SDL_ALPHA_TRANSPARENT) {
|
---|
1144 | > // Updated alpha value
|
---|
1145 | > const int diff = st_get_ticks() - _osdFadeStartTime;
|
---|
1146 | > if (diff > 0) {
|
---|
1147 | > if (diff >= kOSDFadeOutDuration) {
|
---|
1148 | > // Back to full transparency
|
---|
1149 | > _osdAlpha = SDL_ALPHA_TRANSPARENT;
|
---|
1150 | > } else {
|
---|
1151 | > // Do a linear fade out...
|
---|
1152 | > const int startAlpha = SDL_ALPHA_TRANSPARENT + kOSDInitialAlpha * (SDL_ALPHA_OPAQUE - SDL_ALPHA_TRANSPARENT) / 100;
|
---|
1153 | > _osdAlpha = startAlpha + diff * (SDL_ALPHA_TRANSPARENT - startAlpha) / kOSDFadeOutDuration;
|
---|
1154 | > }
|
---|
1155 | > SDL_SetAlpha(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _osdAlpha);
|
---|
1156 | > _forceFull = true;
|
---|
1157 | > }
|
---|
1158 | > }
|
---|
1159 | > #endif
|
---|
1160 | >
|
---|
1161 | > if (!_overlayVisible) {
|
---|
1162 | > origSurf = _screen;
|
---|
1163 | > srcSurf = _tmpscreen;
|
---|
1164 | > width = _screenWidth;
|
---|
1165 | > height = _screenHeight;
|
---|
1166 | > scalerProc = _scalerProc;
|
---|
1167 | > scale1 = _scaleFactor;
|
---|
1168 | > } else {
|
---|
1169 | > origSurf = _overlayscreen;
|
---|
1170 | > srcSurf = _tmpscreen2;
|
---|
1171 | > width = _overlayWidth;
|
---|
1172 | > height = _overlayHeight;
|
---|
1173 | > scalerProc = Normal1x;
|
---|
1174 | >
|
---|
1175 | > scale1 = 1;
|
---|
1176 | > }
|
---|
1177 | >
|
---|
1178 | > // Force a full redraw if requested
|
---|
1179 | > if (_forceFull) {
|
---|
1180 | > _numDirtyRects = 1;
|
---|
1181 | > _dirtyRectList[0].x = 0;
|
---|
1182 | > _dirtyRectList[0].y = 0;
|
---|
1183 | > _dirtyRectList[0].w = width;
|
---|
1184 | > _dirtyRectList[0].h = height;
|
---|
1185 | > } else
|
---|
1186 | > undrawMouse();
|
---|
1187 | >
|
---|
1188 | > // Only draw anything if necessary
|
---|
1189 | > if (_numDirtyRects > 0) {
|
---|
1190 | >
|
---|
1191 | > SDL_Rect *r;
|
---|
1192 | > SDL_Rect dst;
|
---|
1193 | > uint32 srcPitch, dstPitch;
|
---|
1194 | > SDL_Rect *lastRect = _dirtyRectList + _numDirtyRects;
|
---|
1195 | >
|
---|
1196 | > for (r = _dirtyRectList; r != lastRect; ++r) {
|
---|
1197 | > dst = *r;
|
---|
1198 | > dst.x++; // Shift rect by one since 2xSai needs to acces the data around
|
---|
1199 | > dst.y++; // any pixel to scale it, and we want to avoid mem access crashes.
|
---|
1200 | >
|
---|
1201 | > if (SDL_BlitSurface(origSurf, r, srcSurf, &dst) != 0)
|
---|
1202 | > error("SDL_BlitSurface failed: %s", SDL_GetError());
|
---|
1203 | > }
|
---|
1204 | >
|
---|
1205 | > SDL_LockSurface(srcSurf);
|
---|
1206 | > SDL_LockSurface(_hwscreen);
|
---|
1207 | >
|
---|
1208 | > srcPitch = srcSurf->pitch;
|
---|
1209 | > dstPitch = _hwscreen->pitch;
|
---|
1210 | >
|
---|
1211 | > for (r = _dirtyRectList; r != lastRect; ++r) {
|
---|
1212 | > register int dst_y = r->y + _currentShakePos;
|
---|
1213 | > register int dst_h = 0;
|
---|
1214 | > register int orig_dst_y = 0;
|
---|
1215 | > register int rx1 = r->x * scale1;
|
---|
1216 | >
|
---|
1217 | > if (dst_y < height) {
|
---|
1218 | > dst_h = r->h;
|
---|
1219 | > if (dst_h > height - dst_y)
|
---|
1220 | > dst_h = height - dst_y;
|
---|
1221 | >
|
---|
1222 | > orig_dst_y = dst_y;
|
---|
1223 | > dst_y = dst_y * scale1;
|
---|
1224 | >
|
---|
1225 | > if (_adjustAspectRatio && !_overlayVisible)
|
---|
1226 | > dst_y = real2Aspect(dst_y);
|
---|
1227 | >
|
---|
1228 | > assert(scalerProc != NULL);
|
---|
1229 | > scalerProc((byte *)srcSurf->pixels + (r->x * 2 + 2) + (r->y + 1) * srcPitch, srcPitch,
|
---|
1230 | > (byte *)_hwscreen->pixels + rx1 * 2 + dst_y * dstPitch, dstPitch, r->w, dst_h);
|
---|
1231 | > }
|
---|
1232 | >
|
---|
1233 | > r->x = rx1;
|
---|
1234 | > r->y = dst_y;
|
---|
1235 | > r->w = r->w * scale1;
|
---|
1236 | > r->h = dst_h * scale1;
|
---|
1237 | >
|
---|
1238 | > #ifndef DISABLE_SCALERS
|
---|
1239 | > if (_adjustAspectRatio && orig_dst_y < height && !_overlayVisible)
|
---|
1240 | > r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1);
|
---|
1241 | > #endif
|
---|
1242 | > }
|
---|
1243 | > SDL_UnlockSurface(srcSurf);
|
---|
1244 | > SDL_UnlockSurface(_hwscreen);
|
---|
1245 | >
|
---|
1246 | > // Readjust the dirty rect list in case we are doing a full update.
|
---|
1247 | > // This is necessary if shaking is active.
|
---|
1248 | > if (_forceFull) {
|
---|
1249 | > _dirtyRectList[0].y = 0;
|
---|
1250 | > _dirtyRectList[0].h = effectiveScreenHeight();
|
---|
1251 | > }
|
---|
1252 | >
|
---|
1253 | > drawMouse();
|
---|
1254 | >
|
---|
1255 | > #ifdef USE_OSD
|
---|
1256 | > if (_osdAlpha != SDL_ALPHA_TRANSPARENT) {
|
---|
1257 | > SDL_BlitSurface(_osdSurface, 0, _hwscreen, 0);
|
---|
1258 | > }
|
---|
1259 | > #endif
|
---|
1260 | > // Finally, blit all our changes to the screen
|
---|
1261 | > SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList);
|
---|
1262 | > } else {
|
---|
1263 | > drawMouse();
|
---|
1264 | > if (_numDirtyRects)
|
---|
1265 | > SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList);
|
---|
1266 | > }
|
---|
1267 | >
|
---|
1268 | > _numDirtyRects = 0;
|
---|
1269 | > _forceFull = false;
|
---|
1270 | > }
|
---|
1271 | >
|
---|
1272 | > bool OSystem_SDL::saveScreenshot(const char *filename) {
|
---|
1273 | > assert(_hwscreen != NULL);
|
---|
1274 | >
|
---|
1275 | > Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends
|
---|
1276 | > return SDL_SaveBMP(_hwscreen, filename) == 0;
|
---|
1277 | > }
|
---|
1278 | >
|
---|
1279 | > void OSystem_SDL::setFullscreenMode(bool enable) {
|
---|
1280 | > Common::StackLock lock(_graphicsMutex);
|
---|
1281 | >
|
---|
1282 | > if (_fullscreen != enable || _transactionMode == kTransactionCommit) {
|
---|
1283 | > assert(_hwscreen != 0);
|
---|
1284 | > _fullscreen = enable;
|
---|
1285 | >
|
---|
1286 | > if (_transactionMode == kTransactionActive) {
|
---|
1287 | > _transactionDetails.fs = enable;
|
---|
1288 | > _transactionDetails.fsChanged = true;
|
---|
1289 | >
|
---|
1290 | > _transactionDetails.needHotswap = true;
|
---|
1291 | >
|
---|
1292 | > return;
|
---|
1293 | > }
|
---|
1294 | >
|
---|
1295 | > // Switch between fullscreen and windowed mode by invoking hotswapGFXMode().
|
---|
1296 | > // We used to use SDL_WM_ToggleFullScreen() in the past, but this caused various
|
---|
1297 | > // problems. E.g. on OS X, it was implemented incorrectly for a long time; on
|
---|
1298 | > // the MAEMO platform, it seems to have caused problems, too.
|
---|
1299 | > // And on Linux, there were some troubles, too (see bug #1705410).
|
---|
1300 | > // So, we just do it "manually" now. There shouldn't be any drawbacks to that
|
---|
1301 | > // anyway.
|
---|
1302 | > hotswapGFXMode();
|
---|
1303 | > }
|
---|
1304 | > }
|
---|
1305 | >
|
---|
1306 | > void OSystem_SDL::setAspectRatioCorrection(bool enable) {
|
---|
1307 | > if (((_screenHeight == 200 || _screenHeight == 400) && _adjustAspectRatio != enable) ||
|
---|
1308 | > _transactionMode == kTransactionCommit) {
|
---|
1309 | > Common::StackLock lock(_graphicsMutex);
|
---|
1310 | >
|
---|
1311 | > //assert(_hwscreen != 0);
|
---|
1312 | > _adjustAspectRatio = enable;
|
---|
1313 | >
|
---|
1314 | > if (_transactionMode == kTransactionActive) {
|
---|
1315 | > _transactionDetails.ar = enable;
|
---|
1316 | > _transactionDetails.arChanged = true;
|
---|
1317 | >
|
---|
1318 | > _transactionDetails.needHotswap = true;
|
---|
1319 | >
|
---|
1320 | > return;
|
---|
1321 | > } else {
|
---|
1322 | > if (_transactionMode != kTransactionCommit)
|
---|
1323 | > hotswapGFXMode();
|
---|
1324 | > }
|
---|
1325 | >
|
---|
1326 | > // Make sure that an Common::EVENT_SCREEN_CHANGED gets sent later
|
---|
1327 | > _modeChanged = true;
|
---|
1328 | > }
|
---|
1329 | > }
|
---|
1330 | >
|
---|
1331 | > void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h) {
|
---|
1332 | > assert (_transactionMode == kTransactionNone);
|
---|
1333 | > assert(src);
|
---|
1334 | >
|
---|
1335 | > if (_screen == NULL) {
|
---|
1336 | > warning("OSystem_SDL::copyRectToScreen: _screen == NULL");
|
---|
1337 | > return;
|
---|
1338 | > }
|
---|
1339 | >
|
---|
1340 | > Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends
|
---|
1341 | >
|
---|
1342 | > assert(x >= 0 && x < _screenWidth);
|
---|
1343 | > assert(y >= 0 && y < _screenHeight);
|
---|
1344 | > assert(h > 0 && y + h <= _screenHeight);
|
---|
1345 | > assert(w > 0 && x + w <= _screenWidth);
|
---|
1346 | >
|
---|
1347 | > if (((long)src & 3) == 0 && pitch == _screenWidth && x == 0 && y == 0 &&
|
---|
1348 | > w == _screenWidth && h == _screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) {
|
---|
1349 | > /* Special, optimized case for full screen updates.
|
---|
1350 | > * It tries to determine what areas were actually changed,
|
---|
1351 | > * and just updates those, on the actual display. */
|
---|
1352 | > addDirtyRgnAuto(src);
|
---|
1353 | > } else {
|
---|
1354 | > /* Clip the coordinates */
|
---|
1355 | > if (x < 0) {
|
---|
1356 | > w += x;
|
---|
1357 | > src -= x;
|
---|
1358 | > x = 0;
|
---|
1359 | > }
|
---|
1360 | >
|
---|
1361 | > if (y < 0) {
|
---|
1362 | > h += y;
|
---|
1363 | > src -= y * pitch;
|
---|
1364 | > y = 0;
|
---|
1365 | > }
|
---|
1366 | >
|
---|
1367 | > if (w > _screenWidth - x) {
|
---|
1368 | > w = _screenWidth - x;
|
---|
1369 | > }
|
---|
1370 | >
|
---|
1371 | > if (h > _screenHeight - y) {
|
---|
1372 | > h = _screenHeight - y;
|
---|
1373 | > }
|
---|
1374 | >
|
---|
1375 | > if (w <= 0 || h <= 0)
|
---|
1376 | > return;
|
---|
1377 | >
|
---|
1378 | > _cksumValid = false;
|
---|
1379 | > addDirtyRect(x, y, w, h);
|
---|
1380 | > }
|
---|
1381 | >
|
---|
1382 | > // Try to lock the screen surface
|
---|
1383 | > if (SDL_LockSurface(_screen) == -1)
|
---|
1384 | > error("SDL_LockSurface failed: %s", SDL_GetError());
|
---|
1385 | >
|
---|
1386 | > byte *dst = (byte *)_screen->pixels + y * _screenWidth + x;
|
---|
1387 | >
|
---|
1388 | > if (_screenWidth == pitch && pitch == w) {
|
---|
1389 | > memcpy(dst, src, h*w);
|
---|
1390 | > } else {
|
---|
1391 | > do {
|
---|
1392 | > memcpy(dst, src, w);
|
---|
1393 | > src += pitch;
|
---|
1394 | > dst += _screenWidth;
|
---|
1395 | > } while (--h);
|
---|
1396 | > }
|
---|
1397 | >
|
---|
1398 | > // Unlock the screen surface
|
---|
1399 | > SDL_UnlockSurface(_screen);
|
---|
1400 | > }
|
---|
1401 | >
|
---|
1402 | > Graphics::Surface *OSystem_SDL::lockScreen() {
|
---|
1403 | > assert (_transactionMode == kTransactionNone);
|
---|
1404 | >
|
---|
1405 | > // Lock the graphics mutex
|
---|
1406 | > lockMutex(_graphicsMutex);
|
---|
1407 | >
|
---|
1408 | > // paranoia check
|
---|
1409 | > assert(!_screenIsLocked);
|
---|
1410 | > _screenIsLocked = true;
|
---|
1411 | >
|
---|
1412 | > // Try to lock the screen surface
|
---|
1413 | > if (SDL_LockSurface(_screen) == -1)
|
---|
1414 | > error("SDL_LockSurface failed: %s", SDL_GetError());
|
---|
1415 | >
|
---|
1416 | > _framebuffer.pixels = _screen->pixels;
|
---|
1417 | > _framebuffer.w = _screen->w;
|
---|
1418 | > _framebuffer.h = _screen->h;
|
---|
1419 | > _framebuffer.pitch = _screen->pitch;
|
---|
1420 | > _framebuffer.bytesPerPixel = 1;
|
---|
1421 | >
|
---|
1422 | > return &_framebuffer;
|
---|
1423 | > }
|
---|
1424 | >
|
---|
1425 | > void OSystem_SDL::unlockScreen() {
|
---|
1426 | > assert (_transactionMode == kTransactionNone);
|
---|
1427 | >
|
---|
1428 | > // paranoia check
|
---|
1429 | > assert(_screenIsLocked);
|
---|
1430 | > _screenIsLocked = false;
|
---|
1431 | >
|
---|
1432 | > // Unlock the screen surface
|
---|
1433 | > SDL_UnlockSurface(_screen);
|
---|
1434 | >
|
---|
1435 | > // Trigger a full screen update
|
---|
1436 | > _forceFull = true;
|
---|
1437 | >
|
---|
1438 | > // Finally unlock the graphics mutex
|
---|
1439 | > unlockMutex(_graphicsMutex);
|
---|
1440 | > }
|
---|
1441 | >
|
---|
1442 | > void OSystem_SDL::addDirtyRect(int x, int y, int w, int h, bool realCoordinates) {
|
---|
1443 | > if (_forceFull)
|
---|
1444 | > return;
|
---|
1445 | >
|
---|
1446 | > if (_numDirtyRects == NUM_DIRTY_RECT) {
|
---|
1447 | > _forceFull = true;
|
---|
1448 | > return;
|
---|
1449 | > }
|
---|
1450 | >
|
---|
1451 | > int height, width;
|
---|
1452 | >
|
---|
1453 | > if (!_overlayVisible && !realCoordinates) {
|
---|
1454 | > width = _screenWidth;
|
---|
1455 | > height = _screenHeight;
|
---|
1456 | > } else {
|
---|
1457 | > width = _overlayWidth;
|
---|
1458 | > height = _overlayHeight;
|
---|
1459 | > }
|
---|
1460 | >
|
---|
1461 | > // Extend the dirty region by 1 pixel for scalers
|
---|
1462 | > // that "smear" the screen, e.g. 2xSAI
|
---|
1463 | > if (!realCoordinates) {
|
---|
1464 | > x--;
|
---|
1465 | > y--;
|
---|
1466 | > w+=2;
|
---|
1467 | > h+=2;
|
---|
1468 | > }
|
---|
1469 | >
|
---|
1470 | > // clip
|
---|
1471 | > if (x < 0) {
|
---|
1472 | > w += x;
|
---|
1473 | > x = 0;
|
---|
1474 | > }
|
---|
1475 | >
|
---|
1476 | > if (y < 0) {
|
---|
1477 | > h += y;
|
---|
1478 | > y=0;
|
---|
1479 | > }
|
---|
1480 | >
|
---|
1481 | > if (w > width - x) {
|
---|
1482 | > w = width - x;
|
---|
1483 | > }
|
---|
1484 | >
|
---|
1485 | > if (h > height - y) {
|
---|
1486 | > h = height - y;
|
---|
1487 | > }
|
---|
1488 | >
|
---|
1489 | > #ifndef DISABLE_SCALERS
|
---|
1490 | > if (_adjustAspectRatio && !_overlayVisible && !realCoordinates) {
|
---|
1491 | > makeRectStretchable(x, y, w, h);
|
---|
1492 | > }
|
---|
1493 | > #endif
|
---|
1494 | >
|
---|
1495 | > if (w == width && h == height) {
|
---|
1496 | > _forceFull = true;
|
---|
1497 | > return;
|
---|
1498 | > }
|
---|
1499 | >
|
---|
1500 | > if (w > 0 && h > 0) {
|
---|
1501 | > SDL_Rect *r = &_dirtyRectList[_numDirtyRects++];
|
---|
1502 | >
|
---|
1503 | > r->x = x;
|
---|
1504 | > r->y = y;
|
---|
1505 | > r->w = w;
|
---|
1506 | > r->h = h;
|
---|
1507 | > }
|
---|
1508 | > }
|
---|
1509 | >
|
---|
1510 | >
|
---|
1511 | > void OSystem_SDL::makeChecksums(const byte *buf) {
|
---|
1512 | > assert(buf);
|
---|
1513 | > uint32 *sums = _dirtyChecksums;
|
---|
1514 | > uint x,y;
|
---|
1515 | > const uint last_x = (uint)_screenWidth / 8;
|
---|
1516 | > const uint last_y = (uint)_screenHeight / 8;
|
---|
1517 | >
|
---|
1518 | > const uint BASE = 65521; /* largest prime smaller than 65536 */
|
---|
1519 | >
|
---|
1520 | > /* the 8x8 blocks in buf are enumerated starting in the top left corner and
|
---|
1521 | > * reading each line at a time from left to right */
|
---|
1522 | > for (y = 0; y != last_y; y++, buf += _screenWidth * (8 - 1))
|
---|
1523 | > for (x = 0; x != last_x; x++, buf += 8) {
|
---|
1524 | > // Adler32 checksum algorithm (from RFC1950, used by gzip and zlib).
|
---|
1525 | > // This computes the Adler32 checksum of a 8x8 pixel block. Note
|
---|
1526 | > // that we can do the modulo operation (which is the slowest part)
|
---|
1527 | > // of the algorithm) at the end, instead of doing each iteration,
|
---|
1528 | > // since we only have 64 iterations in total - and thus s1 and
|
---|
1529 | > // s2 can't overflow anyway.
|
---|
1530 | > uint32 s1 = 1;
|
---|
1531 | > uint32 s2 = 0;
|
---|
1532 | > const byte *ptr = buf;
|
---|
1533 | > for (int subY = 0; subY < 8; subY++) {
|
---|
1534 | > for (int subX = 0; subX < 8; subX++) {
|
---|
1535 | > s1 += ptr[subX];
|
---|
1536 | > s2 += s1;
|
---|
1537 | > }
|
---|
1538 | > ptr += _screenWidth;
|
---|
1539 | > }
|
---|
1540 | >
|
---|
1541 | > s1 %= BASE;
|
---|
1542 | > s2 %= BASE;
|
---|
1543 | >
|
---|
1544 | > /* output the checksum for this block */
|
---|
1545 | > *sums++ = (s2 << 16) + s1;
|
---|
1546 | > }
|
---|
1547 | > }
|
---|
1548 | >
|
---|
1549 | > void OSystem_SDL::addDirtyRgnAuto(const byte *buf) {
|
---|
1550 | > assert(buf);
|
---|
1551 | > assert(((long)buf & 3) == 0);
|
---|
1552 | >
|
---|
1553 | > /* generate a table of the checksums */
|
---|
1554 | > makeChecksums(buf);
|
---|
1555 | >
|
---|
1556 | > if (!_cksumValid) {
|
---|
1557 | > _forceFull = true;
|
---|
1558 | > _cksumValid = true;
|
---|
1559 | > }
|
---|
1560 | >
|
---|
1561 | > /* go through the checksum list, compare it with the previous checksums,
|
---|
1562 | > and add all dirty rectangles to a list. try to combine small rectangles
|
---|
1563 | > into bigger ones in a simple way */
|
---|
1564 | > if (!_forceFull) {
|
---|
1565 | > int x, y, w;
|
---|
1566 | > uint32 *ck = _dirtyChecksums;
|
---|
1567 | >
|
---|
1568 | > for (y = 0; y != _screenHeight / 8; y++) {
|
---|
1569 | > for (x = 0; x != _screenWidth / 8; x++, ck++) {
|
---|
1570 | > if (ck[0] != ck[_cksumNum]) {
|
---|
1571 | > /* found a dirty 8x8 block, now go as far to the right as possible,
|
---|
1572 | > and at the same time, unmark the dirty status by setting old to new. */
|
---|
1573 | > w=0;
|
---|
1574 | > do {
|
---|
1575 | > ck[w + _cksumNum] = ck[w];
|
---|
1576 | > w++;
|
---|
1577 | > } while (x + w != _screenWidth / 8 && ck[w] != ck[w + _cksumNum]);
|
---|
1578 | >
|
---|
1579 | > addDirtyRect(x * 8, y * 8, w * 8, 8);
|
---|
1580 | >
|
---|
1581 | > if (_forceFull)
|
---|
1582 | > goto get_out;
|
---|
1583 | > }
|
---|
1584 | > }
|
---|
1585 | > }
|
---|
1586 | > } else {
|
---|
1587 | > get_out:;
|
---|
1588 | > /* Copy old checksums to new */
|
---|
1589 | > memcpy(_dirtyChecksums + _cksumNum, _dirtyChecksums, _cksumNum * sizeof(uint32));
|
---|
1590 | > }
|
---|
1591 | > }
|
---|
1592 | >
|
---|
1593 | > int16 OSystem_SDL::getHeight() {
|
---|
1594 | > return _screenHeight;
|
---|
1595 | > }
|
---|
1596 | >
|
---|
1597 | > int16 OSystem_SDL::getWidth() {
|
---|
1598 | > return _screenWidth;
|
---|
1599 | > }
|
---|
1600 | >
|
---|
1601 | > void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) {
|
---|
1602 | > assert(colors);
|
---|
1603 | >
|
---|
1604 | > // Setting the palette before _screen is created is allowed - for now -
|
---|
1605 | > // since we don't actually set the palette until the screen is updated.
|
---|
1606 | > // But it could indicate a programming error, so let's warn about it.
|
---|
1607 | >
|
---|
1608 | > if (!_screen)
|
---|
1609 | > warning("OSystem_SDL::setPalette: _screen == NULL");
|
---|
1610 | >
|
---|
1611 | > const byte *b = colors;
|
---|
1612 | > uint i;
|
---|
1613 | > SDL_Color *base = _currentPalette + start;
|
---|
1614 | > for (i = 0; i < num; i++) {
|
---|
1615 | > base[i].r = b[0];
|
---|
1616 | > base[i].g = b[1];
|
---|
1617 | > base[i].b = b[2];
|
---|
1618 | > b += 4;
|
---|
1619 | > }
|
---|
1620 | >
|
---|
1621 | > if (start < _paletteDirtyStart)
|
---|
1622 | > _paletteDirtyStart = start;
|
---|
1623 | >
|
---|
1624 | > if (start + num > _paletteDirtyEnd)
|
---|
1625 | > _paletteDirtyEnd = start + num;
|
---|
1626 | >
|
---|
1627 | > // Some games blink cursors with palette
|
---|
1628 | > if (_cursorPaletteDisabled)
|
---|
1629 | > blitCursor();
|
---|
1630 | > }
|
---|
1631 | >
|
---|
1632 | > void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) {
|
---|
1633 | > assert(colors);
|
---|
1634 | > const SDL_Color *base = _currentPalette + start;
|
---|
1635 | >
|
---|
1636 | > for (uint i = 0; i < num; ++i) {
|
---|
1637 | > colors[i * 4] = base[i].r;
|
---|
1638 | > colors[i * 4 + 1] = base[i].g;
|
---|
1639 | > colors[i * 4 + 2] = base[i].b;
|
---|
1640 | > colors[i * 4 + 3] = 0xFF;
|
---|
1641 | > }
|
---|
1642 | > }
|
---|
1643 | >
|
---|
1644 | > void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) {
|
---|
1645 | > assert(colors);
|
---|
1646 | > const byte *b = colors;
|
---|
1647 | > uint i;
|
---|
1648 | > SDL_Color *base = _cursorPalette + start;
|
---|
1649 | > for (i = 0; i < num; i++) {
|
---|
1650 | > base[i].r = b[0];
|
---|
1651 | > base[i].g = b[1];
|
---|
1652 | > base[i].b = b[2];
|
---|
1653 | > b += 4;
|
---|
1654 | > }
|
---|
1655 | >
|
---|
1656 | > _cursorPaletteDisabled = false;
|
---|
1657 | >
|
---|
1658 | > blitCursor();
|
---|
1659 | > }
|
---|
1660 | >
|
---|
1661 | > void OSystem_SDL::setShakePos(int shake_pos) {
|
---|
1662 | > assert (_transactionMode == kTransactionNone);
|
---|
1663 | >
|
---|
1664 | > _newShakePos = shake_pos;
|
---|
1665 | > }
|
---|
1666 | >
|
---|
1667 | >
|
---|
1668 | > #pragma mark -
|
---|
1669 | > #pragma mark --- Overlays ---
|
---|
1670 | > #pragma mark -
|
---|
1671 | >
|
---|
1672 | > void OSystem_SDL::showOverlay() {
|
---|
1673 | > assert (_transactionMode == kTransactionNone);
|
---|
1674 | >
|
---|
1675 | > int x, y;
|
---|
1676 | >
|
---|
1677 | > if (_overlayVisible)
|
---|
1678 | > return;
|
---|
1679 | >
|
---|
1680 | > _overlayVisible = true;
|
---|
1681 | >
|
---|
1682 | > // Since resolution could change, put mouse to adjusted position
|
---|
1683 | > // Fixes bug #1349059
|
---|
1684 | > x = _mouseCurState.x * _scaleFactor;
|
---|
1685 | > if (_adjustAspectRatio)
|
---|
1686 | > y = real2Aspect(_mouseCurState.y) * _scaleFactor;
|
---|
1687 | > else
|
---|
1688 | > y = _mouseCurState.y * _scaleFactor;
|
---|
1689 | >
|
---|
1690 | > warpMouse(x, y);
|
---|
1691 | >
|
---|
1692 | > clearOverlay();
|
---|
1693 | > }
|
---|
1694 | >
|
---|
1695 | > void OSystem_SDL::hideOverlay() {
|
---|
1696 | > assert (_transactionMode == kTransactionNone);
|
---|
1697 | >
|
---|
1698 | > if (!_overlayVisible)
|
---|
1699 | > return;
|
---|
1700 | >
|
---|
1701 | > int x, y;
|
---|
1702 | >
|
---|
1703 | > _overlayVisible = false;
|
---|
1704 | >
|
---|
1705 | > // Since resolution could change, put mouse to adjusted position
|
---|
1706 | > // Fixes bug #1349059
|
---|
1707 | > x = _mouseCurState.x / _scaleFactor;
|
---|
1708 | > y = _mouseCurState.y / _scaleFactor;
|
---|
1709 | > if (_adjustAspectRatio)
|
---|
1710 | > y = aspect2Real(y);
|
---|
1711 | >
|
---|
1712 | > warpMouse(x, y);
|
---|
1713 | >
|
---|
1714 | > clearOverlay();
|
---|
1715 | >
|
---|
1716 | > _forceFull = true;
|
---|
1717 | > }
|
---|
1718 | >
|
---|
1719 | > void OSystem_SDL::clearOverlay() {
|
---|
1720 | > //assert (_transactionMode == kTransactionNone);
|
---|
1721 | >
|
---|
1722 | > Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends
|
---|
1723 | >
|
---|
1724 | > if (!_overlayVisible)
|
---|
1725 | > return;
|
---|
1726 | >
|
---|
1727 | > // Clear the overlay by making the game screen "look through" everywhere.
|
---|
1728 | > SDL_Rect src, dst;
|
---|
1729 | > src.x = src.y = 0;
|
---|
1730 | > dst.x = dst.y = 1;
|
---|
1731 | > src.w = dst.w = _screenWidth;
|
---|
1732 | > src.h = dst.h = _screenHeight;
|
---|
1733 | > if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0)
|
---|
1734 | > error("SDL_BlitSurface failed: %s", SDL_GetError());
|
---|
1735 | >
|
---|
1736 | > SDL_LockSurface(_tmpscreen);
|
---|
1737 | > SDL_LockSurface(_overlayscreen);
|
---|
1738 | > _scalerProc((byte *)(_tmpscreen->pixels) + _tmpscreen->pitch + 2, _tmpscreen->pitch,
|
---|
1739 | > (byte *)_overlayscreen->pixels, _overlayscreen->pitch, _screenWidth, _screenHeight);
|
---|
1740 | >
|
---|
1741 | > #ifndef DISABLE_SCALERS
|
---|
1742 | > if (_adjustAspectRatio)
|
---|
1743 | > stretch200To240((uint8 *)_overlayscreen->pixels, _overlayscreen->pitch,
|
---|
1744 | > _overlayWidth, _screenHeight * _scaleFactor, 0, 0, 0);
|
---|
1745 | > #endif
|
---|
1746 | > SDL_UnlockSurface(_tmpscreen);
|
---|
1747 | > SDL_UnlockSurface(_overlayscreen);
|
---|
1748 | >
|
---|
1749 | > _forceFull = true;
|
---|
1750 | > }
|
---|
1751 | >
|
---|
1752 | > void OSystem_SDL::grabOverlay(OverlayColor *buf, int pitch) {
|
---|
1753 | > assert (_transactionMode == kTransactionNone);
|
---|
1754 | >
|
---|
1755 | > if (_overlayscreen == NULL)
|
---|
1756 | > return;
|
---|
1757 | >
|
---|
1758 | > if (SDL_LockSurface(_overlayscreen) == -1)
|
---|
1759 | > error("SDL_LockSurface failed: %s", SDL_GetError());
|
---|
1760 | >
|
---|
1761 | > byte *src = (byte *)_overlayscreen->pixels;
|
---|
1762 | > int h = _overlayHeight;
|
---|
1763 | > do {
|
---|
1764 | > memcpy(buf, src, _overlayWidth * 2);
|
---|
1765 | > src += _overlayscreen->pitch;
|
---|
1766 | > buf += pitch;
|
---|
1767 | > } while (--h);
|
---|
1768 | >
|
---|
1769 | > SDL_UnlockSurface(_overlayscreen);
|
---|
1770 | > }
|
---|
1771 | >
|
---|
1772 | > void OSystem_SDL::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
|
---|
1773 | > assert (_transactionMode == kTransactionNone);
|
---|
1774 | >
|
---|
1775 | > if (_overlayscreen == NULL)
|
---|
1776 | > return;
|
---|
1777 | >
|
---|
1778 | > // Clip the coordinates
|
---|
1779 | > if (x < 0) {
|
---|
1780 | > w += x;
|
---|
1781 | > buf -= x;
|
---|
1782 | > x = 0;
|
---|
1783 | > }
|
---|
1784 | >
|
---|
1785 | > if (y < 0) {
|
---|
1786 | > h += y; buf -= y * pitch;
|
---|
1787 | > y = 0;
|
---|
1788 | > }
|
---|
1789 | >
|
---|
1790 | > if (w > _overlayWidth - x) {
|
---|
1791 | > w = _overlayWidth - x;
|
---|
1792 | > }
|
---|
1793 | >
|
---|
1794 | > if (h > _overlayHeight - y) {
|
---|
1795 | > h = _overlayHeight - y;
|
---|
1796 | > }
|
---|
1797 | >
|
---|
1798 | > if (w <= 0 || h <= 0)
|
---|
1799 | > return;
|
---|
1800 | >
|
---|
1801 | > // Mark the modified region as dirty
|
---|
1802 | > _cksumValid = false;
|
---|
1803 | > addDirtyRect(x, y, w, h);
|
---|
1804 | >
|
---|
1805 | > if (SDL_LockSurface(_overlayscreen) == -1)
|
---|
1806 | > error("SDL_LockSurface failed: %s", SDL_GetError());
|
---|
1807 | >
|
---|
1808 | > byte *dst = (byte *)_overlayscreen->pixels + y * _overlayscreen->pitch + x * 2;
|
---|
1809 | > do {
|
---|
1810 | > memcpy(dst, buf, w * 2);
|
---|
1811 | > dst += _overlayscreen->pitch;
|
---|
1812 | > buf += pitch;
|
---|
1813 | > } while (--h);
|
---|
1814 | >
|
---|
1815 | > SDL_UnlockSurface(_overlayscreen);
|
---|
1816 | > }
|
---|
1817 | >
|
---|
1818 | > OverlayColor OSystem_SDL::RGBToColor(uint8 r, uint8 g, uint8 b) {
|
---|
1819 | > return SDL_MapRGB(_overlayscreen->format, r, g, b);
|
---|
1820 | > }
|
---|
1821 | >
|
---|
1822 | > void OSystem_SDL::colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b) {
|
---|
1823 | > SDL_GetRGB(color, _overlayscreen->format, &r, &g, &b);
|
---|
1824 | > }
|
---|
1825 | >
|
---|
1826 | >
|
---|
1827 | > #pragma mark -
|
---|
1828 | > #pragma mark --- Mouse ---
|
---|
1829 | > #pragma mark -
|
---|
1830 | >
|
---|
1831 | > bool OSystem_SDL::showMouse(bool visible) {
|
---|
1832 | > if (_mouseVisible == visible)
|
---|
1833 | > return visible;
|
---|
1834 | >
|
---|
1835 | > bool last = _mouseVisible;
|
---|
1836 | > _mouseVisible = visible;
|
---|
1837 | >
|
---|
1838 | > return last;
|
---|
1839 | > }
|
---|
1840 | >
|
---|
1841 | > void OSystem_SDL::setMousePos(int x, int y) {
|
---|
1842 | > if (x != _mouseCurState.x || y != _mouseCurState.y) {
|
---|
1843 | > _mouseCurState.x = x;
|
---|
1844 | > _mouseCurState.y = y;
|
---|
1845 | > }
|
---|
1846 | > }
|
---|
1847 | >
|
---|
1848 | > void OSystem_SDL::warpMouse(int x, int y) {
|
---|
1849 | > int y1 = y;
|
---|
1850 | >
|
---|
1851 | > if (_adjustAspectRatio && !_overlayVisible)
|
---|
1852 | > y1 = real2Aspect(y);
|
---|
1853 | >
|
---|
1854 | > if (_mouseCurState.x != x || _mouseCurState.y != y) {
|
---|
1855 | > if (!_overlayVisible)
|
---|
1856 | > SDL_WarpMouse(x * _scaleFactor, y1 * _scaleFactor);
|
---|
1857 | > else
|
---|
1858 | > SDL_WarpMouse(x, y1);
|
---|
1859 | >
|
---|
1860 | > // SDL_WarpMouse() generates a mouse movement event, so
|
---|
1861 | > // setMousePos() would be called eventually. However, the
|
---|
1862 | > // cannon script in CoMI calls this function twice each time
|
---|
1863 | > // the cannon is reloaded. Unless we update the mouse position
|
---|
1864 | > // immediately the second call is ignored, causing the cannon
|
---|
1865 | > // to change its aim.
|
---|
1866 | >
|
---|
1867 | > setMousePos(x, y);
|
---|
1868 | > }
|
---|
1869 | > }
|
---|
1870 | >
|
---|
1871 | > void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) {
|
---|
1872 | > if (w == 0 || h == 0)
|
---|
1873 | > return;
|
---|
1874 | >
|
---|
1875 | > _mouseCurState.hotX = hotspot_x;
|
---|
1876 | > _mouseCurState.hotY = hotspot_y;
|
---|
1877 | >
|
---|
1878 | > _mouseKeyColor = keycolor;
|
---|
1879 | >
|
---|
1880 | > _cursorTargetScale = cursorTargetScale;
|
---|
1881 | >
|
---|
1882 | > if (_mouseCurState.w != (int)w || _mouseCurState.h != (int)h) {
|
---|
1883 | > _mouseCurState.w = w;
|
---|
1884 | > _mouseCurState.h = h;
|
---|
1885 | >
|
---|
1886 | > if (_mouseOrigSurface)
|
---|
1887 | > SDL_FreeSurface(_mouseOrigSurface);
|
---|
1888 | >
|
---|
1889 | > // Allocate bigger surface because AdvMame2x adds black pixel at [0,0]
|
---|
1890 | > _mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
|
---|
1891 | > _mouseCurState.w + 2,
|
---|
1892 | > _mouseCurState.h + 2,
|
---|
1893 | > 16,
|
---|
1894 | > _hwscreen->format->Rmask,
|
---|
1895 | > _hwscreen->format->Gmask,
|
---|
1896 | > _hwscreen->format->Bmask,
|
---|
1897 | > _hwscreen->format->Amask);
|
---|
1898 | >
|
---|
1899 | > if (_mouseOrigSurface == NULL)
|
---|
1900 | > error("allocating _mouseOrigSurface failed");
|
---|
1901 | > SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey);
|
---|
1902 | > }
|
---|
1903 | >
|
---|
1904 | > free(_mouseData);
|
---|
1905 | >
|
---|
1906 | > _mouseData = (byte *)malloc(w * h);
|
---|
1907 | > memcpy(_mouseData, buf, w * h);
|
---|
1908 | > blitCursor();
|
---|
1909 | > }
|
---|
1910 | >
|
---|
1911 | > void OSystem_SDL::blitCursor() {
|
---|
1912 | > byte *dstPtr;
|
---|
1913 | > const byte *srcPtr = _mouseData;
|
---|
1914 | > byte color;
|
---|
1915 | > int w, h, i, j;
|
---|
1916 | >
|
---|
1917 | > if (!_mouseOrigSurface || !_mouseData)
|
---|
1918 | > return;
|
---|
1919 | >
|
---|
1920 | > w = _mouseCurState.w;
|
---|
1921 | > h = _mouseCurState.h;
|
---|
1922 | >
|
---|
1923 | > SDL_LockSurface(_mouseOrigSurface);
|
---|
1924 | >
|
---|
1925 | > // Make whole surface transparent
|
---|
1926 | > for (i = 0; i < h + 2; i++) {
|
---|
1927 | > dstPtr = (byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * i;
|
---|
1928 | > for (j = 0; j < w + 2; j++) {
|
---|
1929 | > *(uint16 *)dstPtr = kMouseColorKey;
|
---|
1930 | > dstPtr += 2;
|
---|
1931 | > }
|
---|
1932 | > }
|
---|
1933 | >
|
---|
1934 | > // Draw from [1,1] since AdvMame2x adds artefact at 0,0
|
---|
1935 | > dstPtr = (byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2;
|
---|
1936 | >
|
---|
1937 | > SDL_Color *palette;
|
---|
1938 | >
|
---|
1939 | > if (_cursorPaletteDisabled)
|
---|
1940 | > palette = _currentPalette;
|
---|
1941 | > else
|
---|
1942 | > palette = _cursorPalette;
|
---|
1943 | >
|
---|
1944 | > for (i = 0; i < h; i++) {
|
---|
1945 | > for (j = 0; j < w; j++) {
|
---|
1946 | > color = *srcPtr;
|
---|
1947 | > if (color != _mouseKeyColor) { // transparent, don't draw
|
---|
1948 | > *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format,
|
---|
1949 | > palette[color].r, palette[color].g, palette[color].b);
|
---|
1950 | > }
|
---|
1951 | > dstPtr += 2;
|
---|
1952 | > srcPtr++;
|
---|
1953 | > }
|
---|
1954 | > dstPtr += _mouseOrigSurface->pitch - w * 2;
|
---|
1955 | > }
|
---|
1956 | >
|
---|
1957 | > int rW, rH;
|
---|
1958 | >
|
---|
1959 | > if (_cursorTargetScale >= _scaleFactor) {
|
---|
1960 | > // The cursor target scale is greater or equal to the scale at
|
---|
1961 | > // which the rest of the screen is drawn. We do not downscale
|
---|
1962 | > // the cursor image, we draw it at its original size. It will
|
---|
1963 | > // appear too large on screen.
|
---|
1964 | >
|
---|
1965 | > rW = w;
|
---|
1966 | > rH = h;
|
---|
1967 | > _mouseCurState.rHotX = _mouseCurState.hotX;
|
---|
1968 | > _mouseCurState.rHotY = _mouseCurState.hotY;
|
---|
1969 | >
|
---|
1970 | > // The virtual dimensions may be larger than the original.
|
---|
1971 | >
|
---|
1972 | > _mouseCurState.vW = w * _cursorTargetScale / _scaleFactor;
|
---|
1973 | > _mouseCurState.vH = h * _cursorTargetScale / _scaleFactor;
|
---|
1974 | > _mouseCurState.vHotX = _mouseCurState.hotX * _cursorTargetScale /
|
---|
1975 | > _scaleFactor;
|
---|
1976 | > _mouseCurState.vHotY = _mouseCurState.hotY * _cursorTargetScale /
|
---|
1977 | > _scaleFactor;
|
---|
1978 | > } else {
|
---|
1979 | > // The cursor target scale is smaller than the scale at which
|
---|
1980 | > // the rest of the screen is drawn. We scale up the cursor
|
---|
1981 | > // image to make it appear correct.
|
---|
1982 | >
|
---|
1983 | > rW = w * _scaleFactor / _cursorTargetScale;
|
---|
1984 | > rH = h * _scaleFactor / _cursorTargetScale;
|
---|
1985 | > _mouseCurState.rHotX = _mouseCurState.hotX * _scaleFactor /
|
---|
1986 | > _cursorTargetScale;
|
---|
1987 | > _mouseCurState.rHotY = _mouseCurState.hotY * _scaleFactor /
|
---|
1988 | > _cursorTargetScale;
|
---|
1989 | >
|
---|
1990 | > // The virtual dimensions will be the same as the original.
|
---|
1991 | >
|
---|
1992 | > _mouseCurState.vW = w;
|
---|
1993 | > _mouseCurState.vH = h;
|
---|
1994 | > _mouseCurState.vHotX = _mouseCurState.hotX;
|
---|
1995 | > _mouseCurState.vHotY = _mouseCurState.hotY;
|
---|
1996 | > }
|
---|
1997 | >
|
---|
1998 | > #ifndef DISABLE_SCALERS
|
---|
1999 | > int rH1 = rH; // store original to pass to aspect-correction function later
|
---|
2000 | > #endif
|
---|
2001 | >
|
---|
2002 | > if (_adjustAspectRatio && _cursorTargetScale == 1) {
|
---|
2003 | > rH = real2Aspect(rH - 1) + 1;
|
---|
2004 | > _mouseCurState.rHotY = real2Aspect(_mouseCurState.rHotY);
|
---|
2005 | > }
|
---|
2006 | >
|
---|
2007 | > if (_mouseCurState.rW != rW || _mouseCurState.rH != rH) {
|
---|
2008 | > _mouseCurState.rW = rW;
|
---|
2009 | > _mouseCurState.rH = rH;
|
---|
2010 | >
|
---|
2011 | > if (_mouseSurface)
|
---|
2012 | > SDL_FreeSurface(_mouseSurface);
|
---|
2013 | >
|
---|
2014 | > _mouseSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
|
---|
2015 | > _mouseCurState.rW,
|
---|
2016 | > _mouseCurState.rH,
|
---|
2017 | > 16,
|
---|
2018 | > _hwscreen->format->Rmask,
|
---|
2019 | > _hwscreen->format->Gmask,
|
---|
2020 | > _hwscreen->format->Bmask,
|
---|
2021 | > _hwscreen->format->Amask);
|
---|
2022 | >
|
---|
2023 | > if (_mouseSurface == NULL)
|
---|
2024 | > error("allocating _mouseSurface failed");
|
---|
2025 | >
|
---|
2026 | > SDL_SetColorKey(_mouseSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey);
|
---|
2027 | > }
|
---|
2028 | >
|
---|
2029 | > SDL_LockSurface(_mouseSurface);
|
---|
2030 | >
|
---|
2031 | > ScalerProc *scalerProc;
|
---|
2032 | >
|
---|
2033 | > // If possible, use the same scaler for the cursor as for the rest of
|
---|
2034 | > // the game. This only works well with the non-blurring scalers so we
|
---|
2035 | > // actually only use the 1x, 1.5x, 2x and AdvMame scalers.
|
---|
2036 | >
|
---|
2037 | > if (_cursorTargetScale == 1 && (_mode == GFX_DOUBLESIZE || _mode == GFX_TRIPLESIZE))
|
---|
2038 | > scalerProc = _scalerProc;
|
---|
2039 | > else
|
---|
2040 | > scalerProc = scalersMagn[_cursorTargetScale - 1][_scaleFactor - 1];
|
---|
2041 | >
|
---|
2042 | > scalerProc((byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2,
|
---|
2043 | > _mouseOrigSurface->pitch, (byte *)_mouseSurface->pixels, _mouseSurface->pitch,
|
---|
2044 | > _mouseCurState.w, _mouseCurState.h);
|
---|
2045 | >
|
---|
2046 | > #ifndef DISABLE_SCALERS
|
---|
2047 | > if (_adjustAspectRatio && _cursorTargetScale == 1)
|
---|
2048 | > cursorStretch200To240((uint8 *)_mouseSurface->pixels, _mouseSurface->pitch, rW, rH1, 0, 0, 0);
|
---|
2049 | > #endif
|
---|
2050 | >
|
---|
2051 | > SDL_UnlockSurface(_mouseSurface);
|
---|
2052 | > SDL_UnlockSurface(_mouseOrigSurface);
|
---|
2053 | > }
|
---|
2054 | >
|
---|
2055 | > #ifndef DISABLE_SCALERS
|
---|
2056 | > // Basically it is kVeryFastAndUglyAspectMode of stretch200To240 from
|
---|
2057 | > // common/scale/aspect.cpp
|
---|
2058 | > static int cursorStretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) {
|
---|
2059 | > int maxDstY = real2Aspect(origSrcY + height - 1);
|
---|
2060 | > int y;
|
---|
2061 | > const uint8 *startSrcPtr = buf + srcX * 2 + (srcY - origSrcY) * pitch;
|
---|
2062 | > uint8 *dstPtr = buf + srcX * 2 + maxDstY * pitch;
|
---|
2063 | >
|
---|
2064 | > for (y = maxDstY; y >= srcY; y--) {
|
---|
2065 | > const uint8 *srcPtr = startSrcPtr + aspect2Real(y) * pitch;
|
---|
2066 | >
|
---|
2067 | > if (srcPtr == dstPtr)
|
---|
2068 | > break;
|
---|
2069 | > memcpy(dstPtr, srcPtr, width * 2);
|
---|
2070 | > dstPtr -= pitch;
|
---|
2071 | > }
|
---|
2072 | >
|
---|
2073 | > return 1 + maxDstY - srcY;
|
---|
2074 | > }
|
---|
2075 | > #endif
|
---|
2076 | >
|
---|
2077 | > void OSystem_SDL::toggleMouseGrab() {
|
---|
2078 | > if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF)
|
---|
2079 | > SDL_WM_GrabInput(SDL_GRAB_ON);
|
---|
2080 | > else
|
---|
2081 | > SDL_WM_GrabInput(SDL_GRAB_OFF);
|
---|
2082 | > }
|
---|
2083 | >
|
---|
2084 | > void OSystem_SDL::undrawMouse() {
|
---|
2085 | > const int x = _mouseBackup.x;
|
---|
2086 | > const int y = _mouseBackup.y;
|
---|
2087 | >
|
---|
2088 | > // When we switch bigger overlay off mouse jumps. Argh!
|
---|
2089 | > // This is intended to prevent undrawing offscreen mouse
|
---|
2090 | > if (!_overlayVisible && (x >= _screenWidth || y >= _screenHeight)) {
|
---|
2091 | > return;
|
---|
2092 | > }
|
---|
2093 | >
|
---|
2094 | > if (_mouseBackup.w != 0 && _mouseBackup.h != 0)
|
---|
2095 | > addDirtyRect(x, y, _mouseBackup.w, _mouseBackup.h);
|
---|
2096 | > }
|
---|
2097 | >
|
---|
2098 | > void OSystem_SDL::drawMouse() {
|
---|
2099 | > if (!_mouseVisible || !_mouseSurface) {
|
---|
2100 | > _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0;
|
---|
2101 | > return;
|
---|
2102 | > }
|
---|
2103 | >
|
---|
2104 | > SDL_Rect dst;
|
---|
2105 | > int scale;
|
---|
2106 | > int width, height;
|
---|
2107 | > int hotX, hotY;
|
---|
2108 | >
|
---|
2109 | > dst.x = _mouseCurState.x;
|
---|
2110 | > dst.y = _mouseCurState.y;
|
---|
2111 | >
|
---|
2112 | > if (!_overlayVisible) {
|
---|
2113 | > scale = _scaleFactor;
|
---|
2114 | > width = _screenWidth;
|
---|
2115 | > height = _screenHeight;
|
---|
2116 | > dst.w = _mouseCurState.vW;
|
---|
2117 | > dst.h = _mouseCurState.vH;
|
---|
2118 | > hotX = _mouseCurState.vHotX;
|
---|
2119 | > hotY = _mouseCurState.vHotY;
|
---|
2120 | > } else {
|
---|
2121 | > scale = 1;
|
---|
2122 | > width = _overlayWidth;
|
---|
2123 | > height = _overlayHeight;
|
---|
2124 | > dst.w = _mouseCurState.rW;
|
---|
2125 | > dst.h = _mouseCurState.rH;
|
---|
2126 | > hotX = _mouseCurState.rHotX;
|
---|
2127 | > hotY = _mouseCurState.rHotY;
|
---|
2128 | > }
|
---|
2129 | >
|
---|
2130 | > // The mouse is undrawn using virtual coordinates, i.e. they may be
|
---|
2131 | > // scaled and aspect-ratio corrected.
|
---|
2132 | >
|
---|
2133 | > _mouseBackup.x = dst.x - hotX;
|
---|
2134 | > _mouseBackup.y = dst.y - hotY;
|
---|
2135 | > _mouseBackup.w = dst.w;
|
---|
2136 | > _mouseBackup.h = dst.h;
|
---|
2137 | >
|
---|
2138 | > // We draw the pre-scaled cursor image, so now we need to adjust for
|
---|
2139 | > // scaling, shake position and aspect ratio correction manually.
|
---|
2140 | >
|
---|
2141 | > if (!_overlayVisible) {
|
---|
2142 | > dst.y += _currentShakePos;
|
---|
2143 | > }
|
---|
2144 | >
|
---|
2145 | > if (_adjustAspectRatio && !_overlayVisible)
|
---|
2146 | > dst.y = real2Aspect(dst.y);
|
---|
2147 | >
|
---|
2148 | > dst.x = scale * dst.x - _mouseCurState.rHotX;
|
---|
2149 | > dst.y = scale * dst.y - _mouseCurState.rHotY;
|
---|
2150 | > dst.w = _mouseCurState.rW;
|
---|
2151 | > dst.h = _mouseCurState.rH;
|
---|
2152 | >
|
---|
2153 | > // Note that SDL_BlitSurface() and addDirtyRect() will both perform any
|
---|
2154 | > // clipping necessary
|
---|
2155 | >
|
---|
2156 | > if (SDL_BlitSurface(_mouseSurface, NULL, _hwscreen, &dst) != 0)
|
---|
2157 | > error("SDL_BlitSurface failed: %s", SDL_GetError());
|
---|
2158 | >
|
---|
2159 | > // The screen will be updated using real surface coordinates, i.e.
|
---|
2160 | > // they will not be scaled or aspect-ratio corrected.
|
---|
2161 | >
|
---|
2162 | > addDirtyRect(dst.x, dst.y, dst.w, dst.h, true);
|
---|
2163 | > }
|
---|
2164 | >
|
---|
2165 | > #pragma mark -
|
---|
2166 | > #pragma mark --- On Screen Display ---
|
---|
2167 | > #pragma mark -
|
---|
2168 | >
|
---|
2169 | > #ifdef USE_OSD
|
---|
2170 | > void OSystem_SDL::displayMessageOnOSD(const char *msg) {
|
---|
2171 | > assert (_transactionMode == kTransactionNone);
|
---|
2172 | > assert(msg);
|
---|
2173 | >
|
---|
2174 | > Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends
|
---|
2175 | >
|
---|
2176 | > uint i;
|
---|
2177 | >
|
---|
2178 | > // Lock the OSD surface for drawing
|
---|
2179 | > if (SDL_LockSurface(_osdSurface))
|
---|
2180 | > error("displayMessageOnOSD: SDL_LockSurface failed: %s", SDL_GetError());
|
---|
2181 | >
|
---|
2182 | > Graphics::Surface dst;
|
---|
2183 | > dst.pixels = _osdSurface->pixels;
|
---|
2184 | > dst.w = _osdSurface->w;
|
---|
2185 | > dst.h = _osdSurface->h;
|
---|
2186 | > dst.pitch = _osdSurface->pitch;
|
---|
2187 | > dst.bytesPerPixel = _osdSurface->format->BytesPerPixel;
|
---|
2188 | >
|
---|
2189 | > // The font we are going to use:
|
---|
2190 | > const Graphics::Font *font = FontMan.getFontByUsage(Graphics::FontManager::kOSDFont);
|
---|
2191 | >
|
---|
2192 | > // Clear everything with the "transparent" color, i.e. the colorkey
|
---|
2193 | > SDL_FillRect(_osdSurface, 0, kOSDColorKey);
|
---|
2194 | >
|
---|
2195 | > // Split the message into separate lines.
|
---|
2196 | > Common::StringList lines;
|
---|
2197 | > const char *ptr;
|
---|
2198 | > for (ptr = msg; *ptr; ++ptr) {
|
---|
2199 | > if (*ptr == '\n') {
|
---|
2200 | > lines.push_back(Common::String(msg, ptr - msg));
|
---|
2201 | > msg = ptr + 1;
|
---|
2202 | > }
|
---|
2203 | > }
|
---|
2204 | > lines.push_back(Common::String(msg, ptr - msg));
|
---|
2205 | >
|
---|
2206 | > // Determine a rect which would contain the message string (clipped to the
|
---|
2207 | > // screen dimensions).
|
---|
2208 | > const int vOffset = 6;
|
---|
2209 | > const int lineSpacing = 1;
|
---|
2210 | > const int lineHeight = font->getFontHeight() + 2 * lineSpacing;
|
---|
2211 | > int width = 0;
|
---|
2212 | > int height = lineHeight * lines.size() + 2 * vOffset;
|
---|
2213 | > for (i = 0; i < lines.size(); i++) {
|
---|
2214 | > width = MAX(width, font->getStringWidth(lines[i]) + 14);
|
---|
2215 | > }
|
---|
2216 | >
|
---|
2217 | > // Clip the rect
|
---|
2218 | > if (width > dst.w)
|
---|
2219 | > width = dst.w;
|
---|
2220 | > if (height > dst.h)
|
---|
2221 | > height = dst.h;
|
---|
2222 | >
|
---|
2223 | > // Draw a dark gray rect
|
---|
2224 | > // TODO: Rounded corners ? Border?
|
---|
2225 | > SDL_Rect osdRect;
|
---|
2226 | > osdRect.x = (dst.w - width) / 2;
|
---|
2227 | > osdRect.y = (dst.h - height) / 2;
|
---|
2228 | > osdRect.w = width;
|
---|
2229 | > osdRect.h = height;
|
---|
2230 | > SDL_FillRect(_osdSurface, &osdRect, SDL_MapRGB(_osdSurface->format, 64, 64, 64));
|
---|
2231 | >
|
---|
2232 | > // Render the message, centered, and in white
|
---|
2233 | > for (i = 0; i < lines.size(); i++) {
|
---|
2234 | > font->drawString(&dst, lines[i],
|
---|
2235 | > osdRect.x, osdRect.y + i * lineHeight + vOffset + lineSpacing, osdRect.w,
|
---|
2236 | > SDL_MapRGB(_osdSurface->format, 255, 255, 255),
|
---|
2237 | > Graphics::kTextAlignCenter);
|
---|
2238 | > }
|
---|
2239 | >
|
---|
2240 | > // Finished drawing, so unlock the OSD surface again
|
---|
2241 | > SDL_UnlockSurface(_osdSurface);
|
---|
2242 | >
|
---|
2243 | > // Init the OSD display parameters, and the fade out
|
---|
2244 | > _osdAlpha = SDL_ALPHA_TRANSPARENT + kOSDInitialAlpha * (SDL_ALPHA_OPAQUE - SDL_ALPHA_TRANSPARENT) / 100;
|
---|
2245 | > _osdFadeStartTime = st_get_ticks() + kOSDFadeOutDelay;
|
---|
2246 | > SDL_SetAlpha(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _osdAlpha);
|
---|
2247 | >
|
---|
2248 | > // Ensure a full redraw takes place next time the screen is updated
|
---|
2249 | > _forceFull = true;
|
---|
2250 | > }
|
---|
2251 | > #endif
|
---|
2252 | >
|
---|
2253 | >
|
---|
2254 | > #pragma mark -
|
---|
2255 | > #pragma mark --- Misc ---
|
---|
2256 | > #pragma mark -
|
---|
2257 | >
|
---|
2258 | > void OSystem_SDL::handleScalerHotkeys(const SDL_KeyboardEvent &key) {
|
---|
2259 | > // Ctrl-Alt-a toggles aspect ratio correction
|
---|
2260 | > if (key.keysym.sym == 'a') {
|
---|
2261 | > setFeatureState(kFeatureAspectRatioCorrection, !_adjustAspectRatio);
|
---|
2262 | > #ifdef USE_OSD
|
---|
2263 | > char buffer[128];
|
---|
2264 | > if (_adjustAspectRatio)
|
---|
2265 | > sprintf(buffer, "Enabled aspect ratio correction\n%d x %d -> %d x %d",
|
---|
2266 | > _screenWidth, _screenHeight,
|
---|
2267 | > _hwscreen->w, _hwscreen->h
|
---|
2268 | > );
|
---|
2269 | > else
|
---|
2270 | > sprintf(buffer, "Disabled aspect ratio correction\n%d x %d -> %d x %d",
|
---|
2271 | > _screenWidth, _screenHeight,
|
---|
2272 | > _hwscreen->w, _hwscreen->h
|
---|
2273 | > );
|
---|
2274 | > displayMessageOnOSD(buffer);
|
---|
2275 | > #endif
|
---|
2276 | >
|
---|
2277 | > return;
|
---|
2278 | > }
|
---|
2279 | >
|
---|
2280 | > int newMode = -1;
|
---|
2281 | > int factor = _scaleFactor - 1;
|
---|
2282 | >
|
---|
2283 | > // Increase/decrease the scale factor
|
---|
2284 | > if (key.keysym.sym == SDLK_EQUALS || key.keysym.sym == SDLK_PLUS || key.keysym.sym == SDLK_MINUS ||
|
---|
2285 | > key.keysym.sym == SDLK_KP_PLUS || key.keysym.sym == SDLK_KP_MINUS) {
|
---|
2286 | > factor += (key.keysym.sym == SDLK_MINUS || key.keysym.sym == SDLK_KP_MINUS) ? -1 : +1;
|
---|
2287 | > if (0 <= factor && factor <= 3) {
|
---|
2288 | > newMode = s_gfxModeSwitchTable[_scalerType][factor];
|
---|
2289 | > }
|
---|
2290 | > }
|
---|
2291 | >
|
---|
2292 | > const bool isNormalNumber = (SDLK_1 <= key.keysym.sym && key.keysym.sym <= SDLK_9);
|
---|
2293 | > const bool isKeypadNumber = (SDLK_KP1 <= key.keysym.sym && key.keysym.sym <= SDLK_KP9);
|
---|
2294 | > if (isNormalNumber || isKeypadNumber) {
|
---|
2295 | > _scalerType = key.keysym.sym - (isNormalNumber ? SDLK_1 : SDLK_KP1);
|
---|
2296 | > if (_scalerType >= ARRAYSIZE(s_gfxModeSwitchTable))
|
---|
2297 | > return;
|
---|
2298 | >
|
---|
2299 | > while (s_gfxModeSwitchTable[_scalerType][factor] < 0) {
|
---|
2300 | > assert(factor > 0);
|
---|
2301 | > factor--;
|
---|
2302 | > }
|
---|
2303 | > newMode = s_gfxModeSwitchTable[_scalerType][factor];
|
---|
2304 | > }
|
---|
2305 | >
|
---|
2306 | > if (newMode >= 0) {
|
---|
2307 | > setGraphicsMode(newMode);
|
---|
2308 | > #ifdef USE_OSD
|
---|
2309 | > if (_osdSurface) {
|
---|
2310 | > const char *newScalerName = 0;
|
---|
2311 | > const GraphicsMode *g = getSupportedGraphicsModes();
|
---|
2312 | > while (g->name) {
|
---|
2313 | > if (g->id == _mode) {
|
---|
2314 | > newScalerName = g->description;
|
---|
2315 | > break;
|
---|
2316 | > }
|
---|
2317 | > g++;
|
---|
2318 | > }
|
---|
2319 | > if (newScalerName) {
|
---|
2320 | > char buffer[128];
|
---|
2321 | > sprintf(buffer, "Active graphics filter: %s\n%d x %d -> %d x %d",
|
---|
2322 | > newScalerName,
|
---|
2323 | > _screenWidth, _screenHeight,
|
---|
2324 | > _hwscreen->w, _hwscreen->h
|
---|
2325 | > );
|
---|
2326 | > displayMessageOnOSD(buffer);
|
---|
2327 | > }
|
---|
2328 | > }
|
---|
2329 | > #endif
|
---|
2330 | >
|
---|
2331 | > }
|
---|
2332 | >
|
---|
2333 | > }
|
---|
2334 | diff -rN scummvm-0.12.0/backends/platform/motoezx/main.cpp scummvm-0.12.0-a1200/backends/platform/motoezx/main.cpp
|
---|
2335 | 0a1,113
|
---|
2336 | > /* ScummVM - Graphic Adventure Engine
|
---|
2337 | > *
|
---|
2338 | > * ScummVM is the legal property of its developers, whose names
|
---|
2339 | > * are too numerous to list here. Please refer to the COPYRIGHT
|
---|
2340 | > * file distributed with this source distribution.
|
---|
2341 | > *
|
---|
2342 | > * This program is free software; you can redistribute it and/or
|
---|
2343 | > * modify it under the terms of the GNU General Public License
|
---|
2344 | > * as published by the Free Software Foundation; either version 2
|
---|
2345 | > * of the License, or (at your option) any later version.
|
---|
2346 | >
|
---|
2347 | > * This program is distributed in the hope that it will be useful,
|
---|
2348 | > * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
2349 | > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
2350 | > * GNU General Public License for more details.
|
---|
2351 | >
|
---|
2352 | > * You should have received a copy of the GNU General Public License
|
---|
2353 | > * along with this program; if not, write to the Free Software
|
---|
2354 | > * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
---|
2355 | > *
|
---|
2356 | > * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-0-12-0/backends/platform/sdl/main.cpp $
|
---|
2357 | > * $Id: main.cpp 30664 2008-01-27 19:47:41Z jvprat $
|
---|
2358 | > *
|
---|
2359 | > */
|
---|
2360 | >
|
---|
2361 | > #if defined(WIN32) && !defined(__SYMBIAN32__)
|
---|
2362 | > #include <windows.h>
|
---|
2363 | > // winnt.h defines ARRAYSIZE, but we want our own one...
|
---|
2364 | > #undef ARRAYSIZE
|
---|
2365 | > #endif
|
---|
2366 | >
|
---|
2367 | > #include "backends/platform/motoezx/sdl.h"
|
---|
2368 | > #include "backends/plugins/sdl/sdl-provider.h"
|
---|
2369 | > #include "base/main.h"
|
---|
2370 | >
|
---|
2371 | > #if defined(__SYMBIAN32__)
|
---|
2372 | > #include "SymbianOs.h"
|
---|
2373 | > #endif
|
---|
2374 | >
|
---|
2375 | > #if !defined(__MAEMO__) && !defined(_WIN32_WCE)
|
---|
2376 | >
|
---|
2377 | > #if defined (WIN32)
|
---|
2378 | > int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*iShowCmd*/) {
|
---|
2379 | > SDL_SetModuleHandle(GetModuleHandle(NULL));
|
---|
2380 | > return main(__argc, __argv);
|
---|
2381 | > }
|
---|
2382 | > #endif
|
---|
2383 | >
|
---|
2384 | > int main(int argc, char *argv[]) {
|
---|
2385 | >
|
---|
2386 | > #if defined(__SYMBIAN32__)
|
---|
2387 | > //
|
---|
2388 | > // Set up redirects for stdout/stderr under Windows and Symbian.
|
---|
2389 | > // Code copied from SDL_main.
|
---|
2390 | > //
|
---|
2391 | >
|
---|
2392 | > // Symbian does not like any output to the console through any *print* function
|
---|
2393 | > char STDOUT_FILE[256], STDERR_FILE[256]; // shhh, don't tell anybody :)
|
---|
2394 | > strcpy(STDOUT_FILE, Symbian::GetExecutablePath());
|
---|
2395 | > strcpy(STDERR_FILE, Symbian::GetExecutablePath());
|
---|
2396 | > strcat(STDOUT_FILE, "scummvm.stdout.txt");
|
---|
2397 | > strcat(STDERR_FILE, "scummvm.stderr.txt");
|
---|
2398 | >
|
---|
2399 | > /* Flush the output in case anything is queued */
|
---|
2400 | > fclose(stdout);
|
---|
2401 | > fclose(stderr);
|
---|
2402 | >
|
---|
2403 | > /* Redirect standard input and standard output */
|
---|
2404 | > FILE *newfp = freopen(STDOUT_FILE, "w", stdout);
|
---|
2405 | > if (newfp == NULL) { /* This happens on NT */
|
---|
2406 | > #if !defined(stdout)
|
---|
2407 | > stdout = fopen(STDOUT_FILE, "w");
|
---|
2408 | > #else
|
---|
2409 | > newfp = fopen(STDOUT_FILE, "w");
|
---|
2410 | > if (newfp) {
|
---|
2411 | > *stdout = *newfp;
|
---|
2412 | > }
|
---|
2413 | > #endif
|
---|
2414 | > }
|
---|
2415 | > newfp = freopen(STDERR_FILE, "w", stderr);
|
---|
2416 | > if (newfp == NULL) { /* This happens on NT */
|
---|
2417 | > #if !defined(stderr)
|
---|
2418 | > stderr = fopen(STDERR_FILE, "w");
|
---|
2419 | > #else
|
---|
2420 | > newfp = fopen(STDERR_FILE, "w");
|
---|
2421 | > if (newfp) {
|
---|
2422 | > *stderr = *newfp;
|
---|
2423 | > }
|
---|
2424 | > #endif
|
---|
2425 | > }
|
---|
2426 | > setbuf(stderr, NULL); /* No buffering */
|
---|
2427 | >
|
---|
2428 | > #endif // defined(__SYMBIAN32__)
|
---|
2429 | >
|
---|
2430 | > // Create our OSystem instance
|
---|
2431 | > #if defined(__SYMBIAN32__)
|
---|
2432 | > g_system = new OSystem_SDL_Symbian();
|
---|
2433 | > #else
|
---|
2434 | > g_system = new OSystem_SDL();
|
---|
2435 | > #endif
|
---|
2436 | > assert(g_system);
|
---|
2437 | >
|
---|
2438 | > #ifdef DYNAMIC_MODULES
|
---|
2439 | > PluginManager::instance().addPluginProvider(new SDLPluginProvider());
|
---|
2440 | > #endif
|
---|
2441 | >
|
---|
2442 | > // Invoke the actual ScummVM main entry point:
|
---|
2443 | > int res = scummvm_main(argc, argv);
|
---|
2444 | > g_system->quit(); // TODO: Consider removing / replacing this!
|
---|
2445 | > return res;
|
---|
2446 | > }
|
---|
2447 | >
|
---|
2448 | > #endif
|
---|
2449 | diff -rN scummvm-0.12.0/backends/platform/motoezx/module.mk scummvm-0.12.0-a1200/backends/platform/motoezx/module.mk
|
---|
2450 | 0a1,13
|
---|
2451 | > MODULE := backends/platform/motoezx
|
---|
2452 | >
|
---|
2453 | > MODULE_OBJS := \
|
---|
2454 | > events.o \
|
---|
2455 | > graphics.o \
|
---|
2456 | > main.o \
|
---|
2457 | > sdl.o
|
---|
2458 | >
|
---|
2459 | > MODULE_DIRS += \
|
---|
2460 | > backends/platform/motoezx/
|
---|
2461 | >
|
---|
2462 | > # We don't use the rules.mk here on purpose
|
---|
2463 | > OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS)
|
---|
2464 | diff -rN scummvm-0.12.0/backends/platform/motoezx/sdl.cpp scummvm-0.12.0-a1200/backends/platform/motoezx/sdl.cpp
|
---|
2465 | 0a1,744
|
---|
2466 | > /* ScummVM - Graphic Adventure Engine
|
---|
2467 | > *
|
---|
2468 | > * ScummVM is the legal property of its developers, whose names
|
---|
2469 | > * are too numerous to list here. Please refer to the COPYRIGHT
|
---|
2470 | > * file distributed with this source distribution.
|
---|
2471 | > *
|
---|
2472 | > * This program is free software; you can redistribute it and/or
|
---|
2473 | > * modify it under the terms of the GNU General Public License
|
---|
2474 | > * as published by the Free Software Foundation; either version 2
|
---|
2475 | > * of the License, or (at your option) any later version.
|
---|
2476 | >
|
---|
2477 | > * This program is distributed in the hope that it will be useful,
|
---|
2478 | > * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
2479 | > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
2480 | > * GNU General Public License for more details.
|
---|
2481 | >
|
---|
2482 | > * You should have received a copy of the GNU General Public License
|
---|
2483 | > * along with this program; if not, write to the Free Software
|
---|
2484 | > * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
---|
2485 | > *
|
---|
2486 | > * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-0-12-0/backends/platform/sdl/sdl.cpp $
|
---|
2487 | > * $Id: sdl.cpp 33386 2008-07-29 00:02:50Z fingolfin $
|
---|
2488 | > *
|
---|
2489 | > */
|
---|
2490 | >
|
---|
2491 | > #include "backends/platform/motoezx/sdl.h"
|
---|
2492 | > #include "common/config-manager.h"
|
---|
2493 | > #include "common/events.h"
|
---|
2494 | > #include "common/util.h"
|
---|
2495 | >
|
---|
2496 | > #include "backends/saves/default/default-saves.h"
|
---|
2497 | > #include "backends/timer/default/default-timer.h"
|
---|
2498 | > #include "sound/mixer_intern.h"
|
---|
2499 | >
|
---|
2500 | > #include "icons/scummvm.xpm"
|
---|
2501 | >
|
---|
2502 | > #include <time.h> // for getTimeAndDate()
|
---|
2503 | >
|
---|
2504 | > //#define SAMPLES_PER_SEC 11025
|
---|
2505 | > #define SAMPLES_PER_SEC 22050
|
---|
2506 | > //#define SAMPLES_PER_SEC 44100
|
---|
2507 | >
|
---|
2508 | > /*
|
---|
2509 | > * Include header files needed for the getFilesystemFactory() method.
|
---|
2510 | > */
|
---|
2511 | > #if defined(__amigaos4__)
|
---|
2512 | > #include "backends/fs/amigaos4/amigaos4-fs-factory.h"
|
---|
2513 | > #elif defined(UNIX)
|
---|
2514 | > #include "backends/fs/posix/posix-fs-factory.h"
|
---|
2515 | > #elif defined(WIN32)
|
---|
2516 | > #include "backends/fs/windows/windows-fs-factory.h"
|
---|
2517 | > #endif
|
---|
2518 | >
|
---|
2519 | >
|
---|
2520 | > static Uint32 timer_handler(Uint32 interval, void *param) {
|
---|
2521 | > ((DefaultTimerManager *)param)->handler();
|
---|
2522 | > return interval;
|
---|
2523 | > }
|
---|
2524 | >
|
---|
2525 | > void OSystem_SDL::initBackend() {
|
---|
2526 | > assert(!_inited);
|
---|
2527 | >
|
---|
2528 | > int joystick_num = ConfMan.getInt("joystick_num");
|
---|
2529 | > uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
|
---|
2530 | >
|
---|
2531 | > if (ConfMan.hasKey("disable_sdl_parachute"))
|
---|
2532 | > sdlFlags |= SDL_INIT_NOPARACHUTE;
|
---|
2533 | >
|
---|
2534 | > #ifdef _WIN32_WCE
|
---|
2535 | > if (ConfMan.hasKey("use_GDI") && ConfMan.getBool("use_GDI")) {
|
---|
2536 | > SDL_VideoInit("windib", 0);
|
---|
2537 | > sdlFlags ^= SDL_INIT_VIDEO;
|
---|
2538 | > }
|
---|
2539 | > #endif
|
---|
2540 | >
|
---|
2541 | > if (joystick_num > -1)
|
---|
2542 | > sdlFlags |= SDL_INIT_JOYSTICK;
|
---|
2543 | >
|
---|
2544 | > if (SDL_Init(sdlFlags) == -1) {
|
---|
2545 | > error("Could not initialize SDL: %s", SDL_GetError());
|
---|
2546 | > }
|
---|
2547 | >
|
---|
2548 | > _graphicsMutex = createMutex();
|
---|
2549 | >
|
---|
2550 | > SDL_ShowCursor(SDL_DISABLE);
|
---|
2551 | >
|
---|
2552 | > // Enable unicode support if possible
|
---|
2553 | > SDL_EnableUNICODE(1);
|
---|
2554 | >
|
---|
2555 | > _cksumValid = false;
|
---|
2556 | > #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && !defined(DISABLE_SCALERS)
|
---|
2557 | > _mode = GFX_DOUBLESIZE;
|
---|
2558 | > _scaleFactor = 2;
|
---|
2559 | > _scalerProc = Normal2x;
|
---|
2560 | > _adjustAspectRatio = ConfMan.getBool("aspect_ratio");
|
---|
2561 | > #else // for small screen platforms
|
---|
2562 | > _mode = GFX_NORMAL;
|
---|
2563 | > _scaleFactor = 1;
|
---|
2564 | > _scalerProc = Normal1x;
|
---|
2565 | > _adjustAspectRatio = false;
|
---|
2566 | > #endif
|
---|
2567 | > _scalerType = 0;
|
---|
2568 | > _modeFlags = 0;
|
---|
2569 | >
|
---|
2570 | > #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
|
---|
2571 | > _fullscreen = ConfMan.getBool("fullscreen");
|
---|
2572 | > #else
|
---|
2573 | > _fullscreen = true;
|
---|
2574 | > #endif
|
---|
2575 | >
|
---|
2576 | > #if !defined(MACOSX) && !defined(__SYMBIAN32__)
|
---|
2577 | > // Setup a custom program icon.
|
---|
2578 | > // Don't set icon on OS X, as we use a nicer external icon there.
|
---|
2579 | > // Don't for Symbian: it uses the EScummVM.aif file for the icon.
|
---|
2580 | > setupIcon();
|
---|
2581 | > #endif
|
---|
2582 | >
|
---|
2583 | > // enable joystick
|
---|
2584 | > if (joystick_num > -1 && SDL_NumJoysticks() > 0) {
|
---|
2585 | > printf("Using joystick: %s\n", SDL_JoystickName(0));
|
---|
2586 | > _joystick = SDL_JoystickOpen(joystick_num);
|
---|
2587 | > }
|
---|
2588 | >
|
---|
2589 | >
|
---|
2590 | > // Create the savefile manager, if none exists yet (we check for this to
|
---|
2591 | > // allow subclasses to provide their own).
|
---|
2592 | > if (_savefile == 0) {
|
---|
2593 | > _savefile = new DefaultSaveFileManager();
|
---|
2594 | > }
|
---|
2595 | >
|
---|
2596 | > // Create and hook up the mixer, if none exists yet (we check for this to
|
---|
2597 | > // allow subclasses to provide their own).
|
---|
2598 | > if (_mixer == 0) {
|
---|
2599 | > setupMixer();
|
---|
2600 | > }
|
---|
2601 | >
|
---|
2602 | > // Create and hook up the timer manager, if none exists yet (we check for
|
---|
2603 | > // this to allow subclasses to provide their own).
|
---|
2604 | > if (_timer == 0) {
|
---|
2605 | > // Note: We could implement a custom SDLTimerManager by using
|
---|
2606 | > // SDL_AddTimer. That might yield better timer resolution, but it would
|
---|
2607 | > // also change the semantics of a timer: Right now, ScummVM timers
|
---|
2608 | > // *never* run in parallel, due to the way they are implemented. If we
|
---|
2609 | > // switched to SDL_AddTimer, each timer might run in a separate thread.
|
---|
2610 | > // However, not all our code is prepared for that, so we can't just
|
---|
2611 | > // switch. Still, it's a potential future change to keep in mind.
|
---|
2612 | > _timer = new DefaultTimerManager();
|
---|
2613 | > _timerID = SDL_AddTimer(10, &timer_handler, _timer);
|
---|
2614 | > }
|
---|
2615 | >
|
---|
2616 | > // Invoke parent implementation of this method
|
---|
2617 | > OSystem::initBackend();
|
---|
2618 | >
|
---|
2619 | > _inited = true;
|
---|
2620 | > }
|
---|
2621 | >
|
---|
2622 | > OSystem_SDL::OSystem_SDL()
|
---|
2623 | > :
|
---|
2624 | > #ifdef USE_OSD
|
---|
2625 | > _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0),
|
---|
2626 | > #endif
|
---|
2627 | > _hwscreen(0), _screen(0), _screenWidth(0), _screenHeight(0),
|
---|
2628 | > _tmpscreen(0), _overlayWidth(0), _overlayHeight(0),
|
---|
2629 | > _overlayVisible(false),
|
---|
2630 | > _overlayscreen(0), _tmpscreen2(0),
|
---|
2631 | > _samplesPerSec(0),
|
---|
2632 | > _cdrom(0), _scalerProc(0), _modeChanged(false), _screenChangeCount(0), _dirtyChecksums(0),
|
---|
2633 | > _mouseVisible(false), _mouseDrawn(false), _mouseData(0), _mouseSurface(0),
|
---|
2634 | > _mouseOrigSurface(0), _cursorTargetScale(1), _cursorPaletteDisabled(true),
|
---|
2635 | > _joystick(0),
|
---|
2636 | > _currentShakePos(0), _newShakePos(0),
|
---|
2637 | > _paletteDirtyStart(0), _paletteDirtyEnd(0),
|
---|
2638 | > #ifdef MIXER_DOUBLE_BUFFERING
|
---|
2639 | > _soundMutex(0), _soundCond(0), _soundThread(0),
|
---|
2640 | > _soundThreadIsRunning(false), _soundThreadShouldQuit(false),
|
---|
2641 | > #endif
|
---|
2642 | > _savefile(0),
|
---|
2643 | > _mixer(0),
|
---|
2644 | > _timer(0),
|
---|
2645 | > _screenIsLocked(false),
|
---|
2646 | > _graphicsMutex(0), _transactionMode(kTransactionNone) {
|
---|
2647 | >
|
---|
2648 | > // allocate palette storage
|
---|
2649 | > _currentPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256);
|
---|
2650 | > _cursorPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256);
|
---|
2651 | >
|
---|
2652 | > _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0;
|
---|
2653 | >
|
---|
2654 | > // reset mouse state
|
---|
2655 | > memset(&_km, 0, sizeof(_km));
|
---|
2656 | > memset(&_mouseCurState, 0, sizeof(_mouseCurState));
|
---|
2657 | >
|
---|
2658 | > _inited = false;
|
---|
2659 | > }
|
---|
2660 | >
|
---|
2661 | > OSystem_SDL::~OSystem_SDL() {
|
---|
2662 | > SDL_RemoveTimer(_timerID);
|
---|
2663 | > closeMixer();
|
---|
2664 | >
|
---|
2665 | > free(_dirtyChecksums);
|
---|
2666 | > free(_currentPalette);
|
---|
2667 | > free(_cursorPalette);
|
---|
2668 | > free(_mouseData);
|
---|
2669 | >
|
---|
2670 | > delete _savefile;
|
---|
2671 | > delete _timer;
|
---|
2672 | > }
|
---|
2673 | >
|
---|
2674 | > uint32 OSystem_SDL::getMillis() {
|
---|
2675 | > uint32 millis = st_get_ticks();
|
---|
2676 | > getEventManager()->processMillis(millis);
|
---|
2677 | > return millis;
|
---|
2678 | > }
|
---|
2679 | >
|
---|
2680 | > void OSystem_SDL::delayMillis(uint msecs) {
|
---|
2681 | > SDL_Delay(msecs);
|
---|
2682 | > }
|
---|
2683 | >
|
---|
2684 | > void OSystem_SDL::getTimeAndDate(struct tm &t) const {
|
---|
2685 | > time_t curTime = time(0);
|
---|
2686 | > t = *localtime(&curTime);
|
---|
2687 | > }
|
---|
2688 | >
|
---|
2689 | > Common::TimerManager *OSystem_SDL::getTimerManager() {
|
---|
2690 | > assert(_timer);
|
---|
2691 | > return _timer;
|
---|
2692 | > }
|
---|
2693 | >
|
---|
2694 | > Common::SaveFileManager *OSystem_SDL::getSavefileManager() {
|
---|
2695 | > assert(_savefile);
|
---|
2696 | > return _savefile;
|
---|
2697 | > }
|
---|
2698 | >
|
---|
2699 | > FilesystemFactory *OSystem_SDL::getFilesystemFactory() {
|
---|
2700 | > #if defined(__amigaos4__)
|
---|
2701 | > return &AmigaOSFilesystemFactory::instance();
|
---|
2702 | > #elif defined(UNIX)
|
---|
2703 | > return &POSIXFilesystemFactory::instance();
|
---|
2704 | > #elif defined(WIN32)
|
---|
2705 | > return &WindowsFilesystemFactory::instance();
|
---|
2706 | > #elif defined(__SYMBIAN32__)
|
---|
2707 | > // Do nothing since its handled by the Symbian SDL inheritance
|
---|
2708 | > #else
|
---|
2709 | > #error Unknown and unsupported backend in OSystem_SDL::getFilesystemFactory
|
---|
2710 | > #endif
|
---|
2711 | > }
|
---|
2712 | >
|
---|
2713 | > void OSystem_SDL::setWindowCaption(const char *caption) {
|
---|
2714 | > SDL_WM_SetCaption(caption, caption);
|
---|
2715 | > }
|
---|
2716 | >
|
---|
2717 | > bool OSystem_SDL::hasFeature(Feature f) {
|
---|
2718 | > return
|
---|
2719 | > (f == kFeatureFullscreenMode) ||
|
---|
2720 | > (f == kFeatureAspectRatioCorrection) ||
|
---|
2721 | > (f == kFeatureAutoComputeDirtyRects) ||
|
---|
2722 | > (f == kFeatureCursorHasPalette) ||
|
---|
2723 | > (f == kFeatureIconifyWindow);
|
---|
2724 | > }
|
---|
2725 | >
|
---|
2726 | > void OSystem_SDL::setFeatureState(Feature f, bool enable) {
|
---|
2727 | > switch (f) {
|
---|
2728 | > case kFeatureFullscreenMode:
|
---|
2729 | > setFullscreenMode(enable);
|
---|
2730 | > break;
|
---|
2731 | > case kFeatureAspectRatioCorrection:
|
---|
2732 | > setAspectRatioCorrection(enable);
|
---|
2733 | > break;
|
---|
2734 | > case kFeatureAutoComputeDirtyRects:
|
---|
2735 | > if (enable)
|
---|
2736 | > _modeFlags |= DF_WANT_RECT_OPTIM;
|
---|
2737 | > else
|
---|
2738 | > _modeFlags &= ~DF_WANT_RECT_OPTIM;
|
---|
2739 | > break;
|
---|
2740 | > case kFeatureIconifyWindow:
|
---|
2741 | > if (enable)
|
---|
2742 | > SDL_WM_IconifyWindow();
|
---|
2743 | > break;
|
---|
2744 | > default:
|
---|
2745 | > break;
|
---|
2746 | > }
|
---|
2747 | > }
|
---|
2748 | >
|
---|
2749 | > bool OSystem_SDL::getFeatureState(Feature f) {
|
---|
2750 | > assert (_transactionMode == kTransactionNone);
|
---|
2751 | >
|
---|
2752 | > switch (f) {
|
---|
2753 | > case kFeatureFullscreenMode:
|
---|
2754 | > return _fullscreen;
|
---|
2755 | > case kFeatureAspectRatioCorrection:
|
---|
2756 | > return _adjustAspectRatio;
|
---|
2757 | > case kFeatureAutoComputeDirtyRects:
|
---|
2758 | > return _modeFlags & DF_WANT_RECT_OPTIM;
|
---|
2759 | > default:
|
---|
2760 | > return false;
|
---|
2761 | > }
|
---|
2762 | > }
|
---|
2763 | >
|
---|
2764 | > void OSystem_SDL::quit() {
|
---|
2765 | > if (_cdrom) {
|
---|
2766 | > SDL_CDStop(_cdrom);
|
---|
2767 | > SDL_CDClose(_cdrom);
|
---|
2768 | > }
|
---|
2769 | > unloadGFXMode();
|
---|
2770 | > deleteMutex(_graphicsMutex);
|
---|
2771 | >
|
---|
2772 | > if (_joystick)
|
---|
2773 | > SDL_JoystickClose(_joystick);
|
---|
2774 | > SDL_ShowCursor(SDL_ENABLE);
|
---|
2775 | >
|
---|
2776 | > SDL_RemoveTimer(_timerID);
|
---|
2777 | > closeMixer();
|
---|
2778 | >
|
---|
2779 | > free(_dirtyChecksums);
|
---|
2780 | > free(_currentPalette);
|
---|
2781 | > free(_cursorPalette);
|
---|
2782 | > free(_mouseData);
|
---|
2783 | >
|
---|
2784 | > delete _savefile;
|
---|
2785 | > delete _timer;
|
---|
2786 | >
|
---|
2787 | > SDL_Quit();
|
---|
2788 | >
|
---|
2789 | > delete getEventManager();
|
---|
2790 | >
|
---|
2791 | > exit(0);
|
---|
2792 | > }
|
---|
2793 | >
|
---|
2794 | > void OSystem_SDL::setupIcon() {
|
---|
2795 | > int w, h, ncols, nbytes, i;
|
---|
2796 | > unsigned int rgba[256], icon[32 * 32];
|
---|
2797 | > unsigned char mask[32][4];
|
---|
2798 | >
|
---|
2799 | > sscanf(scummvm_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes);
|
---|
2800 | > if ((w != 32) || (h != 32) || (ncols > 255) || (nbytes > 1)) {
|
---|
2801 | > warning("Could not load the icon (%d %d %d %d)", w, h, ncols, nbytes);
|
---|
2802 | > return;
|
---|
2803 | > }
|
---|
2804 | > for (i = 0; i < ncols; i++) {
|
---|
2805 | > unsigned char code;
|
---|
2806 | > char color[32];
|
---|
2807 | > unsigned int col;
|
---|
2808 | > sscanf(scummvm_icon[1 + i], "%c c %s", &code, color);
|
---|
2809 | > if (!strcmp(color, "None"))
|
---|
2810 | > col = 0x00000000;
|
---|
2811 | > else if (!strcmp(color, "black"))
|
---|
2812 | > col = 0xFF000000;
|
---|
2813 | > else if (color[0] == '#') {
|
---|
2814 | > sscanf(color + 1, "%06x", &col);
|
---|
2815 | > col |= 0xFF000000;
|
---|
2816 | > } else {
|
---|
2817 | > warning("Could not load the icon (%d %s - %s) ", code, color, scummvm_icon[1 + i]);
|
---|
2818 | > return;
|
---|
2819 | > }
|
---|
2820 | >
|
---|
2821 | > rgba[code] = col;
|
---|
2822 | > }
|
---|
2823 | > memset(mask, 0, sizeof(mask));
|
---|
2824 | > for (h = 0; h < 32; h++) {
|
---|
2825 | > const char *line = scummvm_icon[1 + ncols + h];
|
---|
2826 | > for (w = 0; w < 32; w++) {
|
---|
2827 | > icon[w + 32 * h] = rgba[(int)line[w]];
|
---|
2828 | > if (rgba[(int)line[w]] & 0xFF000000) {
|
---|
2829 | > mask[h][w >> 3] |= 1 << (7 - (w & 0x07));
|
---|
2830 | > }
|
---|
2831 | > }
|
---|
2832 | > }
|
---|
2833 | >
|
---|
2834 | > SDL_Surface *sdl_surf = SDL_CreateRGBSurfaceFrom(icon, 32, 32, 32, 32 * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
|
---|
2835 | > SDL_WM_SetIcon(sdl_surf, (unsigned char *) mask);
|
---|
2836 | > SDL_FreeSurface(sdl_surf);
|
---|
2837 | > }
|
---|
2838 | >
|
---|
2839 | > OSystem::MutexRef OSystem_SDL::createMutex(void) {
|
---|
2840 | > return (MutexRef) SDL_CreateMutex();
|
---|
2841 | > }
|
---|
2842 | >
|
---|
2843 | > void OSystem_SDL::lockMutex(MutexRef mutex) {
|
---|
2844 | > SDL_mutexP((SDL_mutex *) mutex);
|
---|
2845 | > }
|
---|
2846 | >
|
---|
2847 | > void OSystem_SDL::unlockMutex(MutexRef mutex) {
|
---|
2848 | > SDL_mutexV((SDL_mutex *) mutex);
|
---|
2849 | > }
|
---|
2850 | >
|
---|
2851 | > void OSystem_SDL::deleteMutex(MutexRef mutex) {
|
---|
2852 | > SDL_DestroyMutex((SDL_mutex *) mutex);
|
---|
2853 | > }
|
---|
2854 | >
|
---|
2855 | > #pragma mark -
|
---|
2856 | > #pragma mark --- Audio ---
|
---|
2857 | > #pragma mark -
|
---|
2858 | >
|
---|
2859 | > #ifdef MIXER_DOUBLE_BUFFERING
|
---|
2860 | >
|
---|
2861 | > void OSystem_SDL::mixerProducerThread() {
|
---|
2862 | > byte nextSoundBuffer;
|
---|
2863 | >
|
---|
2864 | > SDL_LockMutex(_soundMutex);
|
---|
2865 | > while (true) {
|
---|
2866 | > // Wait till we are allowed to produce data
|
---|
2867 | > SDL_CondWait(_soundCond, _soundMutex);
|
---|
2868 | >
|
---|
2869 | > if (_soundThreadShouldQuit)
|
---|
2870 | > break;
|
---|
2871 | >
|
---|
2872 | > // Generate samples and put them into the next buffer
|
---|
2873 | > nextSoundBuffer = _activeSoundBuf ^ 1;
|
---|
2874 | > _mixer->mixCallback(_soundBuffers[nextSoundBuffer], _soundBufSize);
|
---|
2875 | >
|
---|
2876 | > // Swap buffers
|
---|
2877 | > _activeSoundBuf = nextSoundBuffer;
|
---|
2878 | > }
|
---|
2879 | > SDL_UnlockMutex(_soundMutex);
|
---|
2880 | > }
|
---|
2881 | >
|
---|
2882 | > int SDLCALL OSystem_SDL::mixerProducerThreadEntry(void *arg) {
|
---|
2883 | > OSystem_SDL *this_ = (OSystem_SDL *)arg;
|
---|
2884 | > assert(this_);
|
---|
2885 | > this_->mixerProducerThread();
|
---|
2886 | > return 0;
|
---|
2887 | > }
|
---|
2888 | >
|
---|
2889 | >
|
---|
2890 | > void OSystem_SDL::initThreadedMixer(Audio::MixerImpl *mixer, uint bufSize) {
|
---|
2891 | > _soundThreadIsRunning = false;
|
---|
2892 | > _soundThreadShouldQuit = false;
|
---|
2893 | >
|
---|
2894 | > // Create mutex and condition variable
|
---|
2895 | > _soundMutex = SDL_CreateMutex();
|
---|
2896 | > _soundCond = SDL_CreateCond();
|
---|
2897 | >
|
---|
2898 | > // Create two sound buffers
|
---|
2899 | > _activeSoundBuf = 0;
|
---|
2900 | > _soundBufSize = bufSize;
|
---|
2901 | > _soundBuffers[0] = (byte *)calloc(1, bufSize);
|
---|
2902 | > _soundBuffers[1] = (byte *)calloc(1, bufSize);
|
---|
2903 | >
|
---|
2904 | > _soundThreadIsRunning = true;
|
---|
2905 | >
|
---|
2906 | > // Finally start the thread
|
---|
2907 | > _soundThread = SDL_CreateThread(mixerProducerThreadEntry, this);
|
---|
2908 | > }
|
---|
2909 | >
|
---|
2910 | > void OSystem_SDL::deinitThreadedMixer() {
|
---|
2911 | > // Kill thread?? _soundThread
|
---|
2912 | >
|
---|
2913 | > if (_soundThreadIsRunning) {
|
---|
2914 | > // Signal the producer thread to end, and wait for it to actually finish.
|
---|
2915 | > _soundThreadShouldQuit = true;
|
---|
2916 | > SDL_CondBroadcast(_soundCond);
|
---|
2917 | > SDL_WaitThread(_soundThread, NULL);
|
---|
2918 | >
|
---|
2919 | > // Kill the mutex & cond variables.
|
---|
2920 | > // Attention: AT this point, the mixer callback must not be running
|
---|
2921 | > // anymore, else we will crash!
|
---|
2922 | > SDL_DestroyMutex(_soundMutex);
|
---|
2923 | > SDL_DestroyCond(_soundCond);
|
---|
2924 | >
|
---|
2925 | > _soundThreadIsRunning = false;
|
---|
2926 | >
|
---|
2927 | > free(_soundBuffers[0]);
|
---|
2928 | > free(_soundBuffers[1]);
|
---|
2929 | > }
|
---|
2930 | > }
|
---|
2931 | >
|
---|
2932 | >
|
---|
2933 | > void OSystem_SDL::mixCallback(void *arg, byte *samples, int len) {
|
---|
2934 | > OSystem_SDL *this_ = (OSystem_SDL *)arg;
|
---|
2935 | > assert(this_);
|
---|
2936 | > assert(this_->_mixer);
|
---|
2937 | >
|
---|
2938 | > assert((int)this_->_soundBufSize == len);
|
---|
2939 | >
|
---|
2940 | > // Lock mutex, to ensure our data is not overwritten by the producer thread
|
---|
2941 | > SDL_LockMutex(this_->_soundMutex);
|
---|
2942 | >
|
---|
2943 | > // Copy data from the current sound buffer
|
---|
2944 | > memcpy(samples, this_->_soundBuffers[this_->_activeSoundBuf], len);
|
---|
2945 | >
|
---|
2946 | > // Unlock mutex and wake up the produced thread
|
---|
2947 | > SDL_UnlockMutex(this_->_soundMutex);
|
---|
2948 | > SDL_CondSignal(this_->_soundCond);
|
---|
2949 | > }
|
---|
2950 | >
|
---|
2951 | > #else
|
---|
2952 | >
|
---|
2953 | > void OSystem_SDL::mixCallback(void *sys, byte *samples, int len) {
|
---|
2954 | > OSystem_SDL *this_ = (OSystem_SDL *)sys;
|
---|
2955 | > assert(this_);
|
---|
2956 | > assert(this_->_mixer);
|
---|
2957 | >
|
---|
2958 | > this_->_mixer->mixCallback(samples, len);
|
---|
2959 | > }
|
---|
2960 | >
|
---|
2961 | > #endif
|
---|
2962 | >
|
---|
2963 | > void OSystem_SDL::setupMixer() {
|
---|
2964 | > SDL_AudioSpec desired;
|
---|
2965 | >
|
---|
2966 | > // Determine the desired output sampling frequency.
|
---|
2967 | > _samplesPerSec = 0;
|
---|
2968 | > if (ConfMan.hasKey("output_rate"))
|
---|
2969 | > _samplesPerSec = ConfMan.getInt("output_rate");
|
---|
2970 | > if (_samplesPerSec <= 0)
|
---|
2971 | > _samplesPerSec = SAMPLES_PER_SEC;
|
---|
2972 | >
|
---|
2973 | > // Determine the sample buffer size. We want it to store enough data for
|
---|
2974 | > // about 1/16th of a second. Note that it must be a power of two.
|
---|
2975 | > // So e.g. at 22050 Hz, we request a sample buffer size of 2048.
|
---|
2976 | > int samples = 8192;
|
---|
2977 | > while (16 * samples >= _samplesPerSec) {
|
---|
2978 | > samples >>= 1;
|
---|
2979 | > }
|
---|
2980 | >
|
---|
2981 | > memset(&desired, 0, sizeof(desired));
|
---|
2982 | > desired.freq = _samplesPerSec;
|
---|
2983 | > desired.format = AUDIO_S16SYS;
|
---|
2984 | > desired.channels = 2;
|
---|
2985 | > desired.samples = (uint16)samples;
|
---|
2986 | > desired.callback = mixCallback;
|
---|
2987 | > desired.userdata = this;
|
---|
2988 | >
|
---|
2989 | > // Create the mixer instance
|
---|
2990 | > assert(!_mixer);
|
---|
2991 | > _mixer = new Audio::MixerImpl(this);
|
---|
2992 | > assert(_mixer);
|
---|
2993 | >
|
---|
2994 | > if (SDL_OpenAudio(&desired, &obtained) != 0) {
|
---|
2995 | > warning("Could not open audio device: %s", SDL_GetError());
|
---|
2996 | > _samplesPerSec = 0;
|
---|
2997 | > _mixer->setReady(false);
|
---|
2998 | > } else {
|
---|
2999 | > // Note: This should be the obtained output rate, but it seems that at
|
---|
3000 | > // least on some platforms SDL will lie and claim it did get the rate
|
---|
3001 | > // even if it didn't. Probably only happens for "weird" rates, though.
|
---|
3002 | > _samplesPerSec = obtained.freq;
|
---|
3003 | > debug(1, "Output sample rate: %d Hz", _samplesPerSec);
|
---|
3004 | >
|
---|
3005 | > // Tell the mixer that we are ready and start the sound processing
|
---|
3006 | > _mixer->setOutputRate(_samplesPerSec);
|
---|
3007 | > _mixer->setReady(true);
|
---|
3008 | >
|
---|
3009 | > #ifdef MIXER_DOUBLE_BUFFERING
|
---|
3010 | > initThreadedMixer(_mixer, obtained.samples * 4);
|
---|
3011 | > #endif
|
---|
3012 | >
|
---|
3013 | > // start the sound system
|
---|
3014 | > SDL_PauseAudio(0);
|
---|
3015 | > }
|
---|
3016 | > }
|
---|
3017 | >
|
---|
3018 | > void OSystem_SDL::closeMixer() {
|
---|
3019 | > if (_mixer)
|
---|
3020 | > _mixer->setReady(false);
|
---|
3021 | >
|
---|
3022 | > SDL_CloseAudio();
|
---|
3023 | >
|
---|
3024 | > delete _mixer;
|
---|
3025 | > _mixer = 0;
|
---|
3026 | >
|
---|
3027 | > #ifdef MIXER_DOUBLE_BUFFERING
|
---|
3028 | > deinitThreadedMixer();
|
---|
3029 | > #endif
|
---|
3030 | >
|
---|
3031 | > }
|
---|
3032 | >
|
---|
3033 | > Audio::Mixer *OSystem_SDL::getMixer() {
|
---|
3034 | > assert(_mixer);
|
---|
3035 | > return _mixer;
|
---|
3036 | > }
|
---|
3037 | >
|
---|
3038 | > #pragma mark -
|
---|
3039 | > #pragma mark --- CD Audio ---
|
---|
3040 | > #pragma mark -
|
---|
3041 | >
|
---|
3042 | > bool OSystem_SDL::openCD(int drive) {
|
---|
3043 | > if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
|
---|
3044 | > _cdrom = NULL;
|
---|
3045 | > else {
|
---|
3046 | > _cdrom = SDL_CDOpen(drive);
|
---|
3047 | > // Did it open? Check if _cdrom is NULL
|
---|
3048 | > if (!_cdrom) {
|
---|
3049 | > warning("Couldn't open drive: %s", SDL_GetError());
|
---|
3050 | > } else {
|
---|
3051 | > _cdNumLoops = 0;
|
---|
3052 | > _cdStopTime = 0;
|
---|
3053 | > _cdEndTime = 0;
|
---|
3054 | > }
|
---|
3055 | > }
|
---|
3056 | >
|
---|
3057 | > return (_cdrom != NULL);
|
---|
3058 | > }
|
---|
3059 | >
|
---|
3060 | > void OSystem_SDL::stopCD() { /* Stop CD Audio in 1/10th of a second */
|
---|
3061 | > _cdStopTime = st_get_ticks() + 100;
|
---|
3062 | > _cdNumLoops = 0;
|
---|
3063 | > }
|
---|
3064 | >
|
---|
3065 | > void OSystem_SDL::playCD(int track, int num_loops, int start_frame, int duration) {
|
---|
3066 | > if (!num_loops && !start_frame)
|
---|
3067 | > return;
|
---|
3068 | >
|
---|
3069 | > if (!_cdrom)
|
---|
3070 | > return;
|
---|
3071 | >
|
---|
3072 | > if (duration > 0)
|
---|
3073 | > duration += 5;
|
---|
3074 | >
|
---|
3075 | > _cdTrack = track;
|
---|
3076 | > _cdNumLoops = num_loops;
|
---|
3077 | > _cdStartFrame = start_frame;
|
---|
3078 | >
|
---|
3079 | > SDL_CDStatus(_cdrom);
|
---|
3080 | > if (start_frame == 0 && duration == 0)
|
---|
3081 | > SDL_CDPlayTracks(_cdrom, track, 0, 1, 0);
|
---|
3082 | > else
|
---|
3083 | > SDL_CDPlayTracks(_cdrom, track, start_frame, 0, duration);
|
---|
3084 | > _cdDuration = duration;
|
---|
3085 | > _cdStopTime = 0;
|
---|
3086 | > _cdEndTime = st_get_ticks() + _cdrom->track[track].length * 1000 / CD_FPS;
|
---|
3087 | > }
|
---|
3088 | >
|
---|
3089 | > bool OSystem_SDL::pollCD() {
|
---|
3090 | > if (!_cdrom)
|
---|
3091 | > return false;
|
---|
3092 | >
|
---|
3093 | > return (_cdNumLoops != 0 && (st_get_ticks() < _cdEndTime || SDL_CDStatus(_cdrom) != CD_STOPPED));
|
---|
3094 | > }
|
---|
3095 | >
|
---|
3096 | > void OSystem_SDL::updateCD() {
|
---|
3097 | > if (!_cdrom)
|
---|
3098 | > return;
|
---|
3099 | >
|
---|
3100 | > if (_cdStopTime != 0 && st_get_ticks() >= _cdStopTime) {
|
---|
3101 | > SDL_CDStop(_cdrom);
|
---|
3102 | > _cdNumLoops = 0;
|
---|
3103 | > _cdStopTime = 0;
|
---|
3104 | > return;
|
---|
3105 | > }
|
---|
3106 | >
|
---|
3107 | > if (_cdNumLoops == 0 || st_get_ticks() < _cdEndTime)
|
---|
3108 | > return;
|
---|
3109 | >
|
---|
3110 | > if (_cdNumLoops != 1 && SDL_CDStatus(_cdrom) != CD_STOPPED) {
|
---|
3111 | > // Wait another second for it to be done
|
---|
3112 | > _cdEndTime += 1000;
|
---|
3113 | > return;
|
---|
3114 | > }
|
---|
3115 | >
|
---|
3116 | > if (_cdNumLoops > 0)
|
---|
3117 | > _cdNumLoops--;
|
---|
3118 | >
|
---|
3119 | > if (_cdNumLoops != 0) {
|
---|
3120 | > if (_cdStartFrame == 0 && _cdDuration == 0)
|
---|
3121 | > SDL_CDPlayTracks(_cdrom, _cdTrack, 0, 1, 0);
|
---|
3122 | > else
|
---|
3123 | > SDL_CDPlayTracks(_cdrom, _cdTrack, _cdStartFrame, 0, _cdDuration);
|
---|
3124 | > _cdEndTime = st_get_ticks() + _cdrom->track[_cdTrack].length * 1000 / CD_FPS;
|
---|
3125 | > }
|
---|
3126 | > }
|
---|
3127 | >
|
---|
3128 | > int OSystem_SDL::mySDL_PollEvent(SDL_Event *event) {
|
---|
3129 | > int r = SDL_PollEvent(event);
|
---|
3130 | > if (!r)
|
---|
3131 | > return 0;
|
---|
3132 | > if (event->type == SDL_ACTIVEEVENT){
|
---|
3133 | > if (event->active.state == SDL_APPINPUTFOCUS && !event->active.gain){
|
---|
3134 | > bool st_pause = st_pause_ticks_started();
|
---|
3135 | > if (!st_pause)
|
---|
3136 | > st_pause_ticks_start();
|
---|
3137 | > suspendAudio();
|
---|
3138 | > for(;;){
|
---|
3139 | > printf("wait\n");
|
---|
3140 | > r = SDL_WaitEvent(event);
|
---|
3141 | > printf("wait done\n");
|
---|
3142 | > if (!r)
|
---|
3143 | > continue;
|
---|
3144 | > if (event->type == SDL_QUIT)
|
---|
3145 | > return 1;
|
---|
3146 | > if (event->type != SDL_ACTIVEEVENT)
|
---|
3147 | > continue;
|
---|
3148 | > if (event->active.state == SDL_APPINPUTFOCUS && event->active.gain){
|
---|
3149 | > resumeAudio();
|
---|
3150 | > if (!st_pause) st_pause_ticks_stop();
|
---|
3151 | > return 1;
|
---|
3152 | > }
|
---|
3153 | > }
|
---|
3154 | > }
|
---|
3155 | > }
|
---|
3156 | > return r;
|
---|
3157 | > }
|
---|
3158 | >
|
---|
3159 | > unsigned int st_pause_ticks, st_pause_count;
|
---|
3160 | >
|
---|
3161 | > unsigned int st_get_ticks(void) {
|
---|
3162 | > if (st_pause_count != 0)
|
---|
3163 | > return /*SDL_GetTicks()*/ - st_pause_ticks /*- SDL_GetTicks()*/ + st_pause_count;
|
---|
3164 | > else
|
---|
3165 | > return SDL_GetTicks() - st_pause_ticks;
|
---|
3166 | > }
|
---|
3167 | >
|
---|
3168 | > void st_pause_ticks_init(void) {
|
---|
3169 | > st_pause_ticks = 0;
|
---|
3170 | > st_pause_count = 0;
|
---|
3171 | > }
|
---|
3172 | >
|
---|
3173 | > void st_pause_ticks_start(void) {
|
---|
3174 | > if (st_pause_count == 0)
|
---|
3175 | > st_pause_count = SDL_GetTicks();
|
---|
3176 | > }
|
---|
3177 | >
|
---|
3178 | > void st_pause_ticks_stop(void) {
|
---|
3179 | > if (st_pause_count == 0)
|
---|
3180 | > return;
|
---|
3181 | > st_pause_ticks += SDL_GetTicks() - st_pause_count;
|
---|
3182 | > st_pause_count = 0;
|
---|
3183 | > }
|
---|
3184 | >
|
---|
3185 | > bool st_pause_ticks_started(void) {
|
---|
3186 | > if (st_pause_count == 0)
|
---|
3187 | > return false;
|
---|
3188 | > else
|
---|
3189 | > return true;
|
---|
3190 | > }
|
---|
3191 | >
|
---|
3192 | > void OSystem_SDL::suspendAudio() {
|
---|
3193 | > // if (audioSuspended) return;
|
---|
3194 | > SDL_CloseAudio();
|
---|
3195 | > audioSuspended = true;
|
---|
3196 | > }
|
---|
3197 | >
|
---|
3198 | > int OSystem_SDL::resumeAudio() {
|
---|
3199 | > if (!audioSuspended)
|
---|
3200 | > return -2;
|
---|
3201 | > if (SDL_OpenAudio(&obtained, NULL) < 0){
|
---|
3202 | > printf("audio resumed\n");
|
---|
3203 | > return -1;
|
---|
3204 | > }
|
---|
3205 | > SDL_PauseAudio(0);
|
---|
3206 | > audioSuspended = false;
|
---|
3207 | > return 0;
|
---|
3208 | > }
|
---|
3209 | >
|
---|
3210 | diff -rN scummvm-0.12.0/backends/platform/motoezx/sdl.h scummvm-0.12.0-a1200/backends/platform/motoezx/sdl.h
|
---|
3211 | 0a1,463
|
---|
3212 | > /* ScummVM - Graphic Adventure Engine
|
---|
3213 | > *
|
---|
3214 | > * ScummVM is the legal property of its developers, whose names
|
---|
3215 | > * are too numerous to list here. Please refer to the COPYRIGHT
|
---|
3216 | > * file distributed with this source distribution.
|
---|
3217 | > *
|
---|
3218 | > * This program is free software; you can redistribute it and/or
|
---|
3219 | > * modify it under the terms of the GNU General Public License
|
---|
3220 | > * as published by the Free Software Foundation; either version 2
|
---|
3221 | > * of the License, or (at your option) any later version.
|
---|
3222 | >
|
---|
3223 | > * This program is distributed in the hope that it will be useful,
|
---|
3224 | > * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
3225 | > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
3226 | > * GNU General Public License for more details.
|
---|
3227 | >
|
---|
3228 | > * You should have received a copy of the GNU General Public License
|
---|
3229 | > * along with this program; if not, write to the Free Software
|
---|
3230 | > * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
---|
3231 | > *
|
---|
3232 | > * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-0-12-0/backends/platform/sdl/sdl.h $
|
---|
3233 | > * $Id: sdl.h 33075 2008-07-15 17:13:06Z fingolfin $
|
---|
3234 | > *
|
---|
3235 | > */
|
---|
3236 | >
|
---|
3237 | > #ifndef SDL_COMMON_H
|
---|
3238 | > #define SDL_COMMON_H
|
---|
3239 | >
|
---|
3240 | > #if defined(__SYMBIAN32__)
|
---|
3241 | > #include <esdl\SDL.h>
|
---|
3242 | > #else
|
---|
3243 | > #include <SDL.h>
|
---|
3244 | > #endif
|
---|
3245 | >
|
---|
3246 | > #include "common/scummsys.h"
|
---|
3247 | > #include "common/system.h"
|
---|
3248 | > #include "graphics/scaler.h"
|
---|
3249 | >
|
---|
3250 | >
|
---|
3251 | > namespace Audio {
|
---|
3252 | > class MixerImpl;
|
---|
3253 | > }
|
---|
3254 | >
|
---|
3255 | > namespace Common {
|
---|
3256 | > class SaveFileManager;
|
---|
3257 | > class TimerManager;
|
---|
3258 | > }
|
---|
3259 | >
|
---|
3260 | > #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
|
---|
3261 | > // Uncomment this to enable the 'on screen display' code.
|
---|
3262 | > #define USE_OSD 1
|
---|
3263 | > #endif
|
---|
3264 | >
|
---|
3265 | > #if defined(MACOSX)
|
---|
3266 | > // On Mac OS X, we need to double buffer the audio buffer, else anything
|
---|
3267 | > // which produces sampled data with high latency (like the MT-32 emulator)
|
---|
3268 | > // will sound terribly.
|
---|
3269 | > // This could be enabled for more / most ports in the future, but needs some
|
---|
3270 | > // testing.
|
---|
3271 | > #define MIXER_DOUBLE_BUFFERING 1
|
---|
3272 | > #endif
|
---|
3273 | >
|
---|
3274 | >
|
---|
3275 | > enum {
|
---|
3276 | > GFX_NORMAL = 0,
|
---|
3277 | > GFX_DOUBLESIZE = 1,
|
---|
3278 | > GFX_TRIPLESIZE = 2,
|
---|
3279 | > GFX_2XSAI = 3,
|
---|
3280 | > GFX_SUPER2XSAI = 4,
|
---|
3281 | > GFX_SUPEREAGLE = 5,
|
---|
3282 | > GFX_ADVMAME2X = 6,
|
---|
3283 | > GFX_ADVMAME3X = 7,
|
---|
3284 | > GFX_HQ2X = 8,
|
---|
3285 | > GFX_HQ3X = 9,
|
---|
3286 | > GFX_TV2X = 10,
|
---|
3287 | > GFX_DOTMATRIX = 11
|
---|
3288 | > };
|
---|
3289 | >
|
---|
3290 | >
|
---|
3291 | > class OSystem_SDL : public OSystem {
|
---|
3292 | > private:
|
---|
3293 | > SDL_AudioSpec obtained;
|
---|
3294 | > bool audioSuspended;
|
---|
3295 | > public:
|
---|
3296 | > OSystem_SDL();
|
---|
3297 | > virtual ~OSystem_SDL();
|
---|
3298 | >
|
---|
3299 | > virtual void initBackend();
|
---|
3300 | >
|
---|
3301 | > void beginGFXTransaction(void);
|
---|
3302 | > void endGFXTransaction(void);
|
---|
3303 | >
|
---|
3304 | > // Set the size of the video bitmap.
|
---|
3305 | > // Typically, 320x200
|
---|
3306 | > virtual void initSize(uint w, uint h); // overloaded by CE backend
|
---|
3307 | >
|
---|
3308 | > virtual int getScreenChangeID() const { return _screenChangeCount; }
|
---|
3309 | >
|
---|
3310 | > // Set colors of the palette
|
---|
3311 | > void setPalette(const byte *colors, uint start, uint num);
|
---|
3312 | >
|
---|
3313 | > // Get colors of the palette
|
---|
3314 | > void grabPalette(byte *colors, uint start, uint num);
|
---|
3315 | >
|
---|
3316 | > // Draw a bitmap to screen.
|
---|
3317 | > // The screen will not be updated to reflect the new bitmap
|
---|
3318 | > virtual void copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h); // overloaded by CE backend (FIXME)
|
---|
3319 | >
|
---|
3320 | > virtual Graphics::Surface *lockScreen();
|
---|
3321 | > virtual void unlockScreen();
|
---|
3322 | >
|
---|
3323 | > // Update the dirty areas of the screen
|
---|
3324 | > void updateScreen();
|
---|
3325 | >
|
---|
3326 | > // Either show or hide the mouse cursor
|
---|
3327 | > bool showMouse(bool visible);
|
---|
3328 | >
|
---|
3329 | > // Warp the mouse cursor. Where set_mouse_pos() only informs the
|
---|
3330 | > // backend of the mouse cursor's current position, this function
|
---|
3331 | > // actually moves the cursor to the specified position.
|
---|
3332 | > virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME)
|
---|
3333 | >
|
---|
3334 | > // Set the bitmap that's used when drawing the cursor.
|
---|
3335 | > virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME)
|
---|
3336 | >
|
---|
3337 | > // Set colors of cursor palette
|
---|
3338 | > void setCursorPalette(const byte *colors, uint start, uint num);
|
---|
3339 | >
|
---|
3340 | > // Disables or enables cursor palette
|
---|
3341 | > void disableCursorPalette(bool disable) {
|
---|
3342 | > _cursorPaletteDisabled = disable;
|
---|
3343 | > blitCursor();
|
---|
3344 | > }
|
---|
3345 | >
|
---|
3346 | > // Shaking is used in SCUMM. Set current shake position.
|
---|
3347 | > void setShakePos(int shake_pos);
|
---|
3348 | >
|
---|
3349 | > // Get the number of milliseconds since the program was started.
|
---|
3350 | > uint32 getMillis();
|
---|
3351 | >
|
---|
3352 | > // Delay for a specified amount of milliseconds
|
---|
3353 | > void delayMillis(uint msecs);
|
---|
3354 | >
|
---|
3355 | > // Get the next event.
|
---|
3356 | > // Returns true if an event was retrieved.
|
---|
3357 | > virtual bool pollEvent(Common::Event &event); // overloaded by CE backend
|
---|
3358 | >
|
---|
3359 | > // Set function that generates samples
|
---|
3360 | > virtual void setupMixer();
|
---|
3361 | > static void mixCallback(void *s, byte *samples, int len);
|
---|
3362 | >
|
---|
3363 | > virtual void closeMixer();
|
---|
3364 | >
|
---|
3365 | > virtual Audio::Mixer *getMixer();
|
---|
3366 | >
|
---|
3367 | > // Poll CD status
|
---|
3368 | > // Returns true if cd audio is playing
|
---|
3369 | > bool pollCD();
|
---|
3370 | >
|
---|
3371 | > // Play CD audio track
|
---|
3372 | > void playCD(int track, int num_loops, int start_frame, int duration);
|
---|
3373 | >
|
---|
3374 | > // Stop CD audio track
|
---|
3375 | > void stopCD();
|
---|
3376 | >
|
---|
3377 | > // Update CD audio status
|
---|
3378 | > void updateCD();
|
---|
3379 | >
|
---|
3380 | > // Quit
|
---|
3381 | > virtual void quit(); // overloaded by CE backend
|
---|
3382 | >
|
---|
3383 | > virtual void getTimeAndDate(struct tm &t) const;
|
---|
3384 | > virtual Common::TimerManager *getTimerManager();
|
---|
3385 | >
|
---|
3386 | > // Mutex handling
|
---|
3387 | > MutexRef createMutex();
|
---|
3388 | > void lockMutex(MutexRef mutex);
|
---|
3389 | > void unlockMutex(MutexRef mutex);
|
---|
3390 | > void deleteMutex(MutexRef mutex);
|
---|
3391 | >
|
---|
3392 | > // Overlay
|
---|
3393 | > virtual void showOverlay();
|
---|
3394 | > virtual void hideOverlay();
|
---|
3395 | > virtual void clearOverlay();
|
---|
3396 | > virtual void grabOverlay(OverlayColor *buf, int pitch);
|
---|
3397 | > virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
|
---|
3398 | > virtual int16 getHeight();
|
---|
3399 | > virtual int16 getWidth();
|
---|
3400 | > virtual int16 getOverlayHeight() { return _overlayHeight; }
|
---|
3401 | > virtual int16 getOverlayWidth() { return _overlayWidth; }
|
---|
3402 | >
|
---|
3403 | > // Methods that convert RGB to/from colors suitable for the overlay.
|
---|
3404 | > virtual OverlayColor RGBToColor(uint8 r, uint8 g, uint8 b);
|
---|
3405 | > virtual void colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b);
|
---|
3406 | >
|
---|
3407 | >
|
---|
3408 | > virtual const GraphicsMode *getSupportedGraphicsModes() const;
|
---|
3409 | > virtual int getDefaultGraphicsMode() const;
|
---|
3410 | > virtual bool setGraphicsMode(int mode);
|
---|
3411 | > virtual int getGraphicsMode() const;
|
---|
3412 | >
|
---|
3413 | > virtual void setWindowCaption(const char *caption);
|
---|
3414 | > virtual bool openCD(int drive);
|
---|
3415 | >
|
---|
3416 | > virtual bool hasFeature(Feature f);
|
---|
3417 | > virtual void setFeatureState(Feature f, bool enable);
|
---|
3418 | > virtual bool getFeatureState(Feature f);
|
---|
3419 | >
|
---|
3420 | > #ifdef USE_OSD
|
---|
3421 | > void displayMessageOnOSD(const char *msg);
|
---|
3422 | > #endif
|
---|
3423 | >
|
---|
3424 | > virtual Common::SaveFileManager *getSavefileManager();
|
---|
3425 | > virtual FilesystemFactory *getFilesystemFactory();
|
---|
3426 | >
|
---|
3427 | > protected:
|
---|
3428 | > bool _inited;
|
---|
3429 | >
|
---|
3430 | > #ifdef USE_OSD
|
---|
3431 | > SDL_Surface *_osdSurface;
|
---|
3432 | > Uint8 _osdAlpha; // Transparency level of the OSD
|
---|
3433 | > uint32 _osdFadeStartTime; // When to start the fade out
|
---|
3434 | > enum {
|
---|
3435 | > kOSDFadeOutDelay = 2 * 1000, // Delay before the OSD is faded out (in milliseconds)
|
---|
3436 | > kOSDFadeOutDuration = 500, // Duration of the OSD fade out (in milliseconds)
|
---|
3437 | > kOSDColorKey = 1,
|
---|
3438 | > kOSDInitialAlpha = 80 // Initial alpha level, in percent
|
---|
3439 | > };
|
---|
3440 | > #endif
|
---|
3441 | >
|
---|
3442 | > // hardware screen
|
---|
3443 | > SDL_Surface *_hwscreen;
|
---|
3444 | >
|
---|
3445 | > // unseen game screen
|
---|
3446 | > SDL_Surface *_screen;
|
---|
3447 | >
|
---|
3448 | > // TODO: We could get rid of the following two vars and just use _screen instead
|
---|
3449 | > int _screenWidth, _screenHeight;
|
---|
3450 | >
|
---|
3451 | > // temporary screen (for scalers)
|
---|
3452 | > SDL_Surface *_tmpscreen;
|
---|
3453 | > SDL_Surface *_tmpscreen2;
|
---|
3454 | >
|
---|
3455 | > // overlay
|
---|
3456 | > SDL_Surface *_overlayscreen;
|
---|
3457 | > int _overlayWidth, _overlayHeight;
|
---|
3458 | > bool _overlayVisible;
|
---|
3459 | >
|
---|
3460 | > // Audio
|
---|
3461 | > int _samplesPerSec;
|
---|
3462 | >
|
---|
3463 | > // CD Audio
|
---|
3464 | > SDL_CD *_cdrom;
|
---|
3465 | > int _cdTrack, _cdNumLoops, _cdStartFrame, _cdDuration;
|
---|
3466 | > uint32 _cdEndTime, _cdStopTime;
|
---|
3467 | >
|
---|
3468 | > enum {
|
---|
3469 | > DF_WANT_RECT_OPTIM = 1 << 0
|
---|
3470 | > };
|
---|
3471 | >
|
---|
3472 | > enum {
|
---|
3473 | > kTransactionNone = 0,
|
---|
3474 | > kTransactionCommit = 1,
|
---|
3475 | > kTransactionActive = 2
|
---|
3476 | > };
|
---|
3477 | >
|
---|
3478 | > struct TransactionDetails {
|
---|
3479 | > int mode;
|
---|
3480 | > bool modeChanged;
|
---|
3481 | > int w;
|
---|
3482 | > int h;
|
---|
3483 | > bool sizeChanged;
|
---|
3484 | > bool fs;
|
---|
3485 | > bool fsChanged;
|
---|
3486 | > bool ar;
|
---|
3487 | > bool arChanged;
|
---|
3488 | > bool needHotswap;
|
---|
3489 | > bool needUpdatescreen;
|
---|
3490 | > bool needUnload;
|
---|
3491 | > bool needToggle;
|
---|
3492 | > bool normal1xScaler;
|
---|
3493 | > };
|
---|
3494 | > TransactionDetails _transactionDetails;
|
---|
3495 | >
|
---|
3496 | > /** Force full redraw on next updateScreen */
|
---|
3497 | > bool _forceFull;
|
---|
3498 | > ScalerProc *_scalerProc;
|
---|
3499 | > int _scalerType;
|
---|
3500 | > int _scaleFactor;
|
---|
3501 | > int _mode;
|
---|
3502 | > int _transactionMode;
|
---|
3503 | > bool _fullscreen;
|
---|
3504 | >
|
---|
3505 | > bool _screenIsLocked;
|
---|
3506 | > Graphics::Surface _framebuffer;
|
---|
3507 | >
|
---|
3508 | > /** Current video mode flags (see DF_* constants) */
|
---|
3509 | > uint32 _modeFlags;
|
---|
3510 | > bool _modeChanged;
|
---|
3511 | > int _screenChangeCount;
|
---|
3512 | >
|
---|
3513 | > /** True if aspect ratio correction is enabled. */
|
---|
3514 | > bool _adjustAspectRatio;
|
---|
3515 | >
|
---|
3516 | > enum {
|
---|
3517 | > NUM_DIRTY_RECT = 100,
|
---|
3518 | > MAX_SCALING = 3
|
---|
3519 | > };
|
---|
3520 | >
|
---|
3521 | > // Dirty rect management
|
---|
3522 | > SDL_Rect _dirtyRectList[NUM_DIRTY_RECT];
|
---|
3523 | > int _numDirtyRects;
|
---|
3524 | > uint32 *_dirtyChecksums;
|
---|
3525 | > bool _cksumValid;
|
---|
3526 | > int _cksumNum;
|
---|
3527 | >
|
---|
3528 | > // Keyboard mouse emulation. Disabled by fingolfin 2004-12-18.
|
---|
3529 | > // I am keeping the rest of the code in for now, since the joystick
|
---|
3530 | > // code (or rather, "hack") uses it, too.
|
---|
3531 | > struct KbdMouse {
|
---|
3532 | > int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count;
|
---|
3533 | > uint32 last_time, delay_time, x_down_time, y_down_time;
|
---|
3534 | > };
|
---|
3535 | >
|
---|
3536 | > struct MousePos {
|
---|
3537 | > // The mouse position, using either virtual (game) or real
|
---|
3538 | > // (overlay) coordinates.
|
---|
3539 | > int16 x, y;
|
---|
3540 | >
|
---|
3541 | > // The size and hotspot of the original cursor image.
|
---|
3542 | > int16 w, h;
|
---|
3543 | > int16 hotX, hotY;
|
---|
3544 | >
|
---|
3545 | > // The size and hotspot of the pre-scaled cursor image, in real
|
---|
3546 | > // coordinates.
|
---|
3547 | > int16 rW, rH;
|
---|
3548 | > int16 rHotX, rHotY;
|
---|
3549 | >
|
---|
3550 | > // The size and hotspot of the pre-scaled cursor image, in game
|
---|
3551 | > // coordinates.
|
---|
3552 | > int16 vW, vH;
|
---|
3553 | > int16 vHotX, vHotY;
|
---|
3554 | >
|
---|
3555 | > MousePos() : x(0), y(0), w(0), h(0), hotX(0), hotY(0),
|
---|
3556 | > rW(0), rH(0), rHotX(0), rHotY(0), vW(0), vH(0),
|
---|
3557 | > vHotX(0), vHotY(0)
|
---|
3558 | > { }
|
---|
3559 | > };
|
---|
3560 | >
|
---|
3561 | > // mouse
|
---|
3562 | > KbdMouse _km;
|
---|
3563 | > bool _mouseVisible;
|
---|
3564 | > bool _mouseDrawn;
|
---|
3565 | > byte *_mouseData;
|
---|
3566 | > SDL_Rect _mouseBackup;
|
---|
3567 | > MousePos _mouseCurState;
|
---|
3568 | > byte _mouseKeyColor;
|
---|
3569 | > int _cursorTargetScale;
|
---|
3570 | > bool _cursorPaletteDisabled;
|
---|
3571 | > SDL_Surface *_mouseOrigSurface;
|
---|
3572 | > SDL_Surface *_mouseSurface;
|
---|
3573 | > enum {
|
---|
3574 | > kMouseColorKey = 1
|
---|
3575 | > };
|
---|
3576 | >
|
---|
3577 | > // joystick
|
---|
3578 | > SDL_Joystick *_joystick;
|
---|
3579 | >
|
---|
3580 | > // Shake mode
|
---|
3581 | > int _currentShakePos;
|
---|
3582 | > int _newShakePos;
|
---|
3583 | >
|
---|
3584 | > // Palette data
|
---|
3585 | > SDL_Color *_currentPalette;
|
---|
3586 | > uint _paletteDirtyStart, _paletteDirtyEnd;
|
---|
3587 | >
|
---|
3588 | > // Cursor palette data
|
---|
3589 | > SDL_Color *_cursorPalette;
|
---|
3590 | >
|
---|
3591 | > /**
|
---|
3592 | > * Mutex which prevents multiple threads from interfering with each other
|
---|
3593 | > * when accessing the screen.
|
---|
3594 | > */
|
---|
3595 | > MutexRef _graphicsMutex;
|
---|
3596 | >
|
---|
3597 | > #ifdef MIXER_DOUBLE_BUFFERING
|
---|
3598 | > SDL_mutex *_soundMutex;
|
---|
3599 | > SDL_cond *_soundCond;
|
---|
3600 | > SDL_Thread *_soundThread;
|
---|
3601 | > bool _soundThreadIsRunning;
|
---|
3602 | > bool _soundThreadShouldQuit;
|
---|
3603 | >
|
---|
3604 | > byte _activeSoundBuf;
|
---|
3605 | > uint _soundBufSize;
|
---|
3606 | > byte *_soundBuffers[2];
|
---|
3607 | >
|
---|
3608 | > void mixerProducerThread();
|
---|
3609 | > static int SDLCALL mixerProducerThreadEntry(void *arg);
|
---|
3610 | > void initThreadedMixer(Audio::MixerImpl *mixer, uint bufSize);
|
---|
3611 | > void deinitThreadedMixer();
|
---|
3612 | > #endif
|
---|
3613 | >
|
---|
3614 | >
|
---|
3615 | > Common::SaveFileManager *_savefile;
|
---|
3616 | > Audio::MixerImpl *_mixer;
|
---|
3617 | >
|
---|
3618 | > SDL_TimerID _timerID;
|
---|
3619 | > Common::TimerManager *_timer;
|
---|
3620 | >
|
---|
3621 | >
|
---|
3622 | > protected:
|
---|
3623 | > void addDirtyRgnAuto(const byte *buf);
|
---|
3624 | > void makeChecksums(const byte *buf);
|
---|
3625 | >
|
---|
3626 | > virtual void addDirtyRect(int x, int y, int w, int h, bool realCoordinates = false); // overloaded by CE backend
|
---|
3627 | >
|
---|
3628 | > virtual void drawMouse(); // overloaded by CE backend
|
---|
3629 | > virtual void undrawMouse(); // overloaded by CE backend (FIXME)
|
---|
3630 | > virtual void blitCursor(); // overloaded by CE backend (FIXME)
|
---|
3631 | >
|
---|
3632 | > /** Set the position of the virtual mouse cursor. */
|
---|
3633 | > void setMousePos(int x, int y);
|
---|
3634 | > virtual void fillMouseEvent(Common::Event &event, int x, int y); // overloaded by CE backend
|
---|
3635 | > void toggleMouseGrab();
|
---|
3636 | >
|
---|
3637 | > virtual void internUpdateScreen(); // overloaded by CE backend
|
---|
3638 | >
|
---|
3639 | > virtual void loadGFXMode(); // overloaded by CE backend
|
---|
3640 | > virtual void unloadGFXMode(); // overloaded by CE backend
|
---|
3641 | > virtual void hotswapGFXMode(); // overloaded by CE backend
|
---|
3642 | >
|
---|
3643 | > void setFullscreenMode(bool enable);
|
---|
3644 | > void setAspectRatioCorrection(bool enable);
|
---|
3645 | >
|
---|
3646 | > virtual bool saveScreenshot(const char *filename); // overloaded by CE backend
|
---|
3647 | >
|
---|
3648 | > int effectiveScreenHeight() const {
|
---|
3649 | > return (_adjustAspectRatio ? real2Aspect(_screenHeight) : _screenHeight)
|
---|
3650 | > * _scaleFactor;
|
---|
3651 | > }
|
---|
3652 | >
|
---|
3653 | > void setupIcon();
|
---|
3654 | > void handleKbdMouse();
|
---|
3655 | >
|
---|
3656 | > virtual bool remapKey(SDL_Event &ev, Common::Event &event);
|
---|
3657 | >
|
---|
3658 | > void handleScalerHotkeys(const SDL_KeyboardEvent &key);
|
---|
3659 | >
|
---|
3660 | > int mySDL_PollEvent(SDL_Event *event);
|
---|
3661 | > void suspendAudio();
|
---|
3662 | > int resumeAudio();
|
---|
3663 | >
|
---|
3664 | > };
|
---|
3665 | >
|
---|
3666 | > extern unsigned int st_pause_ticks, st_pause_count;
|
---|
3667 | >
|
---|
3668 | > unsigned int st_get_ticks(void);
|
---|
3669 | > void st_pause_ticks_init(void);
|
---|
3670 | > void st_pause_ticks_start(void);
|
---|
3671 | > void st_pause_ticks_stop(void);
|
---|
3672 | > bool st_pause_ticks_started(void);
|
---|
3673 | >
|
---|
3674 | > #endif
|
---|
3675 | diff -rN scummvm-0.12.0/common/stream.cpp scummvm-0.12.0-a1200/common/stream.cpp
|
---|
3676 | 64a65,69
|
---|
3677 | > if (offs>_size) {
|
---|
3678 | > offs=0; // lubomyr ogg fix
|
---|
3679 | > printf("lubomyr ogg fix _pos>_size in stream.cpp\n");
|
---|
3680 | > }
|
---|
3681 | >
|
---|
3682 | diff -rN scummvm-0.12.0/configure scummvm-0.12.0-a1200/configure
|
---|
3683 | 585c585
|
---|
3684 | < --backend=BACKEND backend to build (sdl, x11, morphos, dc, gp2x, iphone, null) [sdl]
|
---|
3685 | ---
|
---|
3686 | > --backend=BACKEND backend to build (sdl, x11, morphos, dc, gp2x, iphone, motoezx, null) [sdl]
|
---|
3687 | 812a813,816
|
---|
3688 | > motoezx)
|
---|
3689 | > _host_os=linux
|
---|
3690 | > _host_cpu=arm
|
---|
3691 | > ;;
|
---|
3692 | 1694a1699,1705
|
---|
3693 | > motoezx)
|
---|
3694 | > find_sdlconfig
|
---|
3695 | > INCLUDES="$INCLUDES `$_sdlconfig --prefix="$_sdlpath" --cflags`"
|
---|
3696 | > LIBS="$LIBS `$_sdlconfig --prefix="$_sdlpath" --libs`"
|
---|
3697 | > DEFINES="$DEFINES -DSDL_BACKEND"
|
---|
3698 | > MODULES="$MODULES backends/platform/motoezx"
|
---|
3699 | > ;;
|
---|
3700 | diff -rN scummvm-0.12.0/configure-motoezx.txt scummvm-0.12.0-a1200/configure-motoezx.txt
|
---|
3701 | 0a1
|
---|
3702 | > ./configure --host=arm-linux --backend=motoezx --disable-vorbis --enable-tremor --enable-mad --enable-zlib --enable-flac
|
---|