Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
3122 lines (2772 loc) · 107 KB

SDL_os2fslib.c

File metadata and controls

3122 lines (2772 loc) · 107 KB
 
Nov 23, 2005
Nov 23, 2005
1
2
/*
SDL - Simple DirectMedia Layer
Dec 8, 2008
Dec 8, 2008
3
Copyright (C) 1997-2009 Sam Lantinga
Nov 23, 2005
Nov 23, 2005
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Nov 23, 2005
Nov 23, 2005
23
Feb 26, 2006
Feb 26, 2006
24
25
#define _ULS_CALLCONV_
#define CALLCONV _System
Jul 10, 2006
Jul 10, 2006
26
27
#include <unidef.h> // Unicode API
#include <uconv.h> // Unicode API (codepage conversion)
Feb 26, 2006
Feb 26, 2006
28
Nov 23, 2005
Nov 23, 2005
29
30
31
32
33
#include <process.h>
#include <time.h>
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
34
35
36
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
Nov 23, 2005
Nov 23, 2005
37
38
39
40
#include "SDL_os2fslib.h"
static ULONG ulFCFToUse =
Jul 10, 2006
Jul 10, 2006
41
42
43
44
45
46
FCF_TITLEBAR |
FCF_SYSMENU |
FCF_MINBUTTON |
FCF_MAXBUTTON | FCF_NOBYTEALIGN | FCF_SIZEBORDER | FCF_TASKLIST;
static int bMouseCaptured = 0;
Nov 23, 2005
Nov 23, 2005
47
48
49
50
51
52
53
54
55
56
static int bMouseCapturable = 0;
static HPOINTER hptrGlobalPointer = NULL;
static HPOINTER hptrCurrentIcon = NULL;
static int iWindowSizeX = 320;
static int iWindowSizeY = 200;
static int bWindowResized = 0;
#pragma pack(1)
typedef struct BMPINFO
{
Jul 10, 2006
Jul 10, 2006
57
58
BITMAPINFO;
RGB clr;
Nov 23, 2005
Nov 23, 2005
59
60
61
62
63
} BMPINFO, *PBMPINFO;
#pragma pack()
// Backdoors:
Jul 10, 2006
Jul 10, 2006
64
65
DECLSPEC void SDLCALL
SDL_OS2FSLIB_SetFCFToUse(ULONG ulFCF)
Nov 23, 2005
Nov 23, 2005
66
{
Jul 10, 2006
Jul 10, 2006
67
ulFCFToUse = ulFCF;
Nov 23, 2005
Nov 23, 2005
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
}
// Configuration defines:
// We have to report empty alpha mask, otherwise SDL will select
// alpha blitters, and this will have unwanted results, as we don't
// support alpha channel in FSLib yet.
#define REPORT_EMPTY_ALPHA_MASK
// Experimental: Move every FSLib_BitBlt() call into window message
// processing function.
// This may fix dirt left on desktop. Or not.
//#define BITBLT_IN_WINMESSAGEPROC
// Experimental-2: Use WinLockWindowUpdate() in around bitblts!
// This is not enabled, because it seems to cause more problems
// than good.
//#define USE_WINLOCKWINDOWUPDATE_AROUND_BITBLTS
// Use the following to show resized image instead of black stuff
// even if the surface is resizable.
//#define RESIZE_EVEN_IF_RESIZABLE
/* The translation table from a VK keysym to a SDL keysym */
static SDLKey HWScanKeyMap[256];
Jul 10, 2006
Jul 10, 2006
93
94
95
static SDL_keysym *TranslateKey(int vkey, int chcode, int scancode,
SDL_keysym * keysym, int iPressed);
static int iShiftIsPressed;
Nov 23, 2005
Nov 23, 2005
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifdef BITBLT_IN_WINMESSAGEPROC
#define WM_UPDATERECTSREQUEST WM_USER+50
#endif
#ifdef USE_WINLOCKWINDOWUPDATE_AROUND_BITBLTS
#define FSLIB_BITBLT(hwnd, buffer, top, left, width, height) \
{ \
WinLockWindowUpdate(HWND_DESKTOP, HWND_DESKTOP); \
FSLib_BitBlt(hwnd, buffer, top, left, width, height); \
WinLockWindowUpdate(HWND_DESKTOP, NULL); \
}
#else
#define FSLIB_BITBLT(hwnd, buffer, top, left, width, height) \
FSLib_BitBlt(hwnd, buffer, top, left, width, height);
#endif
/////////////////////////////////////////////////////////////////////
//
// SetAccessableWindowPos
//
// Same as WinSetWindowPos(), but takes care for the window to be
// always on the screen, the titlebar will be accessable everytime.
//
/////////////////////////////////////////////////////////////////////
Jul 10, 2006
Jul 10, 2006
121
122
123
static BOOL
SetAccessableWindowPos(HWND hwnd, HWND hwndInsertBehind,
LONG x, LONG y, LONG cx, LONG cy, ULONG fl)
Nov 23, 2005
Nov 23, 2005
124
{
Jul 10, 2006
Jul 10, 2006
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
SWP swpDesktop, swp;
// Get desktop area
WinQueryWindowPos(HWND_DESKTOP, &swpDesktop);
if ((fl & SWP_MOVE) && (fl & SWP_SIZE)) {
// If both moving and sizing, then change size and pos now!!
if (x + cx > swpDesktop.cx)
x = swpDesktop.cx - cx;
if (x < 0)
x = 0;
if (y < 0)
y = 0;
if (y + cy > swpDesktop.cy)
y = swpDesktop.cy - cy;
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
} else if (fl & SWP_MOVE) {
// Just moving
WinQueryWindowPos(hwnd, &swp);
if (x + swp.cx > swpDesktop.cx)
x = swpDesktop.cx - swp.cx;
if (x < 0)
x = 0;
if (y < 0)
y = 0;
if (y + swp.cy > swpDesktop.cy)
y = swpDesktop.cy - swp.cy;
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
} else if (fl & SWP_SIZE) {
// Just sizing
WinQueryWindowPos(hwnd, &swp);
x = swp.x;
y = swp.y;
if (x + cx > swpDesktop.cx)
x = swpDesktop.cx - cx;
if (x < 0)
x = 0;
if (y < 0)
y = 0;
if (y + cy > swpDesktop.cy)
y = swpDesktop.cy - cy;
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy,
fl | SWP_MOVE);
} else
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
Nov 23, 2005
Nov 23, 2005
169
170
}
Jul 10, 2006
Jul 10, 2006
171
172
static UniChar
NativeCharToUniChar(int chcode)
Feb 26, 2006
Feb 26, 2006
173
{
Jul 10, 2006
Jul 10, 2006
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
UniChar ucResult = (UniChar) chcode;
int rc;
UconvObject ucoTemp;
char achFrom[2];
char *pchFrom;
size_t iFromCount;
UniChar aucTo[10];
UniChar *pucTo;
size_t iToCount;
size_t iNonIdentical;
// Create unicode convert object
rc = UniCreateUconvObject(L"", &ucoTemp);
if (rc != ULS_SUCCESS) {
// Could not create convert object!
return ucResult;
}
// Convert language code string to unicode string
achFrom[0] = (char) chcode;
achFrom[1] = 0;
iFromCount = sizeof(char) * 2;
iToCount = sizeof(UniChar) * 2;
pucTo = &(aucTo[0]);
pchFrom = &(achFrom[0]);
rc = UniUconvToUcs(ucoTemp,
&pchFrom,
&iFromCount, &pucTo, &iToCount, &iNonIdentical);
if (rc != ULS_SUCCESS) {
// Could not convert language code to UCS string!
UniFreeUconvObject(ucoTemp);
return ucResult;
}
Feb 26, 2006
Feb 26, 2006
208
Jul 10, 2006
Jul 10, 2006
209
UniFreeUconvObject(ucoTemp);
Feb 26, 2006
Feb 26, 2006
210
211
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
212
printf("%02x converted to %02x\n", (int) chcode, (int) (aucTo[0]));
Feb 26, 2006
Feb 26, 2006
213
214
#endif
Jul 10, 2006
Jul 10, 2006
215
return aucTo[0];
Feb 26, 2006
Feb 26, 2006
216
217
}
Nov 23, 2005
Nov 23, 2005
218
219
220
221
222
223
224
/////////////////////////////////////////////////////////////////////
//
// TranslateKey
//
// This creates SDL Keycodes from VK_ and hardware scan codes
//
/////////////////////////////////////////////////////////////////////
Jul 10, 2006
Jul 10, 2006
225
226
227
static SDL_keysym *
TranslateKey(int vkey, int chcode, int scancode, SDL_keysym * keysym,
int iPressed)
Nov 23, 2005
Nov 23, 2005
228
{
Jul 10, 2006
Jul 10, 2006
229
230
231
keysym->scancode = (unsigned char) scancode;
keysym->mod = KMOD_NONE;
keysym->unicode = 0;
Nov 23, 2005
Nov 23, 2005
232
Jul 10, 2006
Jul 10, 2006
233
234
235
236
237
238
if (iPressed && SDL_TranslateUNICODE) {
if (chcode)
keysym->unicode = NativeCharToUniChar(chcode);
else
keysym->unicode = vkey;
}
Nov 23, 2005
Nov 23, 2005
239
Jul 10, 2006
Jul 10, 2006
240
keysym->sym = HWScanKeyMap[scancode];
Nov 23, 2005
Nov 23, 2005
241
Jul 10, 2006
Jul 10, 2006
242
243
244
245
// Now stuffs based on state of shift key(s)!
if (vkey == VK_SHIFT) {
iShiftIsPressed = iPressed;
}
Nov 23, 2005
Nov 23, 2005
246
Jul 10, 2006
Jul 10, 2006
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
if ((iShiftIsPressed) && (SDL_TranslateUNICODE)) {
// Change syms, if Unicode stuff is required
// I think it's silly, but it's SDL...
switch (keysym->sym) {
case SDLK_BACKQUOTE:
keysym->sym = '~';
break;
case SDLK_1:
keysym->sym = SDLK_EXCLAIM;
break;
case SDLK_2:
keysym->sym = SDLK_AT;
break;
case SDLK_3:
keysym->sym = SDLK_HASH;
break;
case SDLK_4:
keysym->sym = SDLK_DOLLAR;
break;
case SDLK_5:
keysym->sym = '%';
break;
case SDLK_6:
keysym->sym = SDLK_CARET;
break;
case SDLK_7:
keysym->sym = SDLK_AMPERSAND;
break;
case SDLK_8:
keysym->sym = SDLK_ASTERISK;
break;
case SDLK_9:
keysym->sym = SDLK_LEFTPAREN;
break;
case SDLK_0:
keysym->sym = SDLK_RIGHTPAREN;
break;
case SDLK_MINUS:
keysym->sym = SDLK_UNDERSCORE;
break;
case SDLK_PLUS:
keysym->sym = SDLK_EQUALS;
break;
case SDLK_LEFTBRACKET:
keysym->sym = '{';
break;
case SDLK_RIGHTBRACKET:
keysym->sym = '}';
break;
case SDLK_SEMICOLON:
keysym->sym = SDLK_COLON;
break;
case SDLK_QUOTE:
keysym->sym = SDLK_QUOTEDBL;
break;
case SDLK_BACKSLASH:
keysym->sym = '|';
break;
case SDLK_COMMA:
keysym->sym = SDLK_LESS;
break;
case SDLK_PERIOD:
keysym->sym = SDLK_GREATER;
break;
case SDLK_SLASH:
keysym->sym = SDLK_QUESTION;
break;
default:
break;
}
Nov 23, 2005
Nov 23, 2005
321
}
Jul 10, 2006
Jul 10, 2006
322
return keysym;
Nov 23, 2005
Nov 23, 2005
323
324
325
326
327
}
#define CONVERTMOUSEPOSITION() \
/* We have to inverse the mouse position, because every non-os/2 system */ \
/* has a coordinate system where the (0;0) is the top-left corner, */ \
Feb 26, 2006
Feb 26, 2006
328
329
330
331
332
333
/* while on os/2 it's the bottom left corner! */ \
if (FSLib_QueryFSMode(hwnd)) \
{ \
/* We're in FS mode! */ \
/* In FS mode our window is as big as fullscreen mode, but not necessary as */ \
/* big as the source buffer (can be bigger) */ \
Nov 23, 2005
Nov 23, 2005
334
/* So, limit mouse pos to source buffer size! */ \
Feb 26, 2006
Feb 26, 2006
335
336
337
if (ppts->x<0) ppts->x = 0; \
if (ppts->y<0) ppts->y = 0; \
if (ppts->x>=pVideo->hidden->SrcBufferDesc.uiXResolution) ppts->x = pVideo->hidden->SrcBufferDesc.uiXResolution-1; \
Nov 23, 2005
Nov 23, 2005
338
339
340
341
if (ppts->y>=pVideo->hidden->SrcBufferDesc.uiYResolution) ppts->y = pVideo->hidden->SrcBufferDesc.uiYResolution-1; \
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ \
ptl.x = ppts->x; ptl.y = ppts->y; \
WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); \
Feb 26, 2006
Feb 26, 2006
342
343
WinSetPointerPos(HWND_DESKTOP, ptl.x, ptl.y); \
/* Then convert OS/2 position to SDL position */ \
Nov 23, 2005
Nov 23, 2005
344
ppts->y = pVideo->hidden->SrcBufferDesc.uiYResolution - ppts->y - 1; \
Feb 26, 2006
Feb 26, 2006
345
346
347
} else \
{ \
SWP swpClient; \
Nov 23, 2005
Nov 23, 2005
348
/* We're in windowed mode! */ \
Feb 26, 2006
Feb 26, 2006
349
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); \
Nov 23, 2005
Nov 23, 2005
350
/* Convert OS/2 mouse position to SDL position, and also scale it! */ \
Feb 26, 2006
Feb 26, 2006
351
352
353
354
(ppts->x) = (ppts->x) * pVideo->hidden->SrcBufferDesc.uiXResolution / swpClient.cx; \
(ppts->y) = (ppts->y) * pVideo->hidden->SrcBufferDesc.uiYResolution / swpClient.cy; \
(ppts->y) = pVideo->hidden->SrcBufferDesc.uiYResolution - (ppts->y) - 1; \
}
Nov 23, 2005
Nov 23, 2005
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/////////////////////////////////////////////////////////////////////
//
// WndProc
//
// This is the message processing window procedure for the
// SDLWindowClass, which is the client window in our application.
// It handles switching back and away from the app (taking care of
// going out and back to and from fullscreen mode), sending keystrokes
// and mouse events to where it has to be sent, etc...
//
/////////////////////////////////////////////////////////////////////
Jul 10, 2006
Jul 10, 2006
369
370
static MRESULT EXPENTRY
WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
Nov 23, 2005
Nov 23, 2005
371
{
Jul 10, 2006
Jul 10, 2006
372
373
374
HPS ps;
RECTL rcl;
SDL_VideoDevice *pVideo = NULL;
Nov 23, 2005
Nov 23, 2005
375
Jul 10, 2006
Jul 10, 2006
376
377
switch (msg) {
case WM_CHAR: // Keypress notification
Nov 23, 2005
Nov 23, 2005
378
379
380
#ifdef DEBUG_BUILD
// printf("WM_CHAR\n"); fflush(stdout);
#endif
Jul 10, 2006
Jul 10, 2006
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
pVideo = WinQueryWindowPtr(hwnd, 0);
if (pVideo) {
/*
// We skip repeated keys:
if (CHARMSG(&msg)->cRepeat>1)
{
#ifdef DEBUG_BUILD
// printf("Repeated key (%d), skipping...\n", CHARMSG(&msg)->cRepeat); fflush(stdout);
#endif
return (MRESULT) TRUE;
}
*/
// If it's not repeated, then let's see if its pressed or released!
if (SHORT1FROMMP(mp1) & KC_KEYUP) {
// A key has been released
SDL_keysym keysym;
Nov 23, 2005
Nov 23, 2005
398
399
400
401
402
#ifdef DEBUG_BUILD
// printf("WM_CHAR, keyup, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code
#endif
Jul 10, 2006
Jul 10, 2006
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
// One problem is with F1, which gets only the keyup message because
// it is a system key.
// So, when we get keyup message, we simulate keydown too!
// UPDATE:
// This problem should be solved now, that the accelerator keys are
// disabled for this window!
/*
if (SHORT2FROMMP(mp2)==VK_F1)
{
SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
&keysym,0));
} */
SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
&keysym, 0));
} else {
// A key has been pressed
SDL_keysym keysym;
Nov 23, 2005
Nov 23, 2005
426
427
428
429
#ifdef DEBUG_BUILD
// printf("WM_CHAR, keydown, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code
#endif
Jul 10, 2006
Jul 10, 2006
430
431
432
433
434
435
436
437
438
439
440
441
442
// Check for fastkeys: ALT+HOME to toggle FS mode
// ALT+END to close app
if ((SHORT1FROMMP(mp1) & KC_ALT) &&
(SHORT2FROMMP(mp2) == VK_HOME)) {
#ifdef DEBUG_BUILD
printf(" Pressed ALT+HOME!\n");
fflush(stdout);
#endif
// Only switch between fullscreen and back if it's not
// a resizable mode!
if ((!pVideo->hidden->pSDLSurface) ||
((pVideo->hidden->pSDLSurface)
&&
Jan 10, 2009
Jan 10, 2009
443
444
((pVideo->hidden->
pSDLSurface->flags & SDL_RESIZABLE) == 0)))
Jul 10, 2006
Jul 10, 2006
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
FSLib_ToggleFSMode(hwnd, !FSLib_QueryFSMode(hwnd));
#ifdef DEBUG_BUILD
else
printf(" Resizable mode, so discarding ALT+HOME!\n");
fflush(stdout);
#endif
} else if ((SHORT1FROMMP(mp1) & KC_ALT) &&
(SHORT2FROMMP(mp2) == VK_END)) {
#ifdef DEBUG_BUILD
printf(" Pressed ALT+END!\n");
fflush(stdout);
#endif
// Close window, and get out of loop!
// Also send event to SDL application, but we won't
// wait for it to be processed!
SDL_PrivateQuit();
WinPostMsg(hwnd, WM_QUIT, 0, 0);
} else {
SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
&keysym,
1));
}
}
Feb 26, 2006
Feb 26, 2006
472
}
Jul 10, 2006
Jul 10, 2006
473
return (MRESULT) TRUE;
Nov 23, 2005
Nov 23, 2005
474
475
case WM_TRANSLATEACCEL:
Feb 26, 2006
Feb 26, 2006
476
{
Jul 10, 2006
Jul 10, 2006
477
478
479
480
481
482
483
484
485
486
PQMSG pqmsg;
pqmsg = (PQMSG) mp1;
if (mp1) {
if (pqmsg->msg == WM_CHAR) {
// WM_CHAR message!
// Let's filter the ALT keypress and all other acceleration keys!
return (MRESULT) FALSE;
}
}
break; // Default processing (pass to parent until frame control)
Feb 26, 2006
Feb 26, 2006
487
}
Nov 23, 2005
Nov 23, 2005
488
Jul 10, 2006
Jul 10, 2006
489
case WM_PAINT: // Window redraw!
Nov 23, 2005
Nov 23, 2005
490
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
491
492
printf("WM_PAINT (0x%x)\n", hwnd);
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
493
#endif
Jul 10, 2006
Jul 10, 2006
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
ps = WinBeginPaint(hwnd, 0, &rcl);
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo) {
if (!pVideo->hidden->pSDLSurface) {
RECTL rclRect;
// So, don't blit now!
#ifdef DEBUG_BUILD
printf("WM_PAINT : Skipping blit while resizing (Pre!)!\n");
fflush(stdout);
#endif
WinQueryWindowRect(hwnd, &rclRect);
// Fill with black
WinFillRect(ps, &rclRect, CLR_BLACK);
} else {
if (DosRequestMutexSem
(pVideo->hidden->hmtxUseSrcBuffer, 1000) == NO_ERROR) {
int iTop, iLeft, iWidth, iHeight;
int iXScaleError, iYScaleError;
int iXScaleError2, iYScaleError2;
SWP swp;
// Re-blit the modified area!
// For this, we have to calculate the points, scaled!
WinQueryWindowPos(hwnd, &swp);
#ifdef DEBUG_BUILD
printf
("WM_PAINT : WinSize: %d %d, BufSize: %d %d\n",
swp.cx, swp.cy,
pVideo->hidden->SrcBufferDesc.uiXResolution,
pVideo->hidden->SrcBufferDesc.uiYResolution);
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
525
526
527
#endif
#ifndef RESIZE_EVEN_IF_RESIZABLE
Jul 10, 2006
Jul 10, 2006
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
// But only blit if the window is not resizable, or if
// the window is resizable and the source buffer size is the
// same as the destination buffer size!
if ((!pVideo->hidden->pSDLSurface) ||
((pVideo->hidden->pSDLSurface) &&
(pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE)
&&
((swp.cx !=
pVideo->hidden->SrcBufferDesc.uiXResolution)
|| (swp.cy !=
pVideo->hidden->SrcBufferDesc.uiYResolution))
&& (!FSLib_QueryFSMode(hwnd)))) {
RECTL rclRect;
// Resizable surface and in resizing!
// So, don't blit now!
#ifdef DEBUG_BUILD
printf("WM_PAINT : Skipping blit while resizing!\n");
fflush(stdout);
#endif
WinQueryWindowRect(hwnd, &rclRect);
// Fill with black
WinFillRect(ps, &rclRect, CLR_BLACK);
} else
#endif
{
iXScaleError =
Aug 27, 2008
Aug 27, 2008
555
556
(pVideo->hidden->SrcBufferDesc.uiXResolution -
1) / swp.cx;
Jul 10, 2006
Jul 10, 2006
557
iYScaleError =
Aug 27, 2008
Aug 27, 2008
558
559
(pVideo->hidden->SrcBufferDesc.uiYResolution -
1) / swp.cy;
Jul 10, 2006
Jul 10, 2006
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
if (iXScaleError < 0)
iXScaleError = 0;
if (iYScaleError < 0)
iYScaleError = 0;
iXScaleError2 =
(swp.cx -
1) /
(pVideo->hidden->SrcBufferDesc.uiXResolution);
iYScaleError2 =
(swp.cy -
1) /
(pVideo->hidden->SrcBufferDesc.uiYResolution);
if (iXScaleError2 < 0)
iXScaleError2 = 0;
if (iYScaleError2 < 0)
iYScaleError2 = 0;
iTop =
(swp.cy -
rcl.yTop) *
Aug 27, 2008
Aug 27, 2008
580
581
pVideo->hidden->SrcBufferDesc.uiYResolution /
swp.cy - iYScaleError;
Jul 10, 2006
Jul 10, 2006
582
583
iLeft =
rcl.xLeft *
Aug 27, 2008
Aug 27, 2008
584
585
pVideo->hidden->SrcBufferDesc.uiXResolution /
swp.cx - iXScaleError;
Jul 10, 2006
Jul 10, 2006
586
587
588
iWidth =
((rcl.xRight -
rcl.xLeft) *
Aug 27, 2008
Aug 27, 2008
589
590
pVideo->hidden->SrcBufferDesc.uiXResolution +
swp.cx - 1) / swp.cx + 2 * iXScaleError;
Jul 10, 2006
Jul 10, 2006
591
592
593
iHeight =
((rcl.yTop -
rcl.yBottom) *
Aug 27, 2008
Aug 27, 2008
594
595
pVideo->hidden->SrcBufferDesc.uiYResolution +
swp.cy - 1) / swp.cy + 2 * iYScaleError;
Jul 10, 2006
Jul 10, 2006
596
597
598
599
600
601
602
603
604
605
606
iWidth += iXScaleError2;
iHeight += iYScaleError2;
if (iTop < 0)
iTop = 0;
if (iLeft < 0)
iLeft = 0;
if (iTop + iHeight >
pVideo->hidden->SrcBufferDesc.uiYResolution)
iHeight =
Aug 27, 2008
Aug 27, 2008
607
608
pVideo->hidden->SrcBufferDesc.uiYResolution -
iTop;
Jul 10, 2006
Jul 10, 2006
609
610
611
if (iLeft + iWidth >
pVideo->hidden->SrcBufferDesc.uiXResolution)
iWidth =
Aug 27, 2008
Aug 27, 2008
612
613
pVideo->hidden->SrcBufferDesc.uiXResolution -
iLeft;
Jul 10, 2006
Jul 10, 2006
614
615
616
617
618
#ifdef DEBUG_BUILD
printf
("WM_PAINT : BitBlt: %d %d -> %d %d (Buf %d x %d)\n",
iTop, iLeft, iWidth, iHeight,
Aug 27, 2008
Aug 27, 2008
619
pVideo->hidden->SrcBufferDesc.uiXResolution,
Jul 10, 2006
Jul 10, 2006
620
621
622
623
624
625
626
627
628
629
630
pVideo->hidden->SrcBufferDesc.uiYResolution);
fflush(stdout);
#endif
FSLIB_BITBLT(hwnd,
pVideo->hidden->pchSrcBuffer,
iTop, iLeft, iWidth, iHeight);
}
DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer);
}
Nov 23, 2005
Nov 23, 2005
631
632
633
}
}
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
634
635
636
637
else {
printf("WM_PAINT : No pVideo!\n");
fflush(stdout);
}
Nov 23, 2005
Nov 23, 2005
638
#endif
Jul 10, 2006
Jul 10, 2006
639
WinEndPaint(ps);
Nov 23, 2005
Nov 23, 2005
640
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
641
642
printf("WM_PAINT : Done.\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
643
#endif
Jul 10, 2006
Jul 10, 2006
644
return 0;
Nov 23, 2005
Nov 23, 2005
645
646
case WM_SIZE:
Jul 10, 2006
Jul 10, 2006
647
{
Nov 23, 2005
Nov 23, 2005
648
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
649
650
651
printf("WM_SIZE : (%d %d)\n",
SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
652
#endif
Jul 10, 2006
Jul 10, 2006
653
654
655
iWindowSizeX = SHORT1FROMMP(mp2);
iWindowSizeY = SHORT2FROMMP(mp2);
bWindowResized = 1;
Nov 23, 2005
Nov 23, 2005
656
Jul 10, 2006
Jul 10, 2006
657
658
659
660
// Make sure the window will be redrawn
WinInvalidateRegion(hwnd, NULL, TRUE);
}
break;
Nov 23, 2005
Nov 23, 2005
661
662
663
case WM_FSLIBNOTIFICATION:
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
printf("WM_FSLIBNOTIFICATION\n");
fflush(stdout);
#endif
if ((int) mp1 == FSLN_TOGGLEFSMODE) {
// FS mode changed, reblit image!
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo) {
if (!pVideo->hidden->pSDLSurface) {
// Resizable surface and in resizing!
// So, don't blit now!
#ifdef DEBUG_BUILD
printf
("WM_FSLIBNOTIFICATION : Can not blit if there is no surface, doing nothing.\n");
fflush(stdout);
#endif
} else {
if (DosRequestMutexSem
(pVideo->hidden->hmtxUseSrcBuffer,
1000) == NO_ERROR) {
if (pVideo->hidden->pSDLSurface) {
Nov 23, 2005
Nov 23, 2005
684
#ifndef RESIZE_EVEN_IF_RESIZABLE
Jul 10, 2006
Jul 10, 2006
685
686
687
688
689
690
691
692
SWP swp;
// But only blit if the window is not resizable, or if
// the window is resizable and the source buffer size is the
// same as the destination buffer size!
WinQueryWindowPos(hwnd, &swp);
if ((!pVideo->hidden->pSDLSurface) ||
((pVideo->hidden->pSDLSurface) &&
Jan 10, 2009
Jan 10, 2009
693
694
(pVideo->hidden->
pSDLSurface->flags & SDL_RESIZABLE)
Jul 10, 2006
Jul 10, 2006
695
696
&&
((swp.cx !=
Jan 10, 2009
Jan 10, 2009
697
698
pVideo->hidden->
SrcBufferDesc.uiXResolution)
Jul 10, 2006
Jul 10, 2006
699
|| (swp.cy !=
Jan 10, 2009
Jan 10, 2009
700
701
pVideo->hidden->SrcBufferDesc.
uiYResolution))
Jul 10, 2006
Jul 10, 2006
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
&& (!FSLib_QueryFSMode(hwnd)))) {
// Resizable surface and in resizing!
// So, don't blit now!
#ifdef DEBUG_BUILD
printf
("WM_FSLIBNOTIFICATION : Cannot blit while resizing, doing nothing.\n");
fflush(stdout);
#endif
} else
#endif
{
#ifdef DEBUG_BUILD
printf("WM_FSLIBNOTIFICATION : Blitting!\n");
fflush(stdout);
#endif
FSLIB_BITBLT(hwnd,
Aug 27, 2008
Aug 27, 2008
718
pVideo->hidden->pchSrcBuffer, 0,
Jul 10, 2006
Jul 10, 2006
719
0,
Jan 9, 2009
Jan 9, 2009
720
pVideo->hidden->
Jan 10, 2009
Jan 10, 2009
721
722
723
SrcBufferDesc.uiXResolution,
pVideo->hidden->SrcBufferDesc.
uiYResolution);
Jul 10, 2006
Jul 10, 2006
724
725
726
727
728
729
730
731
732
733
734
}
}
#ifdef DEBUG_BUILD
else
printf
("WM_FSLIBNOTIFICATION : No public surface!\n");
fflush(stdout);
#endif
DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer);
}
Nov 23, 2005
Nov 23, 2005
735
736
}
}
Feb 26, 2006
Feb 26, 2006
737
}
Jul 10, 2006
Jul 10, 2006
738
return (MPARAM) 1;
Nov 23, 2005
Nov 23, 2005
739
740
741
case WM_ACTIVATE:
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
742
743
printf("WM_ACTIVATE\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
744
745
#endif
Jul 10, 2006
Jul 10, 2006
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo) {
pVideo->hidden->fInFocus = (int) mp1;
if (pVideo->hidden->fInFocus) {
// Went into focus
if ((pVideo->hidden->iMouseVisible)
&& (!bMouseCaptured))
WinSetPointer(HWND_DESKTOP,
WinQuerySysPointer(HWND_DESKTOP,
SPTR_ARROW, FALSE));
else
WinSetPointer(HWND_DESKTOP, NULL);
if (bMouseCapturable) {
// Re-capture the mouse, if we captured it before!
WinSetCapture(HWND_DESKTOP, hwnd);
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
WinQueryWindowPos(pVideo->hidden->hwndClient,
&swpClient);
ptl.x = 0;
ptl.y = 0;
Aug 27, 2008
Aug 27, 2008
771
772
WinMapWindowPoints(pVideo->hidden->hwndClient,
HWND_DESKTOP, &ptl, 1);
Jul 10, 2006
Jul 10, 2006
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
}
}
} else {
// Went out of focus
WinSetPointer(HWND_DESKTOP,
WinQuerySysPointer(HWND_DESKTOP,
SPTR_ARROW, FALSE));
if (bMouseCaptured) {
// Release the mouse
WinSetCapture(HWND_DESKTOP, hwnd);
bMouseCaptured = 0;
}
Nov 23, 2005
Nov 23, 2005
790
791
792
}
}
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
793
794
printf("WM_ACTIVATE done\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
795
796
#endif
Jul 10, 2006
Jul 10, 2006
797
break;
Nov 23, 2005
Nov 23, 2005
798
799
800
case WM_BUTTON1DOWN:
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
801
802
printf("WM_BUTTON1DOWN\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
803
804
#endif
Jul 10, 2006
Jul 10, 2006
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo) {
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); // Don't report mouse movement!
if (bMouseCapturable) {
// We should capture the mouse!
if (!bMouseCaptured) {
WinSetCapture(HWND_DESKTOP, hwnd);
WinSetPointer(HWND_DESKTOP, NULL);
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
WinQueryWindowPos(pVideo->hidden->hwndClient,
&swpClient);
ptl.x = 0;
ptl.y = 0;
Aug 27, 2008
Aug 27, 2008
823
824
WinMapWindowPoints(pVideo->hidden->hwndClient,
HWND_DESKTOP, &ptl, 1);
Jul 10, 2006
Jul 10, 2006
825
826
827
828
829
830
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
}
}
Nov 23, 2005
Nov 23, 2005
831
}
Feb 26, 2006
Feb 26, 2006
832
}
Jul 10, 2006
Jul 10, 2006
833
break;
Nov 23, 2005
Nov 23, 2005
834
835
case WM_BUTTON1UP:
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
836
837
printf("WM_BUTTON1UP\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
838
#endif
Jul 10, 2006
Jul 10, 2006
839
840
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); // Don't report mouse movement!
break;
Nov 23, 2005
Nov 23, 2005
841
842
case WM_BUTTON2DOWN:
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
843
844
printf("WM_BUTTON2DOWN\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
845
846
#endif
Jul 10, 2006
Jul 10, 2006
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo) {
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); // Don't report mouse movement!
if (bMouseCapturable) {
// We should capture the mouse!
if (!bMouseCaptured) {
WinSetCapture(HWND_DESKTOP, hwnd);
WinSetPointer(HWND_DESKTOP, NULL);
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
WinQueryWindowPos(pVideo->hidden->hwndClient,
&swpClient);
ptl.x = 0;
ptl.y = 0;
Aug 27, 2008
Aug 27, 2008
865
866
WinMapWindowPoints(pVideo->hidden->hwndClient,
HWND_DESKTOP, &ptl, 1);
Jul 10, 2006
Jul 10, 2006
867
868
869
870
871
872
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
}
}
Nov 23, 2005
Nov 23, 2005
873
874
}
Jul 10, 2006
Jul 10, 2006
875
876
}
break;
Nov 23, 2005
Nov 23, 2005
877
878
case WM_BUTTON2UP:
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
879
880
printf("WM_BUTTON2UP\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
881
#endif
Jul 10, 2006
Jul 10, 2006
882
883
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); // Don't report mouse movement!
break;
Nov 23, 2005
Nov 23, 2005
884
885
case WM_BUTTON3DOWN:
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
886
887
printf("WM_BUTTON3DOWN\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
888
889
#endif
Jul 10, 2006
Jul 10, 2006
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo) {
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); // Don't report mouse movement!
if (bMouseCapturable) {
// We should capture the mouse!
if (!bMouseCaptured) {
WinSetCapture(HWND_DESKTOP, hwnd);
WinSetPointer(HWND_DESKTOP, NULL);
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
WinQueryWindowPos(pVideo->hidden->hwndClient,
&swpClient);
ptl.x = 0;
ptl.y = 0;
Aug 27, 2008
Aug 27, 2008
908
909
WinMapWindowPoints(pVideo->hidden->hwndClient,
HWND_DESKTOP, &ptl, 1);
Jul 10, 2006
Jul 10, 2006
910
911
912
913
914
915
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
}
}
Nov 23, 2005
Nov 23, 2005
916
}
Feb 26, 2006
Feb 26, 2006
917
}
Jul 10, 2006
Jul 10, 2006
918
break;
Nov 23, 2005
Nov 23, 2005
919
920
case WM_BUTTON3UP:
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
921
922
printf("WM_BUTTON3UP\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
923
#endif
Jul 10, 2006
Jul 10, 2006
924
925
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); // Don't report mouse movement!
break;
Nov 23, 2005
Nov 23, 2005
926
927
928
929
930
case WM_MOUSEMOVE:
#ifdef DEBUG_BUILD
// printf("WM_MOUSEMOVE\n"); fflush(stdout);
#endif
Jul 10, 2006
Jul 10, 2006
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo) {
if (pVideo->hidden->iSkipWMMOUSEMOVE) {
pVideo->hidden->iSkipWMMOUSEMOVE--;
} else {
POINTS *ppts = (POINTS *) (&mp1);
POINTL ptl;
if (bMouseCaptured) {
SWP swpClient;
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient);
// Send relative mouse position, and re-center the mouse
// Reposition the mouse to the center of the screen/window
SDL_PrivateMouseMotion(0, // Buttons not changed
1, // Relative position
ppts->x -
(swpClient.cx / 2),
(swpClient.cy / 2) - ppts->y);
ptl.x = 0;
ptl.y = 0;
WinMapWindowPoints(pVideo->hidden->hwndClient,
HWND_DESKTOP, &ptl, 1);
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
// Center the mouse to the middle of the window!
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
} else {
CONVERTMOUSEPOSITION();
// Send absolute mouse position
SDL_PrivateMouseMotion(0, // Buttons not changed
0, // Absolute position
ppts->x, ppts->y);
}
}
if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured)) {
Nov 23, 2005
Nov 23, 2005
971
972
973
974
#ifdef DEBUG_BUILD
// printf("WM_MOUSEMOVE : ptr = %p\n", hptrGlobalPointer); fflush(stdout);
#endif
Jul 10, 2006
Jul 10, 2006
975
976
977
978
979
980
981
982
983
if (hptrGlobalPointer)
WinSetPointer(HWND_DESKTOP, hptrGlobalPointer);
else
WinSetPointer(HWND_DESKTOP,
WinQuerySysPointer(HWND_DESKTOP,
SPTR_ARROW, FALSE));
} else {
WinSetPointer(HWND_DESKTOP, NULL);
}
Nov 23, 2005
Nov 23, 2005
984
985
986
987
988
}
#ifdef DEBUG_BUILD
// printf("WM_MOUSEMOVE done\n"); fflush(stdout);
#endif
Jul 10, 2006
Jul 10, 2006
989
990
return (MRESULT) FALSE;
case WM_CLOSE: // Window close
Nov 23, 2005
Nov 23, 2005
991
#ifdef DEBUG_BUILD
Jul 10, 2006
Jul 10, 2006
992
993
printf("WM_CLOSE\n");
fflush(stdout);
Nov 23, 2005
Nov 23, 2005
994
995
#endif
Jul 10, 2006
Jul 10, 2006
996
997
998
999
1000
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo) {
// Send Quit message to the SDL application!
SDL_PrivateQuit();
return 0;