Mercurial > sdl-ios-xcode
annotate src/video/os2fslib/SDL_os2fslib.c @ 1402:d910939febfa
Use consistent identifiers for the various platforms we support.
Make sure every source file includes SDL_config.h, so the proper system
headers are chosen.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 21 Feb 2006 08:46:50 +0000 |
parents | 19418e4422cb |
children | e3242177fe4a |
rev | line source |
---|---|
1190 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2004 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
1190 | 23 |
24 #include <process.h> | |
25 #include <time.h> | |
26 | |
27 #include "SDL_video.h" | |
28 #include "SDL_mouse.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
29 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
30 #include "../SDL_pixels_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
31 #include "../../events/SDL_events_c.h" |
1190 | 32 |
33 #include "SDL_os2fslib.h" | |
34 | |
35 static ULONG ulFCFToUse = | |
36 FCF_TITLEBAR | | |
37 FCF_SYSMENU | | |
38 FCF_MINBUTTON | | |
39 FCF_MAXBUTTON | | |
40 FCF_NOBYTEALIGN | | |
41 FCF_SIZEBORDER | | |
42 FCF_TASKLIST; | |
43 | |
44 static int bMouseCaptured = 0; | |
45 static int bMouseCapturable = 0; | |
46 static HPOINTER hptrGlobalPointer = NULL; | |
47 static HPOINTER hptrCurrentIcon = NULL; | |
48 static int iWindowSizeX = 320; | |
49 static int iWindowSizeY = 200; | |
50 static int bWindowResized = 0; | |
51 | |
52 #pragma pack(1) | |
53 typedef struct BMPINFO | |
54 { | |
55 BITMAPINFO; | |
56 RGB clr; | |
57 } BMPINFO, *PBMPINFO; | |
58 #pragma pack() | |
59 | |
60 | |
61 // Backdoors: | |
62 DECLSPEC void SDLCALL SDL_OS2FSLIB_SetFCFToUse(ULONG ulFCF) | |
63 { | |
64 ulFCFToUse = ulFCF; | |
65 } | |
66 | |
67 // Configuration defines: | |
68 | |
69 // We have to report empty alpha mask, otherwise SDL will select | |
70 // alpha blitters, and this will have unwanted results, as we don't | |
71 // support alpha channel in FSLib yet. | |
72 #define REPORT_EMPTY_ALPHA_MASK | |
73 | |
74 // Experimental: Move every FSLib_BitBlt() call into window message | |
75 // processing function. | |
76 // This may fix dirt left on desktop. Or not. | |
77 //#define BITBLT_IN_WINMESSAGEPROC | |
78 | |
79 // Experimental-2: Use WinLockWindowUpdate() in around bitblts! | |
80 // This is not enabled, because it seems to cause more problems | |
81 // than good. | |
82 //#define USE_WINLOCKWINDOWUPDATE_AROUND_BITBLTS | |
83 | |
84 // Use the following to show resized image instead of black stuff | |
85 // even if the surface is resizable. | |
86 //#define RESIZE_EVEN_IF_RESIZABLE | |
87 | |
88 /* The translation table from a VK keysym to a SDL keysym */ | |
89 static SDLKey HWScanKeyMap[256]; | |
90 static SDL_keysym *TranslateKey(int vkey, int chcode, int scancode, SDL_keysym *keysym, int iPressed); | |
91 static int iShiftIsPressed; | |
92 | |
93 #ifdef BITBLT_IN_WINMESSAGEPROC | |
94 #define WM_UPDATERECTSREQUEST WM_USER+50 | |
95 #endif | |
96 | |
97 #ifdef USE_WINLOCKWINDOWUPDATE_AROUND_BITBLTS | |
98 #define FSLIB_BITBLT(hwnd, buffer, top, left, width, height) \ | |
99 { \ | |
100 WinLockWindowUpdate(HWND_DESKTOP, HWND_DESKTOP); \ | |
101 FSLib_BitBlt(hwnd, buffer, top, left, width, height); \ | |
102 WinLockWindowUpdate(HWND_DESKTOP, NULL); \ | |
103 } | |
104 #else | |
105 #define FSLIB_BITBLT(hwnd, buffer, top, left, width, height) \ | |
106 FSLib_BitBlt(hwnd, buffer, top, left, width, height); | |
107 #endif | |
108 | |
109 ///////////////////////////////////////////////////////////////////// | |
110 // | |
111 // SetAccessableWindowPos | |
112 // | |
113 // Same as WinSetWindowPos(), but takes care for the window to be | |
114 // always on the screen, the titlebar will be accessable everytime. | |
115 // | |
116 ///////////////////////////////////////////////////////////////////// | |
117 static BOOL SetAccessableWindowPos(HWND hwnd, HWND hwndInsertBehind, | |
118 LONG x, LONG y, | |
119 LONG cx, LONG cy, | |
120 ULONG fl) | |
121 { | |
122 SWP swpDesktop, swp; | |
123 // Get desktop area | |
124 WinQueryWindowPos(HWND_DESKTOP, &swpDesktop); | |
125 | |
126 if ((fl & SWP_MOVE) && (fl & SWP_SIZE)) | |
127 { | |
128 // If both moving and sizing, then change size and pos now!! | |
129 if (x+cx>swpDesktop.cx) | |
130 x = swpDesktop.cx - cx; | |
131 if (x<0) | |
132 x = 0; | |
133 if (y<0) | |
134 y = 0; | |
135 if (y+cy>swpDesktop.cy) | |
136 y = swpDesktop.cy - cy; | |
137 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl); | |
138 } else | |
139 if (fl & SWP_MOVE) | |
140 { | |
141 // Just moving | |
142 WinQueryWindowPos(hwnd, &swp); | |
143 if (x+swp.cx>swpDesktop.cx) | |
144 x = swpDesktop.cx - swp.cx; | |
145 if (x<0) | |
146 x = 0; | |
147 if (y<0) | |
148 y = 0; | |
149 if (y+swp.cy>swpDesktop.cy) | |
150 y = swpDesktop.cy - swp.cy; | |
151 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl); | |
152 } else | |
153 if (fl & SWP_SIZE) | |
154 { | |
155 // Just sizing | |
156 WinQueryWindowPos(hwnd, &swp); | |
157 x = swp.x; | |
158 y = swp.y; | |
159 if (x+cx>swpDesktop.cx) | |
160 x = swpDesktop.cx - cx; | |
161 if (x<0) | |
162 x = 0; | |
163 if (y<0) | |
164 y = 0; | |
165 if (y+cy>swpDesktop.cy) | |
166 y = swpDesktop.cy - cy; | |
167 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl | SWP_MOVE); | |
168 } else | |
169 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl); | |
170 } | |
171 | |
172 ///////////////////////////////////////////////////////////////////// | |
173 // | |
174 // TranslateKey | |
175 // | |
176 // This creates SDL Keycodes from VK_ and hardware scan codes | |
177 // | |
178 ///////////////////////////////////////////////////////////////////// | |
179 static SDL_keysym *TranslateKey(int vkey, int chcode, int scancode, SDL_keysym *keysym, int iPressed) | |
180 { | |
181 keysym->scancode = (unsigned char) scancode; | |
182 keysym->mod = KMOD_NONE; | |
183 keysym->unicode = 0; | |
184 | |
185 if (iPressed && SDL_TranslateUNICODE) | |
186 { | |
187 // TODO: | |
188 // Implement real unicode conversion! | |
189 if (chcode) | |
190 keysym->unicode = chcode; | |
191 else | |
192 keysym->unicode = vkey; | |
193 } | |
194 | |
195 keysym->sym = HWScanKeyMap[scancode]; | |
196 | |
197 // Now stuffs based on state of shift key(s)! | |
198 if (vkey == VK_SHIFT) | |
199 { | |
200 iShiftIsPressed = iPressed; | |
201 } | |
202 | |
203 if ((iShiftIsPressed) && (SDL_TranslateUNICODE)) | |
204 { | |
205 // Change syms, if Unicode stuff is required | |
206 // I think it's silly, but it's SDL... | |
207 switch (keysym->sym) | |
208 { | |
209 case SDLK_BACKQUOTE: | |
210 keysym->sym = '~'; | |
211 break; | |
212 case SDLK_1: | |
213 keysym->sym = SDLK_EXCLAIM; | |
214 break; | |
215 case SDLK_2: | |
216 keysym->sym = SDLK_AT; | |
217 break; | |
218 case SDLK_3: | |
219 keysym->sym = SDLK_HASH; | |
220 break; | |
221 case SDLK_4: | |
222 keysym->sym = SDLK_DOLLAR; | |
223 break; | |
224 case SDLK_5: | |
225 keysym->sym = '%'; | |
226 break; | |
227 case SDLK_6: | |
228 keysym->sym = SDLK_CARET; | |
229 break; | |
230 case SDLK_7: | |
231 keysym->sym = SDLK_AMPERSAND; | |
232 break; | |
233 case SDLK_8: | |
234 keysym->sym = SDLK_ASTERISK; | |
235 break; | |
236 case SDLK_9: | |
237 keysym->sym = SDLK_LEFTPAREN; | |
238 break; | |
239 case SDLK_0: | |
240 keysym->sym = SDLK_RIGHTPAREN; | |
241 break; | |
242 case SDLK_MINUS: | |
243 keysym->sym = SDLK_UNDERSCORE; | |
244 break; | |
245 case SDLK_PLUS: | |
246 keysym->sym = SDLK_EQUALS; | |
247 break; | |
248 | |
249 case SDLK_LEFTBRACKET: | |
250 keysym->sym = '{'; | |
251 break; | |
252 case SDLK_RIGHTBRACKET: | |
253 keysym->sym = '}'; | |
254 break; | |
255 | |
256 case SDLK_SEMICOLON: | |
257 keysym->sym = SDLK_COLON; | |
258 break; | |
259 case SDLK_QUOTE: | |
260 keysym->sym = SDLK_QUOTEDBL; | |
261 break; | |
262 case SDLK_BACKSLASH: | |
263 keysym->sym = '|'; | |
264 break; | |
265 | |
266 case SDLK_COMMA: | |
267 keysym->sym = SDLK_LESS; | |
268 break; | |
269 case SDLK_PERIOD: | |
270 keysym->sym = SDLK_GREATER; | |
271 break; | |
272 case SDLK_SLASH: | |
273 keysym->sym = SDLK_QUESTION; | |
274 break; | |
275 | |
276 default: | |
277 break; | |
278 } | |
279 } | |
280 return keysym; | |
281 } | |
282 | |
283 #define CONVERTMOUSEPOSITION() \ | |
284 /* We have to inverse the mouse position, because every non-os/2 system */ \ | |
285 /* has a coordinate system where the (0;0) is the top-left corner, */ \ | |
286 /* while on os/2 it's the bottom left corner! */ \ | |
287 if (FSLib_QueryFSMode(hwnd)) \ | |
288 { \ | |
289 /* We're in FS mode! */ \ | |
290 /* In FS mode our window is as big as fullscreen mode, but not necessary as */ \ | |
291 /* big as the source buffer (can be bigger) */ \ | |
292 /* So, limit mouse pos to source buffer size! */ \ | |
293 if (ppts->x<0) ppts->x = 0; \ | |
294 if (ppts->y<0) ppts->y = 0; \ | |
295 if (ppts->x>=pVideo->hidden->SrcBufferDesc.uiXResolution) ppts->x = pVideo->hidden->SrcBufferDesc.uiXResolution-1; \ | |
296 if (ppts->y>=pVideo->hidden->SrcBufferDesc.uiYResolution) ppts->y = pVideo->hidden->SrcBufferDesc.uiYResolution-1; \ | |
297 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ \ | |
298 ptl.x = ppts->x; ptl.y = ppts->y; \ | |
299 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); \ | |
300 WinSetPointerPos(HWND_DESKTOP, ptl.x, ptl.y); \ | |
301 /* Then convert OS/2 position to SDL position */ \ | |
302 ppts->y = pVideo->hidden->SrcBufferDesc.uiYResolution - ppts->y - 1; \ | |
303 } else \ | |
304 { \ | |
305 SWP swpClient; \ | |
306 /* We're in windowed mode! */ \ | |
307 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); \ | |
308 /* Convert OS/2 mouse position to SDL position, and also scale it! */ \ | |
309 (ppts->x) = (ppts->x) * pVideo->hidden->SrcBufferDesc.uiXResolution / swpClient.cx; \ | |
310 (ppts->y) = (ppts->y) * pVideo->hidden->SrcBufferDesc.uiYResolution / swpClient.cy; \ | |
311 (ppts->y) = pVideo->hidden->SrcBufferDesc.uiYResolution - (ppts->y) - 1; \ | |
312 } | |
313 | |
314 | |
315 | |
316 ///////////////////////////////////////////////////////////////////// | |
317 // | |
318 // WndProc | |
319 // | |
320 // This is the message processing window procedure for the | |
321 // SDLWindowClass, which is the client window in our application. | |
322 // It handles switching back and away from the app (taking care of | |
323 // going out and back to and from fullscreen mode), sending keystrokes | |
324 // and mouse events to where it has to be sent, etc... | |
325 // | |
326 ///////////////////////////////////////////////////////////////////// | |
327 static MRESULT EXPENTRY WndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | |
328 { | |
329 HPS ps; | |
330 RECTL rcl; | |
331 SDL_VideoDevice *pVideo = NULL; | |
332 | |
333 switch (msg) | |
334 { | |
335 case WM_CHAR: // Keypress notification | |
336 #ifdef DEBUG_BUILD | |
337 // printf("WM_CHAR\n"); fflush(stdout); | |
338 #endif | |
339 pVideo = WinQueryWindowPtr(hwnd, 0); | |
340 if (pVideo) | |
341 { | |
342 /* | |
343 // We skip repeated keys: | |
344 if (CHARMSG(&msg)->cRepeat>1) | |
345 { | |
346 #ifdef DEBUG_BUILD | |
347 // printf("Repeated key (%d), skipping...\n", CHARMSG(&msg)->cRepeat); fflush(stdout); | |
348 #endif | |
349 return (MRESULT) TRUE; | |
350 } | |
351 */ | |
352 | |
353 // If it's not repeated, then let's see if its pressed or released! | |
354 if (SHORT1FROMMP(mp1) & KC_KEYUP) | |
355 { | |
356 // A key has been released | |
357 SDL_keysym keysym; | |
358 | |
359 #ifdef DEBUG_BUILD | |
360 // printf("WM_CHAR, keyup, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code | |
361 #endif | |
362 | |
363 // One problem is with F1, which gets only the keyup message because | |
364 // it is a system key. | |
365 // So, when we get keyup message, we simulate keydown too! | |
366 // UPDATE: | |
367 // This problem should be solved now, that the accelerator keys are | |
368 // disabled for this window! | |
369 /* | |
370 if (SHORT2FROMMP(mp2)==VK_F1) | |
371 { | |
372 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code | |
373 SHORT1FROMMP(mp2), // Character code | |
374 CHAR4FROMMP(mp1), // HW Scan code | |
375 &keysym,0)); | |
376 }*/ | |
377 | |
378 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code | |
379 SHORT1FROMMP(mp2), // Character code | |
380 CHAR4FROMMP(mp1), // HW Scan code | |
381 &keysym,0)); | |
382 | |
383 } else | |
384 { | |
385 // A key has been pressed | |
386 SDL_keysym keysym; | |
387 | |
388 #ifdef DEBUG_BUILD | |
389 // printf("WM_CHAR, keydown, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code | |
390 #endif | |
391 // Check for fastkeys: ALT+HOME to toggle FS mode | |
392 // ALT+END to close app | |
393 if ((SHORT1FROMMP(mp1) & KC_ALT) && | |
394 (SHORT2FROMMP(mp2) == VK_HOME)) | |
395 { | |
396 #ifdef DEBUG_BUILD | |
397 printf(" Pressed ALT+HOME!\n"); fflush(stdout); | |
398 #endif | |
399 // Only switch between fullscreen and back if it's not | |
400 // a resizable mode! | |
401 if ( | |
402 (!pVideo->hidden->pSDLSurface) || | |
403 ((pVideo->hidden->pSDLSurface) | |
404 && ((pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE)==0) | |
405 ) | |
406 ) | |
407 FSLib_ToggleFSMode(hwnd, !FSLib_QueryFSMode(hwnd)); | |
408 #ifdef DEBUG_BUILD | |
409 else | |
410 printf(" Resizable mode, so discarding ALT+HOME!\n"); fflush(stdout); | |
411 #endif | |
412 } else | |
413 if ((SHORT1FROMMP(mp1) & KC_ALT) && | |
414 (SHORT2FROMMP(mp2) == VK_END)) | |
415 { | |
416 #ifdef DEBUG_BUILD | |
417 printf(" Pressed ALT+END!\n"); fflush(stdout); | |
418 #endif | |
419 // Close window, and get out of loop! | |
420 // Also send event to SDL application, but we won't | |
421 // wait for it to be processed! | |
422 SDL_PrivateQuit(); | |
423 WinPostMsg(hwnd, WM_QUIT, 0, 0); | |
424 } else | |
425 { | |
426 | |
427 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code | |
428 SHORT1FROMMP(mp2), // Character code | |
429 CHAR4FROMMP(mp1), // HW Scan code | |
430 &keysym,1)); | |
431 | |
432 } | |
433 } | |
434 } | |
435 return (MRESULT) TRUE; | |
436 | |
437 case WM_TRANSLATEACCEL: | |
438 { | |
439 PQMSG pqmsg; | |
440 pqmsg = (PQMSG) mp1; | |
441 if (mp1) | |
442 { | |
443 if (pqmsg->msg == WM_CHAR) | |
444 { | |
445 // WM_CHAR message! | |
446 // Let's filter the ALT keypress and all other acceleration keys! | |
447 return (MRESULT) FALSE; | |
448 } | |
449 } | |
450 break; // Default processing (pass to parent until frame control) | |
451 } | |
452 | |
453 case WM_PAINT: // Window redraw! | |
454 #ifdef DEBUG_BUILD | |
455 printf("WM_PAINT (0x%x)\n", hwnd); fflush(stdout); | |
456 #endif | |
457 ps = WinBeginPaint(hwnd,0,&rcl); | |
458 pVideo = FSLib_GetUserParm(hwnd); | |
459 if (pVideo) | |
460 { | |
461 if (!pVideo->hidden->pSDLSurface) | |
462 { | |
463 RECTL rclRect; | |
464 // So, don't blit now! | |
465 #ifdef DEBUG_BUILD | |
466 printf("WM_PAINT : Skipping blit while resizing (Pre!)!\n"); fflush(stdout); | |
467 #endif | |
468 WinQueryWindowRect(hwnd, &rclRect); | |
469 // Fill with black | |
470 WinFillRect(ps, &rclRect, CLR_BLACK); | |
471 } else | |
472 { | |
473 if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, 1000)==NO_ERROR) | |
474 { | |
475 int iTop, iLeft, iWidth, iHeight; | |
476 int iXScaleError, iYScaleError; | |
477 int iXScaleError2, iYScaleError2; | |
478 SWP swp; | |
479 | |
480 // Re-blit the modified area! | |
481 // For this, we have to calculate the points, scaled! | |
482 WinQueryWindowPos(hwnd, &swp); | |
483 #ifdef DEBUG_BUILD | |
484 printf("WM_PAINT : WinSize: %d %d, BufSize: %d %d\n", | |
485 swp.cx, | |
486 swp.cy, | |
487 pVideo->hidden->SrcBufferDesc.uiXResolution, | |
488 pVideo->hidden->SrcBufferDesc.uiYResolution | |
489 ); | |
490 fflush(stdout); | |
491 #endif | |
492 | |
493 #ifndef RESIZE_EVEN_IF_RESIZABLE | |
494 // But only blit if the window is not resizable, or if | |
495 // the window is resizable and the source buffer size is the | |
496 // same as the destination buffer size! | |
497 if ((!pVideo->hidden->pSDLSurface) || | |
498 ((pVideo->hidden->pSDLSurface) && | |
499 (pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE) && | |
500 ((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution) || | |
501 (swp.cy != pVideo->hidden->SrcBufferDesc.uiYResolution) | |
502 ) && | |
503 (!FSLib_QueryFSMode(hwnd)) | |
504 ) | |
505 ) | |
506 { | |
507 RECTL rclRect; | |
508 // Resizable surface and in resizing! | |
509 // So, don't blit now! | |
510 #ifdef DEBUG_BUILD | |
511 printf("WM_PAINT : Skipping blit while resizing!\n"); fflush(stdout); | |
512 #endif | |
513 WinQueryWindowRect(hwnd, &rclRect); | |
514 // Fill with black | |
515 WinFillRect(ps, &rclRect, CLR_BLACK); | |
516 } else | |
517 #endif | |
518 { | |
519 | |
520 iXScaleError = (pVideo->hidden->SrcBufferDesc.uiXResolution-1) / swp.cx; | |
521 iYScaleError = (pVideo->hidden->SrcBufferDesc.uiYResolution-1) / swp.cy; | |
522 if (iXScaleError<0) iXScaleError = 0; | |
523 if (iYScaleError<0) iYScaleError = 0; | |
524 iXScaleError2 = (swp.cx-1)/(pVideo->hidden->SrcBufferDesc.uiXResolution); | |
525 iYScaleError2 = (swp.cy-1)/(pVideo->hidden->SrcBufferDesc.uiYResolution); | |
526 if (iXScaleError2<0) iXScaleError2 = 0; | |
527 if (iYScaleError2<0) iYScaleError2 = 0; | |
528 | |
529 iTop = (swp.cy - rcl.yTop) * pVideo->hidden->SrcBufferDesc.uiYResolution / swp.cy - iYScaleError; | |
530 iLeft = rcl.xLeft * pVideo->hidden->SrcBufferDesc.uiXResolution / swp.cx - iXScaleError; | |
531 iWidth = ((rcl.xRight-rcl.xLeft) * pVideo->hidden->SrcBufferDesc.uiXResolution + swp.cx-1) | |
532 / swp.cx + 2*iXScaleError; | |
533 iHeight = ((rcl.yTop-rcl.yBottom) * pVideo->hidden->SrcBufferDesc.uiYResolution + swp.cy-1) | |
534 / swp.cy + 2*iYScaleError; | |
535 | |
536 iWidth+=iXScaleError2; | |
537 iHeight+=iYScaleError2; | |
538 | |
539 if (iTop<0) iTop = 0; | |
540 if (iLeft<0) iLeft = 0; | |
541 if (iTop+iHeight>pVideo->hidden->SrcBufferDesc.uiYResolution) iHeight = pVideo->hidden->SrcBufferDesc.uiYResolution-iTop; | |
542 if (iLeft+iWidth>pVideo->hidden->SrcBufferDesc.uiXResolution) iWidth = pVideo->hidden->SrcBufferDesc.uiXResolution-iLeft; | |
543 | |
544 #ifdef DEBUG_BUILD | |
545 printf("WM_PAINT : BitBlt: %d %d -> %d %d (Buf %d x %d)\n", | |
546 iTop, iLeft, iWidth, iHeight, | |
547 pVideo->hidden->SrcBufferDesc.uiXResolution, | |
548 pVideo->hidden->SrcBufferDesc.uiYResolution | |
549 ); | |
550 fflush(stdout); | |
551 #endif | |
552 | |
553 FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer, iTop, iLeft, iWidth, iHeight); | |
554 } | |
555 | |
556 DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer); | |
557 } | |
558 } | |
559 } | |
560 #ifdef DEBUG_BUILD | |
561 else | |
562 { | |
563 printf("WM_PAINT : No pVideo!\n"); fflush(stdout); | |
564 } | |
565 #endif | |
566 WinEndPaint(ps); | |
567 #ifdef DEBUG_BUILD | |
568 printf("WM_PAINT : Done.\n"); | |
569 fflush(stdout); | |
570 #endif | |
571 return 0; | |
572 | |
573 case WM_SIZE: | |
574 { | |
575 #ifdef DEBUG_BUILD | |
576 printf("WM_SIZE : (%d %d)\n", | |
577 SHORT1FROMMP(mp2), SHORT2FROMMP(mp2)); fflush(stdout); | |
578 #endif | |
579 iWindowSizeX = SHORT1FROMMP(mp2); | |
580 iWindowSizeY = SHORT2FROMMP(mp2); | |
581 bWindowResized = 1; | |
582 | |
583 // Make sure the window will be redrawn | |
584 WinInvalidateRegion(hwnd, NULL, TRUE); | |
585 } | |
586 break; | |
587 | |
588 case WM_FSLIBNOTIFICATION: | |
589 #ifdef DEBUG_BUILD | |
590 printf("WM_FSLIBNOTIFICATION\n"); fflush(stdout); | |
591 #endif | |
592 if ((int)mp1 == FSLN_TOGGLEFSMODE) | |
593 { | |
594 // FS mode changed, reblit image! | |
595 pVideo = FSLib_GetUserParm(hwnd); | |
596 if (pVideo) | |
597 { | |
598 if (!pVideo->hidden->pSDLSurface) | |
599 { | |
600 // Resizable surface and in resizing! | |
601 // So, don't blit now! | |
602 #ifdef DEBUG_BUILD | |
603 printf("WM_FSLIBNOTIFICATION : Can not blit if there is no surface, doing nothing.\n"); fflush(stdout); | |
604 #endif | |
605 } else | |
606 { | |
607 if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, 1000)==NO_ERROR) | |
608 { | |
609 if (pVideo->hidden->pSDLSurface) | |
610 { | |
611 #ifndef RESIZE_EVEN_IF_RESIZABLE | |
612 SWP swp; | |
613 | |
614 // But only blit if the window is not resizable, or if | |
615 // the window is resizable and the source buffer size is the | |
616 // same as the destination buffer size! | |
617 WinQueryWindowPos(hwnd, &swp); | |
618 if ((!pVideo->hidden->pSDLSurface) || | |
619 ( | |
620 (pVideo->hidden->pSDLSurface) && | |
621 (pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE) && | |
622 ((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution) || | |
623 (swp.cy != pVideo->hidden->SrcBufferDesc.uiYResolution) | |
624 ) && | |
625 (!FSLib_QueryFSMode(hwnd)) | |
626 ) | |
627 ) | |
628 { | |
629 // Resizable surface and in resizing! | |
630 // So, don't blit now! | |
631 #ifdef DEBUG_BUILD | |
632 printf("WM_FSLIBNOTIFICATION : Cannot blit while resizing, doing nothing.\n"); fflush(stdout); | |
633 #endif | |
634 } else | |
635 #endif | |
636 { | |
637 #ifdef DEBUG_BUILD | |
638 printf("WM_FSLIBNOTIFICATION : Blitting!\n"); fflush(stdout); | |
639 #endif | |
640 FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer, | |
641 0, 0, | |
642 pVideo->hidden->SrcBufferDesc.uiXResolution, | |
643 pVideo->hidden->SrcBufferDesc.uiYResolution); | |
644 } | |
645 } | |
646 #ifdef DEBUG_BUILD | |
647 else | |
648 printf("WM_FSLIBNOTIFICATION : No public surface!\n"); fflush(stdout); | |
649 #endif | |
650 | |
651 DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer); | |
652 } | |
653 } | |
654 } | |
655 } | |
656 return (MPARAM) 1; | |
657 | |
658 case WM_ACTIVATE: | |
659 #ifdef DEBUG_BUILD | |
660 printf("WM_ACTIVATE\n"); fflush(stdout); | |
661 #endif | |
662 | |
663 pVideo = FSLib_GetUserParm(hwnd); | |
664 if (pVideo) | |
665 { | |
666 pVideo->hidden->fInFocus = (int) mp1; | |
667 if (pVideo->hidden->fInFocus) | |
668 { | |
669 // Went into focus | |
670 if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured)) | |
671 WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); | |
672 else | |
673 WinSetPointer(HWND_DESKTOP, NULL); | |
674 | |
675 if (bMouseCapturable) | |
676 { | |
677 // Re-capture the mouse, if we captured it before! | |
678 WinSetCapture(HWND_DESKTOP, hwnd); | |
679 bMouseCaptured = 1; | |
680 { | |
681 SWP swpClient; | |
682 POINTL ptl; | |
683 // Center the mouse to the middle of the window! | |
684 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); | |
685 ptl.x = 0; ptl.y = 0; | |
686 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); | |
687 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ | |
688 WinSetPointerPos(HWND_DESKTOP, | |
689 ptl.x + swpClient.cx/2, | |
690 ptl.y + swpClient.cy/2); | |
691 } | |
692 } | |
693 } else | |
694 { | |
695 // Went out of focus | |
696 WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); | |
697 | |
698 if (bMouseCaptured) | |
699 { | |
700 // Release the mouse | |
701 WinSetCapture(HWND_DESKTOP, hwnd); | |
702 bMouseCaptured = 0; | |
703 } | |
704 } | |
705 } | |
706 #ifdef DEBUG_BUILD | |
707 printf("WM_ACTIVATE done\n"); fflush(stdout); | |
708 #endif | |
709 | |
710 break; | |
711 | |
712 case WM_BUTTON1DOWN: | |
713 #ifdef DEBUG_BUILD | |
714 printf("WM_BUTTON1DOWN\n"); fflush(stdout); | |
715 #endif | |
716 | |
717 pVideo = FSLib_GetUserParm(hwnd); | |
718 if (pVideo) | |
719 { | |
720 SDL_PrivateMouseButton(SDL_PRESSED, | |
721 SDL_BUTTON_LEFT, | |
722 0, 0); // Don't report mouse movement! | |
723 | |
724 if (bMouseCapturable) | |
725 { | |
726 // We should capture the mouse! | |
727 if (!bMouseCaptured) | |
728 { | |
729 WinSetCapture(HWND_DESKTOP, hwnd); | |
730 WinSetPointer(HWND_DESKTOP, NULL); | |
731 bMouseCaptured = 1; | |
732 { | |
733 SWP swpClient; | |
734 POINTL ptl; | |
735 // Center the mouse to the middle of the window! | |
736 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); | |
737 ptl.x = 0; ptl.y = 0; | |
738 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); | |
739 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ | |
740 WinSetPointerPos(HWND_DESKTOP, | |
741 ptl.x + swpClient.cx/2, | |
742 ptl.y + swpClient.cy/2); | |
743 } | |
744 } | |
745 } | |
746 } | |
747 break; | |
748 case WM_BUTTON1UP: | |
749 #ifdef DEBUG_BUILD | |
750 printf("WM_BUTTON1UP\n"); fflush(stdout); | |
751 #endif | |
752 SDL_PrivateMouseButton(SDL_RELEASED, | |
753 SDL_BUTTON_LEFT, | |
754 0, 0); // Don't report mouse movement! | |
755 break; | |
756 case WM_BUTTON2DOWN: | |
757 #ifdef DEBUG_BUILD | |
758 printf("WM_BUTTON2DOWN\n"); fflush(stdout); | |
759 #endif | |
760 | |
761 pVideo = FSLib_GetUserParm(hwnd); | |
762 if (pVideo) | |
763 { | |
764 SDL_PrivateMouseButton(SDL_PRESSED, | |
765 SDL_BUTTON_RIGHT, | |
766 0, 0); // Don't report mouse movement! | |
767 | |
768 if (bMouseCapturable) | |
769 { | |
770 // We should capture the mouse! | |
771 if (!bMouseCaptured) | |
772 { | |
773 WinSetCapture(HWND_DESKTOP, hwnd); | |
774 WinSetPointer(HWND_DESKTOP, NULL); | |
775 bMouseCaptured = 1; | |
776 { | |
777 SWP swpClient; | |
778 POINTL ptl; | |
779 // Center the mouse to the middle of the window! | |
780 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); | |
781 ptl.x = 0; ptl.y = 0; | |
782 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); | |
783 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ | |
784 WinSetPointerPos(HWND_DESKTOP, | |
785 ptl.x + swpClient.cx/2, | |
786 ptl.y + swpClient.cy/2); | |
787 } | |
788 } | |
789 } | |
790 | |
791 } | |
792 break; | |
793 case WM_BUTTON2UP: | |
794 #ifdef DEBUG_BUILD | |
795 printf("WM_BUTTON2UP\n"); fflush(stdout); | |
796 #endif | |
797 SDL_PrivateMouseButton(SDL_RELEASED, | |
798 SDL_BUTTON_RIGHT, | |
799 0, 0); // Don't report mouse movement! | |
800 break; | |
801 case WM_BUTTON3DOWN: | |
802 #ifdef DEBUG_BUILD | |
803 printf("WM_BUTTON3DOWN\n"); fflush(stdout); | |
804 #endif | |
805 | |
806 pVideo = FSLib_GetUserParm(hwnd); | |
807 if (pVideo) | |
808 { | |
809 SDL_PrivateMouseButton(SDL_PRESSED, | |
810 SDL_BUTTON_MIDDLE, | |
811 0, 0); // Don't report mouse movement! | |
812 | |
813 if (bMouseCapturable) | |
814 { | |
815 // We should capture the mouse! | |
816 if (!bMouseCaptured) | |
817 { | |
818 WinSetCapture(HWND_DESKTOP, hwnd); | |
819 WinSetPointer(HWND_DESKTOP, NULL); | |
820 bMouseCaptured = 1; | |
821 { | |
822 SWP swpClient; | |
823 POINTL ptl; | |
824 // Center the mouse to the middle of the window! | |
825 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); | |
826 ptl.x = 0; ptl.y = 0; | |
827 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); | |
828 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ | |
829 WinSetPointerPos(HWND_DESKTOP, | |
830 ptl.x + swpClient.cx/2, | |
831 ptl.y + swpClient.cy/2); | |
832 } | |
833 } | |
834 } | |
835 } | |
836 break; | |
837 case WM_BUTTON3UP: | |
838 #ifdef DEBUG_BUILD | |
839 printf("WM_BUTTON3UP\n"); fflush(stdout); | |
840 #endif | |
841 SDL_PrivateMouseButton(SDL_RELEASED, | |
842 SDL_BUTTON_MIDDLE, | |
843 0, 0); // Don't report mouse movement! | |
844 break; | |
845 case WM_MOUSEMOVE: | |
846 #ifdef DEBUG_BUILD | |
847 // printf("WM_MOUSEMOVE\n"); fflush(stdout); | |
848 #endif | |
849 | |
850 pVideo = FSLib_GetUserParm(hwnd); | |
851 if (pVideo) | |
852 { | |
853 if (pVideo->hidden->iSkipWMMOUSEMOVE) | |
854 { | |
855 pVideo->hidden->iSkipWMMOUSEMOVE--; | |
856 } else | |
857 { | |
858 POINTS *ppts = (POINTS *) (&mp1); | |
859 POINTL ptl; | |
860 | |
861 CONVERTMOUSEPOSITION(); | |
862 | |
863 if (bMouseCaptured) | |
864 { | |
865 SWP swpClient; | |
866 // Send relative mouse position, and re-center the mouse | |
867 // Reposition the mouse to the center of the screen/window | |
868 SDL_PrivateMouseMotion(0, // Buttons not changed | |
869 1, // Relative position | |
870 ppts->x - (pVideo->hidden->SrcBufferDesc.uiXResolution/2), | |
871 ppts->y+1 - (pVideo->hidden->SrcBufferDesc.uiYResolution/2)); | |
872 | |
873 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); | |
874 ptl.x = 0; ptl.y = 0; | |
875 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); | |
876 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ | |
877 // Center the mouse to the middle of the window! | |
878 WinSetPointerPos(HWND_DESKTOP, | |
879 ptl.x + swpClient.cx/2, | |
880 ptl.y + swpClient.cy/2); | |
881 } else | |
882 { | |
883 // Send absolute mouse position | |
884 SDL_PrivateMouseMotion(0, // Buttons not changed | |
885 0, // Absolute position | |
886 ppts->x, | |
887 ppts->y); | |
888 } | |
889 } | |
890 if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured)) | |
891 { | |
892 #ifdef DEBUG_BUILD | |
893 // printf("WM_MOUSEMOVE : ptr = %p\n", hptrGlobalPointer); fflush(stdout); | |
894 #endif | |
895 | |
896 if (hptrGlobalPointer) | |
897 WinSetPointer(HWND_DESKTOP, hptrGlobalPointer); | |
898 else | |
899 WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); | |
900 } | |
901 else | |
902 { | |
903 WinSetPointer(HWND_DESKTOP, NULL); | |
904 } | |
905 } | |
906 #ifdef DEBUG_BUILD | |
907 // printf("WM_MOUSEMOVE done\n"); fflush(stdout); | |
908 #endif | |
909 | |
910 return (MRESULT) FALSE; | |
911 case WM_CLOSE: // Window close | |
912 #ifdef DEBUG_BUILD | |
913 printf("WM_CLOSE\n"); fflush(stdout); | |
914 #endif | |
915 | |
916 pVideo = FSLib_GetUserParm(hwnd); | |
917 if (pVideo) | |
918 { | |
919 // Send Quit message to the SDL application! | |
920 SDL_PrivateQuit(); | |
921 return 0; | |
922 } | |
923 break; | |
924 | |
925 #ifdef BITBLT_IN_WINMESSAGEPROC | |
926 case WM_UPDATERECTSREQUEST: | |
927 pVideo = FSLib_GetUserParm(hwnd); | |
928 if ((pVideo) && (pVideo->hidden->pSDLSurface)) | |
929 { | |
930 if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT)==NO_ERROR) | |
931 { | |
932 int numrects; | |
933 SDL_Rect *rects; | |
934 int i; | |
935 SWP swp; | |
936 | |
937 numrects = (int) mp1; | |
938 rects = (SDL_Rect *) mp2; | |
939 | |
940 WinQueryWindowPos(hwnd, &swp); | |
941 #ifndef RESIZE_EVEN_IF_RESIZABLE | |
942 if ((!pVideo->hidden->pSDLSurface) || | |
943 ( | |
944 (pVideo->hidden->pSDLSurface) && | |
945 (pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE) && | |
946 ((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution) || | |
947 (swp.cy != pVideo->hidden->SrcBufferDesc.uiYResolution) | |
948 ) && | |
949 (!FSLib_QueryFSMode(hwnd)) | |
950 ) | |
951 ) | |
952 { | |
953 // Resizable surface and in resizing! | |
954 // So, don't blit now! | |
955 #ifdef DEBUG_BUILD | |
956 printf("[WM_UPDATERECTSREQUEST] : Skipping blit while resizing!\n"); fflush(stdout); | |
957 #endif | |
958 } else | |
959 #endif | |
960 { | |
961 #ifdef DEBUG_BUILD | |
962 printf("[WM_UPDATERECTSREQUEST] : Blitting!\n"); fflush(stdout); | |
963 #endif | |
964 | |
965 // Blit the changed areas | |
966 for (i=0; i<numrects; i++) | |
967 FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer, | |
968 rects[i].y, rects[i].x, rects[i].w, rects[i].h); | |
969 } | |
970 DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer); | |
971 } | |
972 } | |
973 return 0; | |
974 #endif | |
975 | |
976 default: | |
977 #ifdef DEBUG_BUILD | |
978 printf("Unhandled: %x\n", msg); fflush(stdout); | |
979 #endif | |
980 | |
981 break; | |
982 } | |
983 // Run the default window procedure for unhandled stuffs | |
984 return WinDefWindowProc(hwnd, msg, mp1, mp2); | |
985 } | |
986 | |
987 ///////////////////////////////////////////////////////////////////// | |
988 // | |
989 // PMThreadFunc | |
990 // | |
991 // This function implements the PM-Thread, which initializes the | |
992 // application window itself, the DIVE, and start message processing. | |
993 // | |
994 ///////////////////////////////////////////////////////////////////// | |
995 int iNumOfPMThreadInstances = 0; // Global! | |
996 static void PMThreadFunc(void *pParm) | |
997 { | |
998 SDL_VideoDevice *pVideo = pParm; | |
999 HAB hab; | |
1000 HMQ hmq; | |
1001 QMSG msg; | |
1002 ULONG fcf; | |
1003 | |
1004 #ifdef DEBUG_BUILD | |
1005 printf("[PMThreadFunc] : Starting\n"); fflush(stdout); | |
1006 #endif | |
1007 | |
1008 iNumOfPMThreadInstances++; | |
1009 | |
1010 // Initialize PM, create a message queue. | |
1011 | |
1012 hab=WinInitialize(0); | |
1013 hmq=WinCreateMsgQueue(hab,0); | |
1014 if (hmq==0) | |
1015 { | |
1016 #ifdef DEBUG_BUILD | |
1017 printf("[PMThreadFunc] : Could not create message queue!\n"); | |
1018 printf(" It might be that the application using SDL is not a PM app!\n"); | |
1019 fflush(stdout); | |
1020 #endif | |
1021 pVideo->hidden->iPMThreadStatus = 2; | |
1022 } else | |
1023 { | |
1024 int rc; | |
1025 RECTL rectl; | |
1026 | |
1027 fcf = ulFCFToUse; // Get from global setting | |
1028 | |
1029 #ifdef DEBUG_BUILD | |
1030 printf("[PMThreadFunc] : FSLib_CreateWindow()!\n"); | |
1031 fflush(stdout); | |
1032 #endif | |
1033 | |
1034 rc = FSLib_CreateWindow(HWND_DESKTOP, 0, &fcf, | |
1035 "SDL Application", | |
1036 NULLHANDLE, 0, | |
1037 &(pVideo->hidden->SrcBufferDesc), | |
1038 WndProc, | |
1039 &(pVideo->hidden->hwndClient), | |
1040 &(pVideo->hidden->hwndFrame)); | |
1041 | |
1042 #ifdef DEBUG_BUILD | |
1043 printf("[PMThreadFunc] : FSLib_CreateWindow() rc = %d\n", rc); | |
1044 fflush(stdout); | |
1045 #endif | |
1046 | |
1047 if (!rc) | |
1048 { | |
1049 #ifdef DEBUG_BUILD | |
1050 printf("[PMThreadFunc] : Could not create FSLib window!\n"); | |
1051 fflush(stdout); | |
1052 #endif | |
1053 pVideo->hidden->iPMThreadStatus = 3; | |
1054 } else | |
1055 { | |
1056 #ifdef DEBUG_BUILD | |
1057 printf("[PMThreadFunc] : FSLib_AddUserParm()!\n"); | |
1058 fflush(stdout); | |
1059 #endif | |
1060 | |
1061 // Store pVideo pointer in window data for client window, so | |
1062 // it will know the instance to which it belongs to. | |
1063 FSLib_AddUserParm(pVideo->hidden->hwndClient, pVideo); | |
1064 | |
1065 // Now set default image width height and fourcc! | |
1066 #ifdef DEBUG_BUILD | |
1067 printf("[PMThreadFunc] : SetWindowPos()!\n"); | |
1068 fflush(stdout); | |
1069 #endif | |
1070 | |
1071 // Set the position and size of the main window, | |
1072 // and make it visible! | |
1073 // Calculate frame window size from client window size | |
1074 rectl.xLeft = 0; | |
1075 rectl.yBottom = 0; | |
1076 rectl.xRight = pVideo->hidden->SrcBufferDesc.uiXResolution; // Noninclusive | |
1077 rectl.yTop = pVideo->hidden->SrcBufferDesc.uiYResolution; // Noninclusive | |
1078 WinCalcFrameRect(pVideo->hidden->hwndFrame, &rectl, FALSE); | |
1079 | |
1080 SetAccessableWindowPos(pVideo->hidden->hwndFrame, | |
1081 HWND_TOP, | |
1082 (WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN) - (rectl.xRight-rectl.xLeft)) / 2, | |
1083 (WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN) - (rectl.yTop-rectl.yBottom)) / 2, | |
1084 (rectl.xRight-rectl.xLeft), | |
1085 (rectl.yTop-rectl.yBottom), | |
1086 SWP_SIZE | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE); | |
1087 | |
1088 #ifdef DEBUG_BUILD | |
1089 printf("[PMThreadFunc] : Entering message loop\n"); fflush(stdout); | |
1090 #endif | |
1091 pVideo->hidden->iPMThreadStatus = 1; | |
1092 | |
1093 while (WinGetMsg(hab, (PQMSG)&msg, 0, 0, 0)) | |
1094 WinDispatchMsg(hab, (PQMSG) &msg); | |
1095 | |
1096 #ifdef DEBUG_BUILD | |
1097 printf("[PMThreadFunc] : Leaving message loop\n"); fflush(stdout); | |
1098 #endif | |
1099 // We should release the captured the mouse! | |
1100 if (bMouseCaptured) | |
1101 { | |
1102 WinSetCapture(HWND_DESKTOP, NULLHANDLE); | |
1103 bMouseCaptured = 0; | |
1104 } | |
1105 // Destroy our window | |
1106 WinDestroyWindow(pVideo->hidden->hwndFrame); pVideo->hidden->hwndFrame=NULL; | |
1107 // Show pointer to make sure it will not be left hidden. | |
1108 WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); | |
1109 WinShowPointer(HWND_DESKTOP, TRUE); | |
1110 } | |
1111 // Uninitialize PM | |
1112 WinDestroyMsgQueue(hmq); | |
1113 // All done! | |
1114 pVideo->hidden->iPMThreadStatus = 0; | |
1115 } | |
1116 WinTerminate(hab); | |
1117 /* Commented out, should not be needed anymore, because we send it | |
1118 from WM_CLOSE. | |
1119 // Notify SDL that it should really die now... | |
1120 SDL_PrivateQuit(); SDL_PrivateQuit(); SDL_PrivateQuit(); //... :)) | |
1121 */ | |
1122 #ifdef DEBUG_BUILD | |
1123 printf("[PMThreadFunc] : End, status is %d!\n", pVideo->hidden->iPMThreadStatus); fflush(stdout); | |
1124 #endif | |
1125 | |
1126 iNumOfPMThreadInstances--; | |
1127 | |
1128 // HACK to prevent zombie and hanging SDL applications, which does not take | |
1129 // care of closing the window for some reason: | |
1130 // There are some apps which do not process messages, so do a lot of things | |
1131 // without noticing that the application should close. To close these, | |
1132 // I've thought about the following: | |
1133 // If the window is closed (the execution came here), I wait a bit to | |
1134 // give time to the app to finish its execution. If it does not, I kill it | |
1135 // using DosExit(). Brute force, but should work. | |
1136 if (pVideo->hidden->iPMThreadStatus==0) | |
1137 { | |
1138 DosSleep(5000); // Wait 5 secs | |
1139 // If a new PM thread has been spawned (reinitializing video mode), then all right. | |
1140 // Otherwise, we have a problem, the app doesn't want to stop. Kill! | |
1141 if (iNumOfPMThreadInstances==0) | |
1142 { | |
1143 #ifdef DEBUG_BUILD | |
1144 printf("[PMThreadFunc] : It seems that the application haven't terminated itself\n"); fflush(stdout); | |
1145 printf("[PMThreadFunc] : in the last 5 seconds, so we go berserk.\n"); fflush(stdout); | |
1146 printf("[PMThreadFunc] : Brute force mode. :) Killing process! Dieeeee...\n"); fflush(stdout); | |
1147 #endif | |
1148 DosExit(EXIT_PROCESS, -1); | |
1149 } | |
1150 } | |
1151 _endthread(); | |
1152 } | |
1153 | |
1154 struct WMcursor | |
1155 { | |
1156 HBITMAP hbm; | |
1157 HPOINTER hptr; | |
1158 char *pchData; | |
1159 }; | |
1160 | |
1161 /* Free a window manager cursor */ | |
1162 void os2fslib_FreeWMCursor(_THIS, WMcursor *cursor) | |
1163 { | |
1164 if (cursor) | |
1165 { | |
1166 GpiDeleteBitmap(cursor->hbm); | |
1167 WinDestroyPointer(cursor->hptr); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1168 SDL_free(cursor->pchData); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1169 SDL_free(cursor); |
1190 | 1170 } |
1171 } | |
1172 | |
1173 /* Local functions to convert the SDL cursor mask into OS/2 format */ | |
1174 static void memnot(Uint8 *dst, Uint8 *src, int len) | |
1175 { | |
1176 while ( len-- > 0 ) | |
1177 *dst++ = ~*src++; | |
1178 } | |
1179 static void memxor(Uint8 *dst, Uint8 *src1, Uint8 *src2, int len) | |
1180 { | |
1181 while ( len-- > 0 ) | |
1182 *dst++ = (*src1++)^(*src2++); | |
1183 } | |
1184 | |
1185 /* Create a black/white window manager cursor */ | |
1186 WMcursor *os2fslib_CreateWMCursor_Win(_THIS, Uint8 *data, Uint8 *mask, | |
1187 int w, int h, int hot_x, int hot_y) | |
1188 { | |
1189 HPOINTER hptr; | |
1190 HBITMAP hbm; | |
1191 BITMAPINFOHEADER bmih; | |
1192 BMPINFO bmi; | |
1193 HPS hps; | |
1194 char *pchTemp; | |
1195 char *xptr, *aptr; | |
1196 int maxx, maxy; | |
1197 int i, run, pad; | |
1198 WMcursor *pResult; | |
1199 | |
1200 maxx = WinQuerySysValue(HWND_DESKTOP, SV_CXPOINTER); | |
1201 maxy = WinQuerySysValue(HWND_DESKTOP, SV_CYPOINTER); | |
1202 | |
1203 // Check for max size! | |
1204 if ((w>maxx) || (h>maxy)) | |
1205 return (WMcursor *) NULL; | |
1206 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1207 pResult = (WMcursor *) SDL_malloc(sizeof(WMcursor)); |
1190 | 1208 if (!pResult) return (WMcursor *) NULL; |
1209 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1210 pchTemp = (char *) SDL_malloc((maxx + 7)/8 * maxy*2); |
1190 | 1211 if (!pchTemp) |
1212 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1213 SDL_free(pResult); |
1190 | 1214 return (WMcursor *) NULL; |
1215 } | |
1216 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1217 SDL_memset(pchTemp, 0, (maxx + 7)/8 * maxy*2); |
1190 | 1218 |
1219 hps = WinGetPS(_this->hidden->hwndClient); | |
1220 | |
1221 bmi.cbFix = sizeof(BITMAPINFOHEADER); | |
1222 bmi.cx = maxx; | |
1223 bmi.cy = 2*maxy; | |
1224 bmi.cPlanes = 1; | |
1225 bmi.cBitCount = 1; | |
1226 bmi.argbColor[0].bBlue = 0x00; | |
1227 bmi.argbColor[0].bGreen = 0x00; | |
1228 bmi.argbColor[0].bRed = 0x00; | |
1229 bmi.argbColor[1].bBlue = 0x00; | |
1230 bmi.argbColor[1].bGreen = 0x00; | |
1231 bmi.argbColor[1].bRed = 0xff; | |
1232 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1233 SDL_memset(&bmih, 0, sizeof(BITMAPINFOHEADER)); |
1190 | 1234 bmih.cbFix = sizeof(BITMAPINFOHEADER); |
1235 bmih.cx = maxx; | |
1236 bmih.cy = 2*maxy; | |
1237 bmih.cPlanes = 1; | |
1238 bmih.cBitCount = 1; | |
1239 | |
1240 run = (w+7)/8; | |
1241 pad = (maxx+7)/8 - run; | |
1242 | |
1243 for (i=0; i<h; i++) | |
1244 { | |
1245 xptr = pchTemp + (maxx+7)/8 * (maxy-1-i); | |
1246 aptr = pchTemp + (maxx+7)/8 * (maxy+maxy-1-i); | |
1247 memxor(xptr, data, mask, run); | |
1248 xptr += run; | |
1249 data += run; | |
1250 memnot(aptr, mask, run); | |
1251 mask += run; | |
1252 aptr += run; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1253 SDL_memset(xptr, 0, pad); |
1190 | 1254 xptr += pad; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1255 SDL_memset(aptr, ~0, pad); |
1190 | 1256 aptr += pad; |
1257 } | |
1258 pad += run; | |
1259 for (i=h ; i<maxy; i++ ) | |
1260 { | |
1261 xptr = pchTemp + (maxx+7)/8 * (maxy-1-i); | |
1262 aptr = pchTemp + (maxx+7)/8 * (maxy+maxy-1-i); | |
1263 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1264 SDL_memset(xptr, 0, (maxx+7)/8); |
1190 | 1265 xptr += (maxx+7)/8; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1266 SDL_memset(aptr, ~0, (maxx+7)/8); |
1190 | 1267 aptr += (maxx+7)/8; |
1268 } | |
1269 | |
1270 hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)&bmih, CBM_INIT, (PBYTE) pchTemp, (PBITMAPINFO2)&bmi); | |
1271 hptr = WinCreatePointer(HWND_DESKTOP, hbm, TRUE, hot_x, maxy - hot_y - 1); | |
1272 | |
1273 #ifdef DEBUG_BUILD | |
1274 printf("HotSpot : %d ; %d\n", hot_x, hot_y); | |
1275 printf("HPS returned : %x\n", (ULONG)hps); | |
1276 printf("HBITMAP returned : %x\n", (ULONG)hbm); | |
1277 printf("HPOINTER returned: %x\n", (ULONG)hptr); | |
1278 #endif | |
1279 | |
1280 WinReleasePS(hps); | |
1281 | |
1282 #ifdef DEBUG_BUILD | |
1283 printf("[CreateWMCursor] : ptr = %p\n", hptr); fflush(stdout); | |
1284 #endif | |
1285 | |
1286 pResult->hptr = hptr; | |
1287 pResult->hbm = hbm; | |
1288 pResult->pchData = pchTemp; | |
1289 | |
1290 #ifdef DEBUG_BUILD | |
1291 printf("[CreateWMCursor] : ptr = %p return.\n", hptr); fflush(stdout); | |
1292 #endif | |
1293 | |
1294 return (WMcursor *) pResult; | |
1295 } | |
1296 | |
1297 WMcursor *os2fslib_CreateWMCursor_FS(_THIS, Uint8 *data, Uint8 *mask, | |
1298 int w, int h, int hot_x, int hot_y) | |
1299 { | |
1300 #ifdef DEBUG_BUILD | |
1301 printf("[CreateWMCursor_FS] : returning pointer NULL\n"); fflush(stdout); | |
1302 #endif | |
1303 | |
1304 // In FS mode we'll use software cursor | |
1305 return (WMcursor *) NULL; | |
1306 } | |
1307 | |
1308 /* Show the specified cursor, or hide if cursor is NULL */ | |
1309 int os2fslib_ShowWMCursor(_THIS, WMcursor *cursor) | |
1310 { | |
1311 #ifdef DEBUG_BUILD | |
1312 printf("[ShowWMCursor] : ptr = %p\n", cursor); fflush(stdout); | |
1313 #endif | |
1314 | |
1315 if (cursor) | |
1316 { | |
1317 WinSetPointer(HWND_DESKTOP, cursor->hptr); | |
1318 hptrGlobalPointer = cursor->hptr; | |
1319 _this->hidden->iMouseVisible = 1; | |
1320 } | |
1321 else | |
1322 { | |
1323 WinSetPointer(HWND_DESKTOP, FALSE); | |
1324 hptrGlobalPointer = NULL; | |
1325 _this->hidden->iMouseVisible = 0; | |
1326 } | |
1327 | |
1328 #ifdef DEBUG_BUILD | |
1329 printf("[ShowWMCursor] : ptr = %p, DONE\n", cursor); fflush(stdout); | |
1330 #endif | |
1331 | |
1332 return 1; | |
1333 } | |
1334 | |
1335 /* Warp the window manager cursor to (x,y) | |
1336 If NULL, a mouse motion event is posted internally. | |
1337 */ | |
1338 void os2fslib_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | |
1339 { | |
1340 LONG lx, ly; | |
1341 SWP swpClient; | |
1342 POINTL ptlPoints; | |
1343 WinQueryWindowPos(_this->hidden->hwndClient, &swpClient); | |
1344 ptlPoints.x = swpClient.x; | |
1345 ptlPoints.y = swpClient.y; | |
1346 WinMapWindowPoints(_this->hidden->hwndFrame, HWND_DESKTOP, &ptlPoints, 1); | |
1347 lx = ptlPoints.x + (x*swpClient.cx) / _this->hidden->SrcBufferDesc.uiXResolution; | |
1348 ly = ptlPoints.y + swpClient.cy - ((y*swpClient.cy) / _this->hidden->SrcBufferDesc.uiYResolution) - 1; | |
1349 | |
1350 SDL_PrivateMouseMotion(0, // Buttons not changed | |
1351 0, // Absolute position | |
1352 x, | |
1353 y); | |
1354 | |
1355 WinSetPointerPos(HWND_DESKTOP, lx, ly); | |
1356 | |
1357 } | |
1358 | |
1359 /* If not NULL, this is called when a mouse motion event occurs */ | |
1360 void os2fslib_MoveWMCursor(_THIS, int x, int y) | |
1361 { | |
1362 /* | |
1363 SDL_Rect rect; | |
1364 | |
1365 #ifdef DEBUG_BUILD | |
1366 printf("[MoveWMCursor] : at %d ; %d\n", x, y); fflush(stdout); | |
1367 #endif | |
1368 | |
1369 rect.x = x; | |
1370 rect.y = y; | |
1371 rect.w = 32; | |
1372 rect.h = 32; | |
1373 os2fslib_UpdateRects(_this, 1, &rect); | |
1374 // TODO! | |
1375 */ | |
1376 } | |
1377 | |
1378 /* Determine whether the mouse should be in relative mode or not. | |
1379 This function is called when the input grab state or cursor | |
1380 visibility state changes. | |
1381 If the cursor is not visible, and the input is grabbed, the | |
1382 driver can place the mouse in relative mode, which may result | |
1383 in higher accuracy sampling of the pointer motion. | |
1384 */ | |
1385 void os2fslib_CheckMouseMode(_THIS) | |
1386 { | |
1387 } | |
1388 | |
1389 static void os2fslib_PumpEvents(_THIS) | |
1390 { | |
1391 // Notify SDL that if window has been resized! | |
1392 if ( | |
1393 (_this->hidden->pSDLSurface) && | |
1394 (_this->hidden->pSDLSurface->flags & SDL_RESIZABLE) && | |
1395 ( | |
1396 (_this->hidden->SrcBufferDesc.uiXResolution!=iWindowSizeX) || | |
1397 (_this->hidden->SrcBufferDesc.uiYResolution!=iWindowSizeY) | |
1398 ) && | |
1399 (iWindowSizeX>0) && | |
1400 (iWindowSizeY>0) | |
1401 ) | |
1402 { | |
1403 static time_t prev_time; | |
1404 time_t curr_time; | |
1405 | |
1406 curr_time = time(NULL); | |
1407 if ((difftime(curr_time, prev_time)>=0.25) || | |
1408 (bWindowResized)) | |
1409 { | |
1410 // Make sure we won't flood the event queue with resize events, | |
1411 // only send them at 250 msecs! | |
1412 // (or when the window is resized) | |
1413 #ifdef DEBUG_BUILD | |
1414 printf("[os2fslib_PumpEvents] : Calling PrivateResize (%d %d).\n", | |
1415 iWindowSizeX, iWindowSizeY); | |
1416 fflush(stdout); | |
1417 #endif | |
1418 // Tell SDL the new size | |
1419 SDL_PrivateResize(iWindowSizeX, iWindowSizeY); | |
1420 prev_time = curr_time; | |
1421 bWindowResized = 0; | |
1422 } | |
1423 } | |
1424 } | |
1425 | |
1426 /* We don't actually allow hardware surfaces other than the main one */ | |
1427 static int os2fslib_AllocHWSurface(_THIS, SDL_Surface *surface) | |
1428 { | |
1429 return(-1); | |
1430 } | |
1431 static void os2fslib_FreeHWSurface(_THIS, SDL_Surface *surface) | |
1432 { | |
1433 return; | |
1434 } | |
1435 | |
1436 /* We need to wait for vertical retrace on page flipped displays */ | |
1437 static int os2fslib_LockHWSurface(_THIS, SDL_Surface *surface) | |
1438 { | |
1439 return(0); | |
1440 } | |
1441 | |
1442 static void os2fslib_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
1443 { | |
1444 return; | |
1445 } | |
1446 | |
1447 static int os2fslib_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
1448 { | |
1449 printf("[os2fslib_SetColors] : TODO!\n"); fflush(stdout); | |
1450 // TODO: Implement paletted modes | |
1451 return(1); | |
1452 } | |
1453 | |
1454 static void os2fslib_DestroyIcon(HWND hwndFrame) | |
1455 { | |
1456 if (hptrCurrentIcon) | |
1457 { | |
1458 WinDestroyPointer(hptrCurrentIcon); | |
1459 hptrCurrentIcon = NULL; | |
1460 | |
1461 WinSendMsg(hwndFrame, | |
1462 WM_SETICON, | |
1463 NULL, | |
1464 NULL); | |
1465 } | |
1466 | |
1467 } | |
1468 | |
1469 /* Set the window icon image */ | |
1470 void os2fslib_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask) | |
1471 { | |
1472 HWND hwndFrame; | |
1473 SDL_Surface *icon_rgb; | |
1474 HPOINTER hptrIcon; | |
1475 HBITMAP hbm; | |
1476 BITMAPINFOHEADER bmih; | |
1477 BMPINFO bmi; | |
1478 HPS hps; | |
1479 char *pchTemp; | |
1480 char *pptr, *mptr, *dptr, *dmptr; | |
1481 int maxx, maxy, w, h, x, y; | |
1482 SDL_Rect bounds; | |
1483 | |
1484 #ifdef DEBUG_BUILD | |
1485 printf("[os2fslib_SetIcon] : Creating and setting new icon\n"); fflush(stdout); | |
1486 #endif | |
1487 | |
1488 hwndFrame = WinQueryWindow(_this->hidden->hwndClient, QW_PARENT); | |
1489 | |
1490 // Make sure the old icon resource will be free'd! | |
1491 os2fslib_DestroyIcon(hwndFrame); | |
1492 | |
1493 if ((!icon) || (!mask)) | |
1494 return; | |
1495 | |
1496 w = icon->w; | |
1497 h = icon->h; | |
1498 | |
1499 maxx = WinQuerySysValue(HWND_DESKTOP, SV_CXICON); | |
1500 maxy = WinQuerySysValue(HWND_DESKTOP, SV_CYICON); | |
1501 | |
1502 // Check for max size! | |
1503 if ((w>maxx) || (h>maxy)) | |
1504 return; | |
1505 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1506 pchTemp = (char *) SDL_malloc(w * h*2 * 4); |
1190 | 1507 if (!pchTemp) |
1508 return; | |
1509 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1510 SDL_memset(pchTemp, 0, w * h*2 * 4); |
1190 | 1511 |
1512 // Convert surface to RGB, if it's not RGB yet! | |
1513 icon_rgb = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h, | |
1514 32, 0, 0, 0, 0); | |
1515 if ( icon_rgb == NULL ) | |
1516 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1517 SDL_free(pchTemp); |
1190 | 1518 return; |
1519 } | |
1520 bounds.x = 0; | |
1521 bounds.y = 0; | |
1522 bounds.w = icon->w; | |
1523 bounds.h = icon->h; | |
1524 if ( SDL_LowerBlit(icon, &bounds, icon_rgb, &bounds) < 0 ) | |
1525 { | |
1526 SDL_FreeSurface(icon_rgb); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1527 SDL_free(pchTemp); |
1190 | 1528 return; |
1529 } | |
1530 | |
1531 /* Copy pixels upside-down from RGB surface into BMP, masked with the icon mask */ | |
1532 | |
1533 // Pixels | |
1534 pptr = (char *) (icon_rgb->pixels); | |
1535 // Mask | |
1536 mptr = mask; | |
1537 | |
1538 for (y=0; y<h; y++) | |
1539 { | |
1540 unsigned char uchMaskByte; | |
1541 | |
1542 // Destination | |
1543 dptr = pchTemp + w*4 * (h-y-1); | |
1544 // Destination mask | |
1545 dmptr = pchTemp + w*h*4 + w*4 * (h-y-1); | |
1546 | |
1547 for (x=0; x<w; x++) | |
1548 { | |
1549 if (x%8==0) | |
1550 { | |
1551 uchMaskByte = (unsigned char) (*mptr); | |
1552 mptr++; | |
1553 } else | |
1554 uchMaskByte <<= 1; | |
1555 | |
1556 if (uchMaskByte & 0x80) | |
1557 { | |
1558 // Copy RGB | |
1559 *dptr++ = *pptr++; | |
1560 *dptr++ = *pptr++; | |
1561 *dptr++ = *pptr++; | |
1562 *dptr++ = *pptr++; | |
1563 | |
1564 *dmptr++ = 0; | |
1565 *dmptr++ = 0; | |
1566 *dmptr++ = 0; | |
1567 *dmptr++ = 0; | |
1568 } else | |
1569 { | |
1570 // Set pixels to fully transparent | |
1571 *dptr++ = 0; pptr++; | |
1572 *dptr++ = 0; pptr++; | |
1573 *dptr++ = 0; pptr++; | |
1574 *dptr++ = 0; pptr++; | |
1575 | |
1576 *dmptr++ = 255; | |
1577 *dmptr++ = 255; | |
1578 *dmptr++ = 255; | |
1579 *dmptr++ = 255; | |
1580 } | |
1581 } | |
1582 } | |
1583 | |
1584 // There is no more need for the RGB surface | |
1585 SDL_FreeSurface(icon_rgb); | |
1586 | |
1587 hps = WinGetPS(_this->hidden->hwndClient); | |
1588 | |
1589 bmi.cbFix = sizeof(BITMAPINFOHEADER); | |
1590 bmi.cx = w; | |
1591 bmi.cy = 2*h; | |
1592 bmi.cPlanes = 1; | |
1593 bmi.cBitCount = 32; | |
1594 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1595 SDL_memset(&bmih, 0, sizeof(BITMAPINFOHEADER)); |
1190 | 1596 bmih.cbFix = sizeof(BITMAPINFOHEADER); |
1597 bmih.cx = w; | |
1598 bmih.cy = 2*h; | |
1599 bmih.cPlanes = 1; | |
1600 bmih.cBitCount = 32; | |
1601 | |
1602 hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)&bmih, CBM_INIT, (PBYTE) pchTemp, (PBITMAPINFO2)&bmi); | |
1603 hptrIcon = WinCreatePointer(HWND_DESKTOP, hbm, FALSE, 0, 0); | |
1604 | |
1605 WinReleasePS(hps); | |
1606 | |
1607 // Free pixel array | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
1608 SDL_free(pchTemp); |
1190 | 1609 |
1610 // Change icon in frame window | |
1611 WinSendMsg(hwndFrame, | |
1612 WM_SETICON, | |
1613 (MPARAM) hptrIcon, | |
1614 NULL); | |
1615 | |
1616 /* | |
1617 // Change icon in switchlist | |
1618 // Seems like it's not needed, the WM_SETICON already does it. | |
1619 { | |
1620 PID pidFrame; | |
1621 HSWITCH hswitchFrame; | |
1622 SWCNTRL swctl; | |
1623 | |
1624 WinQueryWindowProcess(hwndFrame, &pidFrame, NULL); | |
1625 hswitchFrame = WinQuerySwitchHandle(hwndFrame, pidFrame); | |
1626 WinQuerySwitchEntry(hswitchFrame, &swctl); | |
1627 | |
1628 swctl.hwndIcon = hptrIcon; | |
1629 | |
1630 WinChangeSwitchEntry(hswitchFrame, &swctl); | |
1631 } | |
1632 */ | |
1633 | |
1634 // Store icon handle in global variable | |
1635 hptrCurrentIcon = hptrIcon; | |
1636 } | |
1637 | |
1638 // ------------------------ REAL FUNCTIONS ----------------- | |
1639 | |
1640 | |
1641 static void os2fslib_SetCursorManagementFunctions(_THIS, int iForWindowedMode) | |
1642 { | |
1643 if (iForWindowedMode) | |
1644 { | |
1645 _this->FreeWMCursor = os2fslib_FreeWMCursor; | |
1646 _this->CreateWMCursor = os2fslib_CreateWMCursor_Win; | |
1647 _this->ShowWMCursor = os2fslib_ShowWMCursor; | |
1648 _this->WarpWMCursor = os2fslib_WarpWMCursor; | |
1649 _this->MoveWMCursor = os2fslib_MoveWMCursor; | |
1650 _this->CheckMouseMode = NULL;//os2fslib_CheckMouseMode; | |
1651 } else | |
1652 { | |
1653 // We'll have software mouse cursor in FS mode! | |
1654 _this->FreeWMCursor = os2fslib_FreeWMCursor; | |
1655 _this->CreateWMCursor = os2fslib_CreateWMCursor_FS; | |
1656 _this->ShowWMCursor = os2fslib_ShowWMCursor; | |
1657 _this->WarpWMCursor = os2fslib_WarpWMCursor; | |
1658 _this->MoveWMCursor = os2fslib_MoveWMCursor; | |
1659 _this->CheckMouseMode = NULL;//os2fslib_CheckMouseMode; | |
1660 } | |
1661 } | |
1662 | |
1663 static void os2fslib_InitOSKeymap(_THIS) | |
1664 { | |
1665 int i; | |
1666 | |
1667 iShiftIsPressed = 0; | |
1668 | |
1669 /* Map the VK and CH keysyms */ | |
1670 for ( i=0; i<=255; ++i ) | |
1671 HWScanKeyMap[i] = SDLK_UNKNOWN; | |
1672 | |
1673 // First line of keyboard: | |
1674 HWScanKeyMap[0x1] = SDLK_ESCAPE; | |
1675 HWScanKeyMap[0x3b] = SDLK_F1; | |
1676 HWScanKeyMap[0x3c] = SDLK_F2; | |
1677 HWScanKeyMap[0x3d] = SDLK_F3; | |
1678 HWScanKeyMap[0x3e] = SDLK_F4; | |
1679 HWScanKeyMap[0x3f] = SDLK_F5; | |
1680 HWScanKeyMap[0x40] = SDLK_F6; | |
1681 HWScanKeyMap[0x41] = SDLK_F7; | |
1682 HWScanKeyMap[0x42] = SDLK_F8; | |
1683 HWScanKeyMap[0x43] = SDLK_F9; | |
1684 HWScanKeyMap[0x44] = SDLK_F10; | |
1685 HWScanKeyMap[0x57] = SDLK_F11; | |
1686 HWScanKeyMap[0x58] = SDLK_F12; | |
1687 HWScanKeyMap[0x5d] = SDLK_PRINT; | |
1688 HWScanKeyMap[0x46] = SDLK_SCROLLOCK; | |
1689 HWScanKeyMap[0x5f] = SDLK_PAUSE; | |
1690 | |
1691 // Second line of keyboard: | |
1692 HWScanKeyMap[0x29] = SDLK_BACKQUOTE; | |
1693 HWScanKeyMap[0x2] = SDLK_1; | |
1694 HWScanKeyMap[0x3] = SDLK_2; | |
1695 HWScanKeyMap[0x4] = SDLK_3; | |
1696 HWScanKeyMap[0x5] = SDLK_4; | |
1697 HWScanKeyMap[0x6] = SDLK_5; | |
1698 HWScanKeyMap[0x7] = SDLK_6; | |
1699 HWScanKeyMap[0x8] = SDLK_7; | |
1700 HWScanKeyMap[0x9] = SDLK_8; | |
1701 HWScanKeyMap[0xa] = SDLK_9; | |
1702 HWScanKeyMap[0xb] = SDLK_0; | |
1703 HWScanKeyMap[0xc] = SDLK_MINUS; | |
1704 HWScanKeyMap[0xd] = SDLK_EQUALS; | |
1705 HWScanKeyMap[0xe] = SDLK_BACKSPACE; | |
1706 HWScanKeyMap[0x68] = SDLK_INSERT; | |
1707 HWScanKeyMap[0x60] = SDLK_HOME; | |
1708 HWScanKeyMap[0x62] = SDLK_PAGEUP; | |
1709 HWScanKeyMap[0x45] = SDLK_NUMLOCK; | |
1710 HWScanKeyMap[0x5c] = SDLK_KP_DIVIDE; | |
1711 HWScanKeyMap[0x37] = SDLK_KP_MULTIPLY; | |
1712 HWScanKeyMap[0x4a] = SDLK_KP_MINUS; | |
1713 | |
1714 // Third line of keyboard: | |
1715 HWScanKeyMap[0xf] = SDLK_TAB; | |
1716 HWScanKeyMap[0x10] = SDLK_q; | |
1717 HWScanKeyMap[0x11] = SDLK_w; | |
1718 HWScanKeyMap[0x12] = SDLK_e; | |
1719 HWScanKeyMap[0x13] = SDLK_r; | |
1720 HWScanKeyMap[0x14] = SDLK_t; | |
1721 HWScanKeyMap[0x15] = SDLK_y; | |
1722 HWScanKeyMap[0x16] = SDLK_u; | |
1723 HWScanKeyMap[0x17] = SDLK_i; | |
1724 HWScanKeyMap[0x18] = SDLK_o; | |
1725 HWScanKeyMap[0x19] = SDLK_p; | |
1726 HWScanKeyMap[0x1a] = SDLK_LEFTBRACKET; | |
1727 HWScanKeyMap[0x1b] = SDLK_RIGHTBRACKET; | |
1728 HWScanKeyMap[0x1c] = SDLK_RETURN; | |
1729 HWScanKeyMap[0x69] = SDLK_DELETE; | |
1730 HWScanKeyMap[0x65] = SDLK_END; | |
1731 HWScanKeyMap[0x67] = SDLK_PAGEDOWN; | |
1732 HWScanKeyMap[0x47] = SDLK_KP7; | |
1733 HWScanKeyMap[0x48] = SDLK_KP8; | |
1734 HWScanKeyMap[0x49] = SDLK_KP9; | |
1735 HWScanKeyMap[0x4e] = SDLK_KP_PLUS; | |
1736 | |
1737 // Fourth line of keyboard: | |
1738 HWScanKeyMap[0x3a] = SDLK_CAPSLOCK; | |
1739 HWScanKeyMap[0x1e] = SDLK_a; | |
1740 HWScanKeyMap[0x1f] = SDLK_s; | |
1741 HWScanKeyMap[0x20] = SDLK_d; | |
1742 HWScanKeyMap[0x21] = SDLK_f; | |
1743 HWScanKeyMap[0x22] = SDLK_g; | |
1744 HWScanKeyMap[0x23] = SDLK_h; | |
1745 HWScanKeyMap[0x24] = SDLK_j; | |
1746 HWScanKeyMap[0x25] = SDLK_k; | |
1747 HWScanKeyMap[0x26] = SDLK_l; | |
1748 HWScanKeyMap[0x27] = SDLK_SEMICOLON; | |
1749 HWScanKeyMap[0x28] = SDLK_QUOTE; | |
1750 HWScanKeyMap[0x2b] = SDLK_BACKSLASH; | |
1751 HWScanKeyMap[0x4b] = SDLK_KP4; | |
1752 HWScanKeyMap[0x4c] = SDLK_KP5; | |
1753 HWScanKeyMap[0x4d] = SDLK_KP6; | |
1754 | |
1755 // Fifth line of keyboard: | |
1756 HWScanKeyMap[0x2a] = SDLK_LSHIFT; | |
1757 HWScanKeyMap[0x56] = SDLK_WORLD_1; // Code 161, letter i' on hungarian keyboard | |
1758 HWScanKeyMap[0x2c] = SDLK_z; | |
1759 HWScanKeyMap[0x2d] = SDLK_x; | |
1760 HWScanKeyMap[0x2e] = SDLK_c; | |
1761 HWScanKeyMap[0x2f] = SDLK_v; | |
1762 HWScanKeyMap[0x30] = SDLK_b; | |
1763 HWScanKeyMap[0x31] = SDLK_n; | |
1764 HWScanKeyMap[0x32] = SDLK_m; | |
1765 HWScanKeyMap[0x33] = SDLK_COMMA; | |
1766 HWScanKeyMap[0x34] = SDLK_PERIOD; | |
1767 HWScanKeyMap[0x35] = SDLK_SLASH; | |
1768 HWScanKeyMap[0x36] = SDLK_RSHIFT; | |
1769 HWScanKeyMap[0x61] = SDLK_UP; | |
1770 HWScanKeyMap[0x4f] = SDLK_KP1; | |
1771 HWScanKeyMap[0x50] = SDLK_KP2; | |
1772 HWScanKeyMap[0x51] = SDLK_KP3; | |
1773 HWScanKeyMap[0x5a] = SDLK_KP_ENTER; | |
1774 | |
1775 // Sixth line of keyboard: | |
1776 HWScanKeyMap[0x1d] = SDLK_LCTRL; | |
1777 HWScanKeyMap[0x7e] = SDLK_LSUPER; // Windows key | |
1778 HWScanKeyMap[0x38] = SDLK_LALT; | |
1779 HWScanKeyMap[0x39] = SDLK_SPACE; | |
1780 HWScanKeyMap[0x5e] = SDLK_RALT;// Actually, altgr on my keyboard... | |
1781 HWScanKeyMap[0x7f] = SDLK_RSUPER; | |
1782 HWScanKeyMap[0x7c] = SDLK_MENU; | |
1783 HWScanKeyMap[0x5b] = SDLK_RCTRL; | |
1784 HWScanKeyMap[0x63] = SDLK_LEFT; | |
1785 HWScanKeyMap[0x66] = SDLK_DOWN; | |
1786 HWScanKeyMap[0x64] = SDLK_RIGHT; | |
1787 HWScanKeyMap[0x52] = SDLK_KP0; | |
1788 HWScanKeyMap[0x53] = SDLK_KP_PERIOD; | |
1789 } | |
1790 | |
1791 | |
1792 /* Iconify the window. | |
1793 This function returns 1 if there is a window manager and the | |
1794 window was actually iconified, it returns 0 otherwise. | |
1795 */ | |
1796 int os2fslib_IconifyWindow(_THIS) | |
1797 { | |
1798 HAB hab; | |
1799 HMQ hmq; | |
1800 ERRORID hmqerror; | |
1801 | |
1802 // If there is no more window, nothing we can do! | |
1803 if (_this->hidden->iPMThreadStatus!=1) return 0; | |
1804 | |
1805 // Cannot do anything in fullscreen mode! | |
1806 if (FSLib_QueryFSMode(_this->hidden->hwndClient)) | |
1807 return 0; | |
1808 | |
1809 // Make sure this thread is prepared for using the Presentation Manager! | |
1810 hab = WinInitialize(0); | |
1811 hmq = WinCreateMsgQueue(hab,0); | |
1812 // Remember if there was an error at WinCreateMsgQueue(), because we don't | |
1813 // want to destroy somebody else's queue later. :) | |
1814 hmqerror = WinGetLastError(hab); | |
1815 | |
1816 WinSetWindowPos(_this->hidden->hwndFrame, HWND_TOP, | |
1817 0, 0, 0, 0, SWP_MINIMIZE); | |
1818 | |
1819 // Now destroy the message queue, if we've created it! | |
1820 if (ERRORIDERROR(hmqerror)==0) | |
1821 WinDestroyMsgQueue(hmq); | |
1822 | |
1823 return 1; | |
1824 } | |
1825 | |
1826 static SDL_GrabMode os2fslib_GrabInput(_THIS, SDL_GrabMode mode) | |
1827 { | |
1828 HAB hab; | |
1829 HMQ hmq; | |
1830 ERRORID hmqerror; | |
1831 | |
1832 | |
1833 // If there is no more window, nothing we can do! | |
1834 if (_this->hidden->iPMThreadStatus!=1) | |
1835 return SDL_GRAB_OFF; | |
1836 | |
1837 // Make sure this thread is prepared for using the Presentation Manager! | |
1838 hab = WinInitialize(0); | |
1839 hmq = WinCreateMsgQueue(hab,0); | |
1840 // Remember if there was an error at WinCreateMsgQueue(), because we don't | |
1841 // want to destroy somebody else's queue later. :) | |
1842 hmqerror = WinGetLastError(hab); | |
1843 | |
1844 | |
1845 if (mode == SDL_GRAB_OFF) | |
1846 { | |
1847 #ifdef DEBUG_BUILD | |
1848 printf("[os2fslib_GrabInput] : Releasing mouse\n"); fflush(stdout); | |
1849 #endif | |
1850 | |
1851 // Release the mouse | |
1852 bMouseCapturable = 0; | |
1853 if (bMouseCaptured) | |
1854 { | |
1855 WinSetCapture(HWND_DESKTOP, NULLHANDLE); | |
1856 bMouseCaptured = 0; | |
1857 } | |
1858 } else | |
1859 { | |
1860 #ifdef DEBUG_BUILD | |
1861 printf("[os2fslib_GrabInput] : Capturing mouse\n"); fflush(stdout); | |
1862 #endif | |
1863 | |
1864 // Capture the mouse | |
1865 bMouseCapturable = 1; | |
1866 if (WinQueryFocus(HWND_DESKTOP) == _this->hidden->hwndClient) | |
1867 { | |
1868 WinSetCapture(HWND_DESKTOP, _this->hidden->hwndClient); | |
1869 bMouseCaptured = 1; | |
1870 { | |
1871 SWP swpClient; | |
1872 POINTL ptl; | |
1873 // Center the mouse to the middle of the window! | |
1874 WinQueryWindowPos(_this->hidden->hwndClient, &swpClient); | |
1875 ptl.x = 0; ptl.y = 0; | |
1876 WinMapWindowPoints(_this->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); | |
1877 _this->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ | |
1878 WinSetPointerPos(HWND_DESKTOP, | |
1879 ptl.x + swpClient.cx/2, | |
1880 ptl.y + swpClient.cy/2); | |
1881 } | |
1882 } | |
1883 } | |
1884 | |
1885 // Now destroy the message queue, if we've created it! | |
1886 if (ERRORIDERROR(hmqerror)==0) | |
1887 WinDestroyMsgQueue(hmq); | |
1888 | |
1889 return mode; | |
1890 } | |
1891 | |
1892 /* Set the title and icon text */ | |
1893 static void os2fslib_SetCaption(_THIS, const char *title, const char *icon) | |
1894 { | |
1895 HAB hab; | |
1896 HMQ hmq; | |
1897 ERRORID hmqerror; | |
1898 | |
1899 // If there is no more window, nothing we can do! | |
1900 if (_this->hidden->iPMThreadStatus!=1) return; | |
1901 | |
1902 // Make sure this thread is prepared for using the Presentation Manager! | |
1903 hab = WinInitialize(0); | |
1904 hmq = WinCreateMsgQueue(hab,0); | |
1905 // Remember if there was an error at WinCreateMsgQueue(), because we don't | |
1906 // want to destroy somebody else's queue later. :) | |
1907 hmqerror = WinGetLastError(hab); | |
1908 | |
1909 WinSetWindowText(_this->hidden->hwndFrame, (char *) title); | |
1910 | |
1911 // Now destroy the message queue, if we've created it! | |
1912 if (ERRORIDERROR(hmqerror)==0) | |
1913 WinDestroyMsgQueue(hmq); | |
1914 } | |
1915 | |
1916 static int os2fslib_ToggleFullScreen(_THIS, int on) | |
1917 { | |
1918 #ifdef DEBUG_BUILD | |
1919 printf("[os2fslib_ToggleFullScreen] : %d\n", on); fflush(stdout); | |
1920 #endif | |
1921 // If there is no more window, nothing we can do! | |
1922 if (_this->hidden->iPMThreadStatus!=1) return 0; | |
1923 | |
1924 FSLib_ToggleFSMode(_this->hidden->hwndClient, on); | |
1925 /* Cursor manager functions to Windowed/FS mode*/ | |
1926 os2fslib_SetCursorManagementFunctions(_this, !on); | |
1927 return 1; | |
1928 } | |
1929 | |
1930 /* This is called after the video mode has been set, to get the | |
1931 initial mouse state. It should queue events as necessary to | |
1932 properly represent the current mouse focus and position. | |
1933 */ | |
1934 static void os2fslib_UpdateMouse(_THIS) | |
1935 { | |
1936 POINTL ptl; | |
1937 HAB hab; | |
1938 HMQ hmq; | |
1939 ERRORID hmqerror; | |
1940 SWP swpClient; | |
1941 | |
1942 // If there is no more window, nothing we can do! | |
1943 if (_this->hidden->iPMThreadStatus!=1) return; | |
1944 | |
1945 | |
1946 // Make sure this thread is prepared for using the Presentation Manager! | |
1947 hab = WinInitialize(0); | |
1948 hmq = WinCreateMsgQueue(hab,0); | |
1949 // Remember if there was an error at WinCreateMsgQueue(), because we don't | |
1950 // want to destroy somebody else's queue later. :) | |
1951 hmqerror = WinGetLastError(hab); | |
1952 | |
1953 | |
1954 | |
1955 if (_this->hidden->fInFocus) | |
1956 { | |
1957 // If our app is in focus | |
1958 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | |
1959 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); | |
1960 SDL_PrivateAppActive(1, SDL_APPACTIVE); | |
1961 WinQueryPointerPos(HWND_DESKTOP, &ptl); | |
1962 WinMapWindowPoints(HWND_DESKTOP, _this->hidden->hwndClient, &ptl, 1); | |
1963 WinQueryWindowPos(_this->hidden->hwndClient, &swpClient); | |
1964 // Convert OS/2 mouse position to SDL position, and also scale it! | |
1965 ptl.x = ptl.x * _this->hidden->SrcBufferDesc.uiXResolution / swpClient.cx; | |
1966 ptl.y = ptl.y * _this->hidden->SrcBufferDesc.uiYResolution / swpClient.cy; | |
1967 ptl.y = _this->hidden->SrcBufferDesc.uiYResolution - ptl.y - 1; | |
1968 SDL_PrivateMouseMotion(0, 0, (Sint16) (ptl.x), (Sint16) (ptl.y)); | |
1969 } else | |
1970 { | |
1971 // If we're not in focus | |
1972 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | |
1973 SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); | |
1974 SDL_PrivateAppActive(0, SDL_APPACTIVE); | |
1975 SDL_PrivateMouseMotion(0, 0, (Sint16) -1, (Sint16) -1); | |
1976 } | |
1977 | |
1978 // Now destroy the message queue, if we've created it! | |
1979 if (ERRORIDERROR(hmqerror)==0) | |
1980 WinDestroyMsgQueue(hmq); | |
1981 | |
1982 } | |
1983 | |
1984 /* This pointer should exist in the native video subsystem and should | |
1985 point to an appropriate update function for the current video mode | |
1986 */ | |
1987 static void os2fslib_UpdateRects(_THIS, int numrects, SDL_Rect *rects) | |
1988 { | |
1989 // If there is no more window, nothing we can do! | |
1990 if (_this->hidden->iPMThreadStatus!=1) return; | |
1991 | |
1992 #ifdef BITBLT_IN_WINMESSAGEPROC | |
1993 WinSendMsg(_this->hidden->hwndClient, | |
1994 WM_UPDATERECTSREQUEST, | |
1995 (MPARAM) numrects, | |
1996 (MPARAM) rects); | |
1997 #else | |
1998 if (DosRequestMutexSem(_this->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT)==NO_ERROR) | |
1999 { | |
2000 int i; | |
2001 | |
2002 if (_this->hidden->pSDLSurface) | |
2003 { | |
2004 #ifndef RESIZE_EVEN_IF_RESIZABLE | |
2005 SWP swp; | |
2006 // But only blit if the window is not resizable, or if | |
2007 // the window is resizable and the source buffer size is the | |
2008 // same as the destination buffer size! | |
2009 WinQueryWindowPos(_this->hidden->hwndClient, &swp); | |
2010 if ((_this->hidden->pSDLSurface) && | |
2011 (_this->hidden->pSDLSurface->flags & SDL_RESIZABLE) && | |
2012 ((swp.cx != _this->hidden->SrcBufferDesc.uiXResolution) || | |
2013 (swp.cy != _this->hidden->SrcBufferDesc.uiYResolution) | |
2014 ) && | |
2015 (!FSLib_QueryFSMode(_this->hidden->hwndClient)) | |
2016 ) | |
2017 { | |
2018 // Resizable surface and in resizing! | |
2019 // So, don't blit now! | |
2020 #ifdef DEBUG_BUILD | |
2021 printf("[UpdateRects] : Skipping blit while resizing!\n"); fflush(stdout); | |
2022 #endif | |
2023 } else | |
2024 #endif | |
2025 { | |
2026 /* | |
2027 // Blit the whole window | |
2028 FSLIB_BITBLT(_this->hidden->hwndClient, _this->hidden->pchSrcBuffer, | |
2029 0, 0, | |
2030 _this->hidden->SrcBufferDesc.uiXResolution, | |
2031 _this->hidden->SrcBufferDesc.uiYResolution); | |
2032 */ | |
2033 #ifdef DEBUG_BUILD | |
2034 printf("[os2fslib_UpdateRects] : Blitting!\n"); fflush(stdout); | |
2035 #endif | |
2036 | |
2037 // Blit the changed areas | |
2038 for (i=0; i<numrects; i++) | |
2039 FSLIB_BITBLT(_this->hidden->hwndClient, _this->hidden->pchSrcBuffer, | |
2040 rects[i].y, rects[i].x, rects[i].w, rects[i].h); | |
2041 } | |
2042 } | |
2043 #ifdef DEBUG_BUILD | |
2044 else | |
2045 printf("[os2fslib_UpdateRects] : No public surface!\n"); fflush(stdout); | |
2046 #endif | |
2047 DosReleaseMutexSem(_this->hidden->hmtxUseSrcBuffer); | |
2048 } | |
2049 #ifdef DEBUG_BUILD | |
2050 else | |
2051 printf("[os2fslib_UpdateRects] : Error in mutex!\n"); fflush(stdout); | |
2052 #endif | |
2053 #endif | |
2054 } | |
2055 | |
2056 | |
2057 /* Reverse the effects VideoInit() -- called if VideoInit() fails | |
2058 or if the application is shutting down the video subsystem. | |
2059 */ | |
2060 static void os2fslib_VideoQuit(_THIS) | |
2061 { | |
2062 #ifdef DEBUG_BUILD | |
2063 printf("[os2fslib_VideoQuit]\n"); fflush(stdout); | |
2064 #endif | |
2065 // Close PM stuff if running! | |
2066 if (_this->hidden->iPMThreadStatus == 1) | |
2067 { | |
2068 int iTimeout; | |
2069 WinPostMsg(_this->hidden->hwndFrame, WM_QUIT, (MPARAM) 0, (MPARAM) 0); | |
2070 // HACK: We had this line before: | |
2071 //DosWaitThread((TID *) &(_this->hidden->tidPMThread), DCWW_WAIT); | |
2072 // We don't use it, because the PMThread will never stop, or if it stops, | |
2073 // it will kill the whole process as a emergency fallback. | |
2074 // So, we only check for the iPMThreadStatus stuff! | |
2075 #ifdef DEBUG_BUILD | |
2076 printf("[os2fslib_VideoQuit] : Waiting for PM thread to die\n"); fflush(stdout); | |
2077 #endif | |
2078 | |
2079 iTimeout=0; | |
2080 while ((_this->hidden->iPMThreadStatus == 1) && (iTimeout<100)) | |
2081 { | |
2082 iTimeout++; | |
2083 DosSleep(64); | |
2084 } | |
2085 | |
2086 #ifdef DEBUG_BUILD | |
2087 printf("[os2fslib_VideoQuit] : End of wait.\n"); fflush(stdout); | |
2088 #endif | |
2089 | |
2090 if (_this->hidden->iPMThreadStatus == 1) | |
2091 { | |
2092 #ifdef DEBUG_BUILD | |
2093 printf("[os2fslib_VideoQuit] : Killing PM thread!\n"); fflush(stdout); | |
2094 #endif | |
2095 | |
2096 _this->hidden->iPMThreadStatus = 0; | |
2097 DosKillThread(_this->hidden->tidPMThread); | |
2098 | |
2099 if (_this->hidden->hwndFrame) | |
2100 { | |
2101 #ifdef DEBUG_BUILD | |
2102 printf("[os2fslib_VideoQuit] : Destroying PM window!\n"); fflush(stdout); | |
2103 #endif | |
2104 | |
2105 WinDestroyWindow(_this->hidden->hwndFrame); _this->hidden->hwndFrame=NULL; | |
2106 } | |
2107 } | |
2108 | |
2109 } | |
2110 | |
2111 // Free result of an old ListModes() call, because there is | |
2112 // no FreeListModes() call in SDL! | |
2113 if (_this->hidden->pListModesResult) | |
2114 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2115 SDL_free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL; |
1190 | 2116 } |
2117 | |
2118 // Free list of available fullscreen modes | |
2119 if (_this->hidden->pAvailableFSLibVideoModes) | |
2120 { | |
2121 FSLib_FreeVideoModeList(_this->hidden->pAvailableFSLibVideoModes); | |
2122 _this->hidden->pAvailableFSLibVideoModes = NULL; | |
2123 } | |
2124 | |
2125 // Free application icon if we had one | |
2126 if (hptrCurrentIcon) | |
2127 { | |
2128 WinDestroyPointer(hptrCurrentIcon); | |
2129 hptrCurrentIcon = NULL; | |
2130 } | |
2131 } | |
2132 | |
2133 /* Set the requested video mode, returning a surface which will be | |
2134 set to the SDL_VideoSurface. The width and height will already | |
2135 be verified by ListModes(), and the video subsystem is free to | |
2136 set the mode to a supported bit depth different from the one | |
2137 specified -- the desired bpp will be emulated with a shadow | |
2138 surface if necessary. If a new mode is returned, this function | |
2139 should take care of cleaning up the current mode. | |
2140 */ | |
2141 static SDL_Surface *os2fslib_SetVideoMode(_THIS, SDL_Surface *current, | |
2142 int width, int height, int bpp, Uint32 flags) | |
2143 { | |
2144 static int bFirstCall = 1; | |
2145 FSLib_VideoMode_p pModeInfo, pModeInfoFound; | |
2146 FSLib_VideoMode TempModeInfo; | |
2147 HAB hab; | |
2148 HMQ hmq; | |
2149 ERRORID hmqerror; | |
2150 RECTL rectl; | |
2151 SDL_Surface *pResult; | |
2152 | |
2153 // If there is no more window, nothing we can do! | |
2154 if (_this->hidden->iPMThreadStatus!=1) return NULL; | |
2155 | |
2156 #ifdef DEBUG_BUILD | |
2157 printf("[os2fslib_SetVideoMode] : Request for %dx%d @ %dBPP, flags=0x%x\n", width, height, bpp, flags); fflush(stdout); | |
2158 #endif | |
2159 | |
2160 // We don't support palette modes! | |
2161 if (bpp==8) bpp=32; | |
2162 | |
2163 // Also, we don't support resizable modes in fullscreen mode. | |
2164 if (flags & SDL_RESIZABLE) | |
2165 flags &= ~SDL_FULLSCREEN; | |
2166 | |
2167 // No double buffered mode | |
2168 if (flags & SDL_DOUBLEBUF) | |
2169 flags &= ~SDL_DOUBLEBUF; | |
2170 | |
2171 // And, we don't support HWSURFACE yet. | |
2172 if (flags & SDL_HWSURFACE) | |
2173 { | |
2174 flags &= ~SDL_HWSURFACE; | |
2175 flags |= SDL_SWSURFACE; | |
2176 } | |
2177 | |
2178 #ifdef DEBUG_BUILD | |
2179 printf("[os2fslib_SetVideoMode] : Changed request to %dx%d @ %dBPP, flags=0x%x\n", width, height, bpp, flags); fflush(stdout); | |
2180 #endif | |
2181 | |
2182 // First check if there is such a video mode they want! | |
2183 pModeInfoFound = NULL; | |
2184 | |
2185 // For fullscreen mode we don't support every resolution! | |
2186 // So, go through the video modes, and check for such a resolution! | |
2187 pModeInfoFound = NULL; | |
2188 pModeInfo = _this->hidden->pAvailableFSLibVideoModes; | |
2189 | |
2190 while (pModeInfo) | |
2191 { | |
2192 // Check all available fullscreen modes for this resolution | |
2193 if ((pModeInfo->uiXResolution == width) && | |
2194 (pModeInfo->uiYResolution == height) && | |
2195 (pModeInfo->uiBPP!=8)) // palettized modes not yet supported | |
2196 { | |
2197 // If good resolution, try to find the exact BPP, or at least | |
2198 // something similar... | |
2199 if (!pModeInfoFound) | |
2200 pModeInfoFound = pModeInfo; | |
2201 else | |
2202 if ((pModeInfoFound->uiBPP!=bpp) && | |
2203 (pModeInfoFound->uiBPP<pModeInfo->uiBPP)) | |
2204 pModeInfoFound = pModeInfo; | |
2205 } | |
2206 pModeInfo = pModeInfo->pNext; | |
2207 } | |
2208 | |
2209 // If we did not find a good fullscreen mode, then try a similar | |
2210 if (!pModeInfoFound) | |
2211 { | |
2212 #ifdef DEBUG_BUILD | |
2213 printf("[os2fslib_SetVideoMode] : Requested video mode not found, looking for a similar one!\n"); fflush(stdout); | |
2214 #endif | |
2215 // Go through the video modes again, and find a similar resolution! | |
2216 pModeInfo = _this->hidden->pAvailableFSLibVideoModes; | |
2217 while (pModeInfo) | |
2218 { | |
2219 // Check all available fullscreen modes for this resolution | |
2220 if ((pModeInfo->uiXResolution >= width) && | |
2221 (pModeInfo->uiYResolution >= height) && | |
2222 (pModeInfo->uiBPP == bpp)) | |
2223 { | |
2224 if (!pModeInfoFound) | |
2225 pModeInfoFound = pModeInfo; | |
2226 else | |
2227 if (((pModeInfoFound->uiXResolution-width)*(pModeInfoFound->uiYResolution-height))> | |
2228 ((pModeInfo->uiXResolution-width)*(pModeInfo->uiYResolution-height))) | |
2229 { | |
2230 // Found a mode which is closer than the current one | |
2231 pModeInfoFound = pModeInfo; | |
2232 } | |
2233 } | |
2234 pModeInfo = pModeInfo->pNext; | |
2235 } | |
2236 } | |
2237 | |
2238 // If we did not find a good fullscreen mode, then return NULL | |
2239 if (!pModeInfoFound) | |
2240 { | |
2241 #ifdef DEBUG_BUILD | |
2242 printf("[os2fslib_SetVideoMode] : Requested video mode not found!\n"); fflush(stdout); | |
2243 #endif | |
2244 return NULL; | |
2245 } | |
2246 | |
2247 #ifdef DEBUG_BUILD | |
2248 printf("[os2fslib_SetVideoMode] : Found mode!\n"); fflush(stdout); | |
2249 #endif | |
2250 | |
2251 // We'll possibly adjust the structure, so copy out the values | |
2252 // into TempModeInfo! | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2253 SDL_memcpy(&TempModeInfo, pModeInfoFound, sizeof(TempModeInfo)); |
1190 | 2254 pModeInfoFound = &TempModeInfo; |
2255 | |
2256 if (flags & SDL_RESIZABLE) | |
2257 { | |
2258 #ifdef DEBUG_BUILD | |
2259 printf("[os2fslib_SetVideoMode] : Requested mode is resizable, changing width/height\n"); fflush(stdout); | |
2260 #endif | |
2261 // Change width and height to requested one! | |
2262 TempModeInfo.uiXResolution = width; | |
2263 TempModeInfo.uiYResolution = height; | |
2264 TempModeInfo.uiScanLineSize = width * ((TempModeInfo.uiBPP+7)/8); | |
2265 } | |
2266 | |
2267 // We can try create new surface! | |
2268 | |
2269 // Make sure this thread is prepared for using the Presentation Manager! | |
2270 hab = WinInitialize(0); | |
2271 hmq = WinCreateMsgQueue(hab,0); | |
2272 // Remember if there was an error at WinCreateMsgQueue(), because we don't | |
2273 // want to destroy somebody else's queue later. :) | |
2274 hmqerror = WinGetLastError(hab); | |
2275 | |
2276 | |
2277 | |
2278 if (DosRequestMutexSem(_this->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT)==NO_ERROR) | |
2279 { | |
2280 #ifdef DEBUG_BUILD | |
2281 printf("[os2fslib_SetVideoMode] : Creating new SW surface\n"); fflush(stdout); | |
2282 #endif | |
2283 | |
2284 // Create new software surface! | |
2285 pResult = SDL_CreateRGBSurface(SDL_SWSURFACE, | |
2286 pModeInfoFound->uiXResolution, | |
2287 pModeInfoFound->uiYResolution, | |
2288 pModeInfoFound->uiBPP, | |
2289 ((unsigned int) pModeInfoFound->PixelFormat.ucRedMask) << pModeInfoFound->PixelFormat.ucRedPosition, | |
2290 ((unsigned int) pModeInfoFound->PixelFormat.ucGreenMask) << pModeInfoFound->PixelFormat.ucGreenPosition, | |
2291 ((unsigned int) pModeInfoFound->PixelFormat.ucBlueMask) << pModeInfoFound->PixelFormat.ucBluePosition, | |
2292 ((unsigned int) pModeInfoFound->PixelFormat.ucAlphaMask) << pModeInfoFound->PixelFormat.ucAlphaPosition); | |
2293 | |
2294 if (pResult == NULL) | |
2295 { | |
2296 DosReleaseMutexSem(_this->hidden->hmtxUseSrcBuffer); | |
2297 SDL_OutOfMemory(); | |
2298 return NULL; | |
2299 } | |
2300 | |
2301 #ifdef DEBUG_BUILD | |
2302 printf("[os2fslib_SetVideoMode] : Adjusting pixel format\n"); fflush(stdout); | |
2303 #endif | |
2304 | |
2305 // Adjust pixel format mask! | |
2306 pResult->format->Rmask = ((unsigned int) pModeInfoFound->PixelFormat.ucRedMask) << pModeInfoFound->PixelFormat.ucRedPosition; | |
2307 pResult->format->Rshift = pModeInfoFound->PixelFormat.ucRedPosition; | |
2308 pResult->format->Rloss = pModeInfoFound->PixelFormat.ucRedAdjust; | |
2309 pResult->format->Gmask = ((unsigned int) pModeInfoFound->PixelFormat.ucGreenMask) << pModeInfoFound->PixelFormat.ucGreenPosition; | |
2310 pResult->format->Gshift = pModeInfoFound->PixelFormat.ucGreenPosition; | |
2311 pResult->format->Gloss = pModeInfoFound->PixelFormat.ucGreenAdjust; | |
2312 pResult->format->Bmask = ((unsigned int) pModeInfoFound->PixelFormat.ucBlueMask) << pModeInfoFound->PixelFormat.ucBluePosition; | |
2313 pResult->format->Bshift = pModeInfoFound->PixelFormat.ucBluePosition; | |
2314 pResult->format->Bloss = pModeInfoFound->PixelFormat.ucBlueAdjust; | |
2315 pResult->format->Amask = ((unsigned int) pModeInfoFound->PixelFormat.ucAlphaMask) << pModeInfoFound->PixelFormat.ucAlphaPosition; | |
2316 pResult->format->Ashift = pModeInfoFound->PixelFormat.ucAlphaPosition; | |
2317 pResult->format->Aloss = pModeInfoFound->PixelFormat.ucAlphaAdjust; | |
2318 | |
2319 #ifdef REPORT_EMPTY_ALPHA_MASK | |
2320 pResult->format->Amask = | |
2321 pResult->format->Ashift = | |
2322 pResult->format->Aloss = 0; | |
2323 #endif | |
2324 | |
2325 // Adjust surface flags | |
2326 pResult->flags |= (flags & SDL_FULLSCREEN); | |
2327 pResult->flags |= (flags & SDL_RESIZABLE); | |
2328 | |
2329 // It might be that the software surface pitch is not the same as | |
2330 // the pitch we have, so adjust that! | |
2331 pModeInfoFound->uiScanLineSize = pResult->pitch; | |
2332 | |
2333 // Store new source buffer parameters! | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2334 SDL_memcpy(&(_this->hidden->SrcBufferDesc), pModeInfoFound, sizeof(*pModeInfoFound)); |
1190 | 2335 _this->hidden->pchSrcBuffer = pResult->pixels; |
2336 | |
2337 #ifdef DEBUG_BUILD | |
2338 printf("[os2fslib_SetVideoMode] : Telling FSLib the stuffs\n"); fflush(stdout); | |
2339 #endif | |
2340 | |
2341 // Tell the FSLib window the new source image format | |
2342 FSLib_SetSrcBufferDesc(_this->hidden->hwndClient, &(_this->hidden->SrcBufferDesc)); | |
2343 | |
2344 if ( | |
2345 ((flags & SDL_RESIZABLE)==0) || | |
2346 (bFirstCall) | |
2347 ) | |
2348 { | |
2349 bFirstCall = 0; | |
2350 #ifdef DEBUG_BUILD | |
2351 printf("[os2fslib_SetVideoMode] : Modifying window size\n"); fflush(stdout); | |
2352 #endif | |
2353 | |
2354 // Calculate frame window size from client window size | |
2355 rectl.xLeft = 0; | |
2356 rectl.yBottom = 0; | |
2357 rectl.xRight = pModeInfoFound->uiXResolution; // Noninclusive | |
2358 rectl.yTop = pModeInfoFound->uiYResolution; // Noninclusive | |
2359 WinCalcFrameRect(_this->hidden->hwndFrame, &rectl, FALSE); | |
2360 | |
2361 // Set the new size of the main window | |
2362 SetAccessableWindowPos(_this->hidden->hwndFrame, | |
2363 HWND_TOP, | |
2364 0, 0, | |
2365 (rectl.xRight-rectl.xLeft), | |
2366 (rectl.yTop-rectl.yBottom), | |
2367 SWP_SIZE | SWP_ACTIVATE | SWP_SHOW); | |
2368 } | |
2369 | |
2370 // Set fullscreen mode flag, and switch to fullscreen if needed! | |
2371 if (flags & SDL_FULLSCREEN) | |
2372 { | |
2373 #ifdef DEBUG_BUILD | |
2374 printf("[os2fslib_SetVideoMode] : Also trying to switch to fullscreen\n"); | |
2375 fflush(stdout); | |
2376 #endif | |
2377 FSLib_ToggleFSMode(_this->hidden->hwndClient, 1); | |
2378 /* Cursor manager functions to FS mode*/ | |
2379 os2fslib_SetCursorManagementFunctions(_this, 0); | |
2380 } else | |
2381 { | |
2382 #ifdef DEBUG_BUILD | |
2383 printf("[os2fslib_SetVideoMode] : Also trying to switch to desktop mode\n"); | |
2384 fflush(stdout); | |
2385 #endif | |
2386 FSLib_ToggleFSMode(_this->hidden->hwndClient, 0); | |
2387 /* Cursor manager functions to Windowed mode*/ | |
2388 os2fslib_SetCursorManagementFunctions(_this, 1); | |
2389 } | |
2390 | |
2391 _this->hidden->pSDLSurface = pResult; | |
2392 | |
2393 DosReleaseMutexSem(_this->hidden->hmtxUseSrcBuffer); | |
2394 } else | |
2395 { | |
2396 #ifdef DEBUG_BUILD | |
2397 printf("[os2fslib_SetVideoMode] : Could not get hmtxUseSrcBuffer!\n"); fflush(stdout); | |
2398 #endif | |
2399 | |
2400 pResult = NULL; | |
2401 } | |
2402 | |
2403 // As we have the new surface, we don't need the current one anymore! | |
2404 if ((pResult) && (current)) | |
2405 { | |
2406 #ifdef DEBUG_BUILD | |
2407 printf("[os2fslib_SetVideoMode] : Freeing old surface\n"); fflush(stdout); | |
2408 #endif | |
2409 SDL_FreeSurface(current); | |
2410 } | |
2411 | |
2412 // Redraw window | |
2413 WinInvalidateRegion(_this->hidden->hwndClient, NULL, TRUE); | |
2414 | |
2415 // Now destroy the message queue, if we've created it! | |
2416 if (ERRORIDERROR(hmqerror)==0) | |
2417 { | |
2418 #ifdef DEBUG_BUILD | |
2419 printf("[os2fslib_SetVideoMode] : Destroying message queue\n"); fflush(stdout); | |
2420 #endif | |
2421 WinDestroyMsgQueue(hmq); | |
2422 } | |
2423 | |
2424 #ifdef DEBUG_BUILD | |
2425 printf("[os2fslib_SetVideoMode] : Done\n"); fflush(stdout); | |
2426 #endif | |
2427 | |
2428 /* We're done */ | |
2429 | |
2430 // Return with the new surface! | |
2431 return pResult; | |
2432 } | |
2433 | |
2434 /* List the available video modes for the given pixel format, sorted | |
2435 from largest to smallest. | |
2436 */ | |
2437 static SDL_Rect **os2fslib_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
2438 { | |
2439 #ifdef DEBUG_BUILD | |
2440 printf("[os2fslib_ListModes] : ListModes of %d Bpp\n", format->BitsPerPixel); | |
2441 #endif | |
2442 // Destroy result of previous call, if there is any | |
2443 if (_this->hidden->pListModesResult) | |
2444 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2445 SDL_free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL; |
1190 | 2446 } |
2447 | |
2448 // For resizable and windowed mode we support every resolution! | |
2449 if ((flags & SDL_RESIZABLE) && ((flags & SDL_FULLSCREEN) == 0)) | |
2450 return (SDL_Rect **)-1; | |
2451 | |
2452 // Check if they need fullscreen or non-fullscreen video modes! | |
2453 if ((flags & SDL_FULLSCREEN) == 0) | |
2454 | |
2455 { | |
2456 // For windowed mode we support every resolution! | |
2457 return (SDL_Rect **)-1; | |
2458 } else | |
2459 { | |
2460 FSLib_VideoMode_p pFSMode; | |
2461 // For fullscreen mode we don't support every resolution! | |
2462 // Now create a new list | |
2463 pFSMode = _this->hidden->pAvailableFSLibVideoModes; | |
2464 while (pFSMode) | |
2465 { | |
2466 if (pFSMode->uiBPP == format->BitsPerPixel) | |
2467 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2468 SDL_Rect *pRect = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect)); |
1190 | 2469 if (pRect) |
2470 { | |
2471 // Fill description | |
2472 pRect->x = 0; | |
2473 pRect->y = 0; | |
2474 pRect->w = pFSMode->uiXResolution; | |
2475 pRect->h = pFSMode->uiYResolution; | |
2476 #ifdef DEBUG_BUILD | |
2477 // printf("!!! Seems to be good!\n"); | |
2478 // printf("F: %dx%d\n", pRect->w, pRect->h); | |
2479 #endif | |
2480 // And insert into list of pRects | |
2481 if (!(_this->hidden->pListModesResult)) | |
2482 { | |
2483 #ifdef DEBUG_BUILD | |
2484 // printf("!!! Inserting to beginning\n"); | |
2485 #endif | |
2486 | |
2487 // We're the first one to be inserted! | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2488 _this->hidden->pListModesResult = (SDL_Rect**) SDL_malloc(2*sizeof(SDL_Rect*)); |
1190 | 2489 if (_this->hidden->pListModesResult) |
2490 { | |
2491 _this->hidden->pListModesResult[0] = pRect; | |
2492 _this->hidden->pListModesResult[1] = NULL; | |
2493 } else | |
2494 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2495 SDL_free(pRect); |
1190 | 2496 } |
2497 } else | |
2498 { | |
2499 // We're not the first ones, so find the place where we | |
2500 // have to insert ourselves | |
2501 SDL_Rect **pNewList; | |
2502 int iPlace, iNumOfSlots, i; | |
2503 | |
2504 #ifdef DEBUG_BUILD | |
2505 // printf("!!! Searching where to insert\n"); | |
2506 #endif | |
2507 | |
2508 iPlace = -1; iNumOfSlots = 1; // Count the last NULL too! | |
2509 for (i=0; _this->hidden->pListModesResult[i]; i++) | |
2510 { | |
2511 iNumOfSlots++; | |
2512 if (iPlace==-1) | |
2513 { | |
2514 if ((_this->hidden->pListModesResult[i]->w*_this->hidden->pListModesResult[i]->h)< | |
2515 (pRect->w*pRect->h)) | |
2516 { | |
2517 iPlace = i; | |
2518 } | |
2519 } | |
2520 } | |
2521 if (iPlace==-1) iPlace = iNumOfSlots-1; | |
2522 | |
2523 #ifdef DEBUG_BUILD | |
2524 // printf("!!! From %d slots, it will be at %d\n", iNumOfSlots, iPlace); | |
2525 #endif | |
2526 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2527 pNewList = (SDL_Rect**) SDL_realloc(_this->hidden->pListModesResult, (iNumOfSlots+1)*sizeof(SDL_Rect*)); |
1190 | 2528 if (pNewList) |
2529 { | |
2530 for (i=iNumOfSlots;i>iPlace;i--) | |
2531 pNewList[i] = pNewList[i-1]; | |
2532 pNewList[iPlace] = pRect; | |
2533 _this->hidden->pListModesResult = pNewList; | |
2534 } else | |
2535 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2536 SDL_free(pRect); |
1190 | 2537 } |
2538 } | |
2539 } | |
2540 } | |
2541 pFSMode = pFSMode->pNext; | |
2542 } | |
2543 } | |
2544 #ifdef DEBUG_BUILD | |
2545 // printf("Returning list\n"); | |
2546 #endif | |
2547 return _this->hidden->pListModesResult; | |
2548 } | |
2549 | |
2550 /* Initialize the native video subsystem, filling 'vformat' with the | |
2551 "best" display pixel format, returning 0 or -1 if there's an error. | |
2552 */ | |
2553 static int os2fslib_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
2554 { | |
2555 FSLib_VideoMode_p pDesktopMode; | |
2556 | |
2557 #ifdef DEBUG_BUILD | |
2558 printf("[os2fslib_VideoInit] : Enter\n"); fflush(stdout); | |
2559 #endif | |
2560 | |
2561 // Report the best pixel format. For this, | |
2562 // we'll use the current desktop format. | |
2563 pDesktopMode = FSLib_GetDesktopVideoMode(); | |
2564 if (!pDesktopMode) | |
2565 { | |
2566 SDL_SetError("Could not query desktop video mode!"); | |
2567 #ifdef DEBUG_BUILD | |
2568 printf("[os2fslib_VideoInit] : Could not query desktop video mode!\n"); | |
2569 #endif | |
2570 return -1; | |
2571 } | |
2572 | |
2573 /* Determine the screen depth */ | |
2574 vformat->BitsPerPixel = pDesktopMode->uiBPP; | |
2575 vformat->BytesPerPixel = (vformat->BitsPerPixel+7)/8; | |
2576 | |
2577 vformat->Rmask = ((unsigned int) pDesktopMode->PixelFormat.ucRedMask) << pDesktopMode->PixelFormat.ucRedPosition; | |
2578 vformat->Rshift = pDesktopMode->PixelFormat.ucRedPosition; | |
2579 vformat->Rloss = pDesktopMode->PixelFormat.ucRedAdjust; | |
2580 vformat->Gmask = ((unsigned int) pDesktopMode->PixelFormat.ucGreenMask) << pDesktopMode->PixelFormat.ucGreenPosition; | |
2581 vformat->Gshift = pDesktopMode->PixelFormat.ucGreenPosition; | |
2582 vformat->Gloss = pDesktopMode->PixelFormat.ucGreenAdjust; | |
2583 vformat->Bmask = ((unsigned int) pDesktopMode->PixelFormat.ucBlueMask) << pDesktopMode->PixelFormat.ucBluePosition; | |
2584 vformat->Bshift = pDesktopMode->PixelFormat.ucBluePosition; | |
2585 vformat->Bloss = pDesktopMode->PixelFormat.ucBlueAdjust; | |
2586 vformat->Amask = ((unsigned int) pDesktopMode->PixelFormat.ucAlphaMask) << pDesktopMode->PixelFormat.ucAlphaPosition; | |
2587 vformat->Ashift = pDesktopMode->PixelFormat.ucAlphaPosition; | |
2588 vformat->Aloss = pDesktopMode->PixelFormat.ucAlphaAdjust; | |
2589 | |
2590 #ifdef REPORT_EMPTY_ALPHA_MASK | |
2591 vformat->Amask = | |
2592 vformat->Ashift = | |
2593 vformat->Aloss = 0; | |
2594 #endif | |
2595 | |
2596 // Fill in some window manager capabilities | |
2597 _this->info.wm_available = 1; | |
2598 | |
2599 // Initialize some internal variables | |
2600 _this->hidden->pListModesResult = NULL; | |
2601 _this->hidden->fInFocus = 0; | |
2602 _this->hidden->iSkipWMMOUSEMOVE = 0; | |
2603 _this->hidden->iMouseVisible = 1; | |
2604 DosCreateMutexSem(NULL, &(_this->hidden->hmtxUseSrcBuffer), 0, FALSE); | |
2605 | |
2606 // Now create our window with a default size | |
2607 | |
2608 // For this, we select the first available fullscreen mode as | |
2609 // current window size! | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2610 SDL_memcpy(&(_this->hidden->SrcBufferDesc), _this->hidden->pAvailableFSLibVideoModes, sizeof(_this->hidden->SrcBufferDesc)); |
1190 | 2611 // Allocate new video buffer! |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2612 _this->hidden->pchSrcBuffer = (char *) SDL_malloc(_this->hidden->pAvailableFSLibVideoModes->uiScanLineSize * _this->hidden->pAvailableFSLibVideoModes->uiYResolution); |
1190 | 2613 if (!_this->hidden->pchSrcBuffer) |
2614 { | |
2615 #ifdef DEBUG_BUILD | |
2616 printf("[os2fslib_VideoInit] : Yikes, not enough memory for new video buffer!\n"); fflush(stdout); | |
2617 #endif | |
2618 SDL_SetError("Not enough memory for new video buffer!\n"); | |
2619 return -1; | |
2620 } | |
2621 | |
2622 // For this, we need a message processing thread. | |
2623 // We'll create a new thread for this, which will do everything | |
2624 // what is related to PM | |
2625 _this->hidden->iPMThreadStatus = 0; | |
2626 _this->hidden->tidPMThread = _beginthread(PMThreadFunc, NULL, 65536, (void *) _this); | |
2627 if (_this->hidden->tidPMThread <= 0) | |
2628 { | |
2629 #ifdef DEBUG_BUILD | |
2630 printf("[os2fslib_VideoInit] : Could not create PM thread!\n"); | |
2631 #endif | |
2632 SDL_SetError("Could not create PM thread"); | |
2633 return -1; | |
2634 } | |
2635 #ifdef USE_DOSSETPRIORITY | |
2636 // Burst the priority of PM Thread! | |
2637 DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, _this->hidden->tidPMThread); | |
2638 #endif | |
2639 // Wait for the PM thread to initialize! | |
2640 while (_this->hidden->iPMThreadStatus==0) | |
2641 DosSleep(32); | |
2642 // If the PM thread could not set up everything, then | |
2643 // report an error! | |
2644 if (_this->hidden->iPMThreadStatus!=1) | |
2645 { | |
2646 #ifdef DEBUG_BUILD | |
2647 printf("[os2fslib_VideoInit] : PMThread reported an error : %d\n", _this->hidden->iPMThreadStatus); | |
2648 #endif | |
2649 SDL_SetError("Error initializing PM thread"); | |
2650 return -1; | |
2651 } | |
2652 | |
2653 return 0; | |
2654 } | |
2655 | |
2656 | |
2657 static void os2fslib_DeleteDevice(_THIS) | |
2658 { | |
2659 #ifdef DEBUG_BUILD | |
2660 printf("[os2fslib_DeleteDevice]\n"); fflush(stdout); | |
2661 #endif | |
2662 // Free used memory | |
2663 FSLib_FreeVideoModeList(_this->hidden->pAvailableFSLibVideoModes); | |
2664 if (_this->hidden->pListModesResult) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2665 SDL_free(_this->hidden->pListModesResult); |
1190 | 2666 if (_this->hidden->pchSrcBuffer) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2667 SDL_free(_this->hidden->pchSrcBuffer); |
1190 | 2668 DosCloseMutexSem(_this->hidden->hmtxUseSrcBuffer); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2669 SDL_free(_this->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2670 SDL_free(_this); |
1190 | 2671 FSLib_Uninitialize(); |
2672 } | |
2673 | |
2674 static int os2fslib_Available(void) | |
2675 { | |
2676 | |
2677 // If we can run, it means that we could load FSLib, | |
2678 // so we assume that it's available then! | |
2679 return 1; | |
2680 } | |
2681 | |
2682 static void os2fslib_MorphToPM() | |
2683 { | |
2684 PPIB pib; | |
2685 PTIB tib; | |
2686 | |
2687 DosGetInfoBlocks(&tib, &pib); | |
2688 | |
2689 // Change flag from VIO to PM: | |
2690 if (pib->pib_ultype==2) pib->pib_ultype = 3; | |
2691 } | |
2692 | |
2693 static SDL_VideoDevice *os2fslib_CreateDevice(int devindex) | |
2694 { | |
2695 SDL_VideoDevice *device; | |
2696 | |
2697 #ifdef DEBUG_BUILD | |
2698 printf("[os2fslib_CreateDevice] : Enter\n"); fflush(stdout); | |
2699 #endif | |
2700 | |
2701 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2702 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
1190 | 2703 if ( device ) |
2704 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2705 SDL_memset(device, 0, (sizeof *device)); |
1190 | 2706 // Also allocate memory for private data |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2707 device->hidden = (struct SDL_PrivateVideoData *) SDL_malloc((sizeof(struct SDL_PrivateVideoData))); |
1190 | 2708 } |
2709 if ( (device == NULL) || (device->hidden == NULL) ) | |
2710 { | |
2711 SDL_OutOfMemory(); | |
2712 if ( device ) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2713 SDL_free(device); |
1190 | 2714 return NULL; |
2715 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2716 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
1190 | 2717 |
2718 /* Set the function pointers */ | |
2719 #ifdef DEBUG_BUILD | |
2720 printf("[os2fslib_CreateDevice] : VideoInit is %p\n", os2fslib_VideoInit); fflush(stdout); | |
2721 #endif | |
2722 | |
2723 /* Initialization/Query functions */ | |
2724 device->VideoInit = os2fslib_VideoInit; | |
2725 device->ListModes = os2fslib_ListModes; | |
2726 device->SetVideoMode = os2fslib_SetVideoMode; | |
2727 device->ToggleFullScreen = os2fslib_ToggleFullScreen; | |
2728 device->UpdateMouse = os2fslib_UpdateMouse; | |
2729 device->CreateYUVOverlay = NULL; | |
2730 device->SetColors = os2fslib_SetColors; | |
2731 device->UpdateRects = os2fslib_UpdateRects; | |
2732 device->VideoQuit = os2fslib_VideoQuit; | |
2733 /* Hardware acceleration functions */ | |
2734 device->AllocHWSurface = os2fslib_AllocHWSurface; | |
2735 device->CheckHWBlit = NULL; | |
2736 device->FillHWRect = NULL; | |
2737 device->SetHWColorKey = NULL; | |
2738 device->SetHWAlpha = NULL; | |
2739 device->LockHWSurface = os2fslib_LockHWSurface; | |
2740 device->UnlockHWSurface = os2fslib_UnlockHWSurface; | |
2741 device->FlipHWSurface = NULL; | |
2742 device->FreeHWSurface = os2fslib_FreeHWSurface; | |
2743 /* Window manager functions */ | |
2744 device->SetCaption = os2fslib_SetCaption; | |
2745 device->SetIcon = os2fslib_SetIcon; | |
2746 device->IconifyWindow = os2fslib_IconifyWindow; | |
2747 device->GrabInput = os2fslib_GrabInput; | |
2748 device->GetWMInfo = NULL; | |
2749 /* Cursor manager functions to Windowed mode*/ | |
2750 os2fslib_SetCursorManagementFunctions(device, 1); | |
2751 /* Event manager functions */ | |
2752 device->InitOSKeymap = os2fslib_InitOSKeymap; | |
2753 device->PumpEvents = os2fslib_PumpEvents; | |
2754 /* The function used to dispose of this structure */ | |
2755 device->free = os2fslib_DeleteDevice; | |
2756 | |
2757 // Make sure we'll be able to use Win* API even if the application | |
2758 // was linked to be a VIO application! | |
2759 os2fslib_MorphToPM(); | |
2760 | |
2761 // Now initialize FSLib, and query available video modes! | |
2762 if (!FSLib_Initialize()) | |
2763 { | |
2764 // Could not initialize FSLib! | |
2765 #ifdef DEBUG_BUILD | |
2766 printf("[os2fslib_CreateDevice] : Could not initialize FSLib!\n"); | |
2767 #endif | |
2768 SDL_SetError("Could not initialize FSLib!"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2769 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
2770 SDL_free(device); |
1190 | 2771 return NULL; |
2772 } | |
2773 device->hidden->pAvailableFSLibVideoModes = | |
2774 FSLib_GetVideoModeList(); | |
2775 | |
2776 return device; | |
2777 } | |
2778 | |
2779 VideoBootStrap OS2FSLib_bootstrap = { | |
2780 "os2fslib", "OS/2 Video Output using FSLib", | |
2781 os2fslib_Available, os2fslib_CreateDevice | |
2782 }; | |
2783 |