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