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