Mercurial > sdl-ios-xcode
annotate src/video/windx5/SDL_dx5events.c @ 327:13fc64213765
*** empty log message ***
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 31 Mar 2002 03:34:16 +0000 |
parents | 1b5457c0a8ad |
children | 3d6dd1b7b7ba |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
290
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 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 | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* CAUTION!!!! If you modify this file, check ../windib/SDL_sysevents.c */ | |
29 | |
30 #include "directx.h" | |
31 | |
32 #include <stdio.h> | |
33 #include "SDL_events.h" | |
34 #include "SDL_video.h" | |
35 #include "SDL_error.h" | |
36 #include "SDL_syswm.h" | |
37 #include "SDL_sysevents.h" | |
38 #include "SDL_events_c.h" | |
39 #include "SDL_lowvideo.h" | |
40 #include "SDL_dx5video.h" | |
41 | |
42 #ifndef WM_APP | |
43 #define WM_APP 0x8000 | |
44 #endif | |
45 | |
46 /* The keyboard and mouse device input */ | |
47 #define MAX_INPUTS 16 /* Maximum of 16-1 input devices */ | |
48 #define INPUT_QSIZE 32 /* Buffer up to 32 input messages */ | |
49 | |
50 static LPDIRECTINPUT dinput = NULL; | |
51 static LPDIRECTINPUTDEVICE2 SDL_DIdev[MAX_INPUTS]; | |
52 static HANDLE SDL_DIevt[MAX_INPUTS]; | |
53 static void (*SDL_DIfun[MAX_INPUTS])(const int, DIDEVICEOBJECTDATA *); | |
54 static int SDL_DIndev = 0; | |
55 static int mouse_lost; | |
56 static int mouse_pressed; | |
57 | |
58 /* The translation table from a DirectInput scancode to an SDL keysym */ | |
59 static SDLKey DIK_keymap[256]; | |
60 static SDL_keysym *TranslateKey(UINT scancode, SDL_keysym *keysym, int pressed); | |
61 | |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
62 /* DJM: If the user setup the window for us, we want to save his window proc, |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
63 and give him a chance to handle some messages. */ |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
64 static WNDPROC userWindowProc = NULL; |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
65 |
0 | 66 /* Convert a DirectInput return code to a text message */ |
67 static void SetDIerror(char *function, int code) | |
68 { | |
69 static char *error; | |
70 static char errbuf[BUFSIZ]; | |
71 | |
72 errbuf[0] = 0; | |
73 switch (code) { | |
74 case DIERR_GENERIC: | |
75 error = "Undefined error!"; | |
76 break; | |
77 case DIERR_OLDDIRECTINPUTVERSION: | |
78 error = "Your version of DirectInput needs upgrading"; | |
79 break; | |
80 case DIERR_INVALIDPARAM: | |
81 error = "Invalid parameters"; | |
82 break; | |
83 case DIERR_OUTOFMEMORY: | |
84 error = "Out of memory"; | |
85 break; | |
86 case DIERR_DEVICENOTREG: | |
87 error = "Device not registered"; | |
88 break; | |
89 case DIERR_NOINTERFACE: | |
90 error = "Interface not supported"; | |
91 break; | |
92 case DIERR_NOTINITIALIZED: | |
93 error = "Device not initialized"; | |
94 break; | |
95 default: | |
96 sprintf(errbuf, "%s: Unknown DirectInput error: 0x%x", | |
97 function, code); | |
98 break; | |
99 } | |
100 if ( ! errbuf[0] ) { | |
101 sprintf(errbuf, "%s: %s", function, error); | |
102 } | |
103 SDL_SetError("%s", errbuf); | |
104 return; | |
105 } | |
106 | |
107 /* Initialize DirectInput | |
108 Note: If NONEXCLUSIVE access is requested for the devices, normal | |
109 windows input messages will continue to be generated for that | |
110 input device, in addition to DirectInput messages. | |
111 */ | |
112 static void handle_keyboard(const int numevents, DIDEVICEOBJECTDATA *events); | |
113 static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *events); | |
114 struct { | |
115 char *name; | |
116 REFGUID guid; | |
117 LPCDIDATAFORMAT format; | |
118 DWORD win_level; | |
119 DWORD raw_level; | |
120 void (*fun)(const int numevents, DIDEVICEOBJECTDATA *events); | |
121 } inputs[] = { | |
122 { "keyboard", | |
123 &GUID_SysKeyboard, &c_dfDIKeyboard, | |
124 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), | |
125 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), handle_keyboard }, | |
126 { "mouse", | |
127 &GUID_SysMouse, &c_dfDIMouse, | |
128 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), | |
129 (DISCL_FOREGROUND|DISCL_EXCLUSIVE), handle_mouse }, | |
130 { NULL, NULL, NULL, 0, 0, NULL } | |
131 }; | |
132 | |
133 static int DX5_DInputInit(_THIS) | |
134 { | |
135 int i; | |
136 LPDIRECTINPUTDEVICE device; | |
137 HRESULT result; | |
138 DIPROPDWORD dipdw; | |
139 | |
140 /* Create the DirectInput object */ | |
141 result = DInputCreate(SDL_Instance, DIRECTINPUT_VERSION, | |
142 &dinput, NULL); | |
143 if ( result != DI_OK ) { | |
144 SetDIerror("DirectInputCreate", result); | |
145 return(-1); | |
146 } | |
147 | |
148 /* Create all of our registered input devices */ | |
149 SDL_DIndev = 0; | |
150 for ( i=0; inputs[i].name; ++i ) { | |
151 /* Create the DirectInput device */ | |
152 result = IDirectInput_CreateDevice(dinput, inputs[i].guid, | |
153 &device, NULL); | |
154 if ( result != DI_OK ) { | |
155 SetDIerror("DirectInput::CreateDevice", result); | |
156 return(-1); | |
157 } | |
158 result = IDirectInputDevice_QueryInterface(device, | |
159 &IID_IDirectInputDevice2, (LPVOID *)&SDL_DIdev[i]); | |
160 IDirectInputDevice_Release(device); | |
161 if ( result != DI_OK ) { | |
162 SetDIerror("DirectInputDevice::QueryInterface", result); | |
163 return(-1); | |
164 } | |
165 result = IDirectInputDevice2_SetCooperativeLevel(SDL_DIdev[i], | |
166 SDL_Window, inputs[i].win_level); | |
167 if ( result != DI_OK ) { | |
168 SetDIerror("DirectInputDevice::SetCooperativeLevel", | |
169 result); | |
170 return(-1); | |
171 } | |
172 result = IDirectInputDevice2_SetDataFormat(SDL_DIdev[i], | |
173 inputs[i].format); | |
174 if ( result != DI_OK ) { | |
175 SetDIerror("DirectInputDevice::SetDataFormat", result); | |
176 return(-1); | |
177 } | |
178 | |
179 /* Set buffered input -- we aren't polling */ | |
180 memset(&dipdw, 0, sizeof(dipdw)); | |
181 dipdw.diph.dwSize = sizeof(dipdw); | |
182 dipdw.diph.dwHeaderSize = sizeof(dipdw.diph); | |
183 dipdw.diph.dwObj = 0; | |
184 dipdw.diph.dwHow = DIPH_DEVICE; | |
185 dipdw.dwData = INPUT_QSIZE; | |
186 result = IDirectInputDevice2_SetProperty(SDL_DIdev[i], | |
187 DIPROP_BUFFERSIZE, &dipdw.diph); | |
188 if ( result != DI_OK ) { | |
189 SetDIerror("DirectInputDevice::SetProperty", result); | |
190 return(-1); | |
191 } | |
192 | |
193 /* Create an event to be signaled when input is ready */ | |
194 SDL_DIevt[i] = CreateEvent(NULL, FALSE, FALSE, NULL); | |
195 if ( SDL_DIevt[i] == NULL ) { | |
196 SDL_SetError("Couldn't create DirectInput event"); | |
197 return(-1); | |
198 } | |
199 result = IDirectInputDevice2_SetEventNotification(SDL_DIdev[i], | |
200 SDL_DIevt[i]); | |
201 if ( result != DI_OK ) { | |
202 SetDIerror("DirectInputDevice::SetEventNotification", | |
203 result); | |
204 return(-1); | |
205 } | |
206 SDL_DIfun[i] = inputs[i].fun; | |
207 | |
208 /* Acquire the device for input */ | |
209 IDirectInputDevice2_Acquire(SDL_DIdev[i]); | |
210 | |
211 /* Increment the number of devices we have */ | |
212 ++SDL_DIndev; | |
213 } | |
214 mouse_pressed = 0; | |
215 | |
216 /* DirectInput is ready! */ | |
217 return(0); | |
218 } | |
219 | |
220 /* Change cooperative level based on whether or not we are fullscreen */ | |
221 void DX5_DInputReset(_THIS, int fullscreen) | |
222 { | |
223 DWORD level; | |
224 int i; | |
225 HRESULT result; | |
226 | |
227 for ( i=0; i<MAX_INPUTS; ++i ) { | |
228 if ( SDL_DIdev[i] != NULL ) { | |
229 if ( fullscreen ) { | |
230 level = inputs[i].raw_level; | |
231 } else { | |
232 level = inputs[i].win_level; | |
233 } | |
234 IDirectInputDevice2_Unacquire(SDL_DIdev[i]); | |
235 result = IDirectInputDevice2_SetCooperativeLevel( | |
236 SDL_DIdev[i], SDL_Window, level); | |
237 IDirectInputDevice2_Acquire(SDL_DIdev[i]); | |
238 if ( result != DI_OK ) { | |
239 SetDIerror( | |
240 "DirectInputDevice::SetCooperativeLevel", result); | |
241 } | |
242 } | |
243 } | |
244 mouse_lost = 1; | |
245 } | |
246 | |
247 /* Clean up DirectInput */ | |
248 static void DX5_DInputQuit(_THIS) | |
249 { | |
250 int i; | |
251 | |
252 if ( dinput != NULL ) { | |
253 /* Close and release all DirectInput devices */ | |
254 for ( i=0; i<MAX_INPUTS; ++i ) { | |
255 if ( SDL_DIdev[i] != NULL ) { | |
256 IDirectInputDevice2_Unacquire(SDL_DIdev[i]); | |
257 IDirectInputDevice2_SetEventNotification( | |
258 SDL_DIdev[i], NULL); | |
259 if ( SDL_DIevt[i] != NULL ) { | |
260 CloseHandle(SDL_DIevt[i]); | |
261 SDL_DIevt[i] = NULL; | |
262 } | |
263 IDirectInputDevice2_Release(SDL_DIdev[i]); | |
264 SDL_DIdev[i] = NULL; | |
265 } | |
266 } | |
267 /* Release DirectInput */ | |
268 IDirectInput_Release(dinput); | |
269 dinput = NULL; | |
270 } | |
271 } | |
272 | |
273 /* Flag to tell SDL whether or not we queued an event */ | |
274 static int posted = 0; | |
275 | |
276 /* Input event handler functions */ | |
277 static void handle_keyboard(const int numevents, DIDEVICEOBJECTDATA *keybuf) | |
278 { | |
279 int i; | |
280 SDL_keysym keysym; | |
281 | |
282 /* Translate keyboard messages */ | |
283 for ( i=0; i<numevents; ++i ) { | |
284 if ( keybuf[i].dwData & 0x80 ) { | |
285 posted = SDL_PrivateKeyboard(SDL_PRESSED, | |
286 TranslateKey(keybuf[i].dwOfs, &keysym, 1)); | |
287 } else { | |
288 posted = SDL_PrivateKeyboard(SDL_RELEASED, | |
289 TranslateKey(keybuf[i].dwOfs, &keysym, 0)); | |
290 } | |
291 } | |
292 } | |
293 static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *ptrbuf) | |
294 { | |
295 int i; | |
296 Sint16 xrel, yrel; | |
297 Uint8 state; | |
298 Uint8 button; | |
299 | |
300 /* If we are in windowed mode, Windows is taking care of the mouse */ | |
325
1b5457c0a8ad
Fixed the bug where mouse cursor and SDL mouse coordinates didn't match
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
301 if ( (SDL_PublicSurface->flags & SDL_OPENGL) || |
1b5457c0a8ad
Fixed the bug where mouse cursor and SDL mouse coordinates didn't match
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
302 !(SDL_PublicSurface->flags & SDL_FULLSCREEN) ) { |
0 | 303 return; |
304 } | |
305 | |
306 /* If the mouse was lost, regain some sense of mouse state */ | |
307 if ( mouse_lost ) { | |
308 POINT mouse_pos; | |
309 Uint8 old_state; | |
310 Uint8 new_state; | |
311 | |
312 /* Set ourselves up with the current cursor position */ | |
313 GetCursorPos(&mouse_pos); | |
314 ScreenToClient(SDL_Window, &mouse_pos); | |
315 posted = SDL_PrivateMouseMotion(0, 0, | |
316 (Sint16)mouse_pos.x, (Sint16)mouse_pos.y); | |
317 | |
318 /* Check for mouse button changes */ | |
319 old_state = SDL_GetMouseState(NULL, NULL); | |
320 new_state = 0; | |
321 { /* Get the new DirectInput button state for the mouse */ | |
322 DIMOUSESTATE distate; | |
323 HRESULT result; | |
324 | |
325 result=IDirectInputDevice2_GetDeviceState(SDL_DIdev[1], | |
326 sizeof(distate), &distate); | |
327 if ( result != DI_OK ) { | |
328 /* Try again next time */ | |
329 SetDIerror( | |
330 "IDirectInputDevice2::GetDeviceState", result); | |
331 return; | |
332 } | |
333 for ( i=3; i>=0; --i ) { | |
334 if ( (distate.rgbButtons[i]&0x80) == 0x80 ) { | |
335 new_state |= 0x01; | |
336 } | |
337 new_state <<= 1; | |
338 } | |
339 } | |
340 for ( i=0; i<8; ++i ) { | |
341 if ( (old_state&0x01) != (new_state&0x01) ) { | |
342 button = (Uint8)(i+1); | |
343 /* Button #2 on two button mice is button 3 | |
344 (the middle button is button 2) | |
345 */ | |
346 if ( button == 2 ) { | |
347 button = 3; | |
348 } else | |
349 if ( button == 3 ) { | |
350 button = 2; | |
351 } | |
352 if ( new_state & 0x01 ) { | |
353 /* Grab mouse so we get mouse-up */ | |
354 if ( ++mouse_pressed > 0 ) { | |
355 SetCapture(SDL_Window); | |
356 } | |
357 state = SDL_PRESSED; | |
358 } else { | |
359 /* Release mouse after all mouse-ups */ | |
360 if ( --mouse_pressed <= 0 ) { | |
361 ReleaseCapture(); | |
362 mouse_pressed = 0; | |
363 } | |
364 state = SDL_RELEASED; | |
365 } | |
366 posted = SDL_PrivateMouseButton(state, button, | |
367 0, 0); | |
368 } | |
369 old_state >>= 1; | |
370 new_state >>= 1; | |
371 } | |
372 mouse_lost = 0; | |
373 return; | |
374 } | |
375 | |
376 /* Translate mouse messages */ | |
377 xrel = 0; | |
378 yrel = 0; | |
379 for ( i=0; i<(int)numevents; ++i ) { | |
380 switch (ptrbuf[i].dwOfs) { | |
381 case DIMOFS_X: | |
382 xrel += (Sint16)ptrbuf[i].dwData; | |
383 break; | |
384 case DIMOFS_Y: | |
385 yrel += (Sint16)ptrbuf[i].dwData; | |
386 break; | |
61
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
387 case DIMOFS_Z: |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
388 if ( xrel || yrel ) { |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
389 posted = SDL_PrivateMouseMotion( |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
390 0, 1, xrel, yrel); |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
391 xrel = 0; |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
392 yrel = 0; |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
393 } |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
394 if((int)ptrbuf[i].dwData > 0) |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
395 posted = SDL_PrivateMouseButton( |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
396 SDL_PRESSED, 4, 0, 0); |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
397 else if((int)ptrbuf[i].dwData < 0) |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
398 posted = SDL_PrivateMouseButton( |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
399 SDL_PRESSED, 5, 0, 0); |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
400 break; |
0 | 401 case DIMOFS_BUTTON0: |
402 case DIMOFS_BUTTON1: | |
403 case DIMOFS_BUTTON2: | |
404 case DIMOFS_BUTTON3: | |
405 if ( xrel || yrel ) { | |
406 posted = SDL_PrivateMouseMotion( | |
407 0, 1, xrel, yrel); | |
408 xrel = 0; | |
409 yrel = 0; | |
410 } | |
411 button = (Uint8)(ptrbuf[i].dwOfs-DIMOFS_BUTTON0)+1; | |
412 /* Button #2 on two button mice is button 3 | |
413 (the middle button is button 2) | |
414 */ | |
415 if ( button == 2 ) { | |
416 button = 3; | |
417 } else | |
418 if ( button == 3 ) { | |
419 button = 2; | |
420 } | |
421 if ( ptrbuf[i].dwData & 0x80 ) { | |
422 /* Grab mouse so we get mouse-up */ | |
423 if ( ++mouse_pressed > 0 ) { | |
424 SetCapture(SDL_Window); | |
425 } | |
426 state = SDL_PRESSED; | |
427 } else { | |
428 /* Release mouse after all mouse-ups */ | |
429 if ( --mouse_pressed <= 0 ) { | |
430 ReleaseCapture(); | |
431 mouse_pressed = 0; | |
432 } | |
433 state = SDL_RELEASED; | |
434 } | |
435 posted = SDL_PrivateMouseButton(state, button, | |
436 0, 0); | |
437 break; | |
438 } | |
439 } | |
440 if ( xrel || yrel ) { | |
441 posted = SDL_PrivateMouseMotion( 0, 1, xrel, yrel); | |
442 } | |
443 } | |
444 | |
445 /* The main Win32 event handler */ | |
446 LONG | |
447 DX5_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |
448 { | |
449 switch (msg) { | |
450 case WM_ACTIVATEAPP: { | |
451 int i, active; | |
452 | |
453 active = (wParam && (GetForegroundWindow() == hwnd)); | |
454 if ( active ) { | |
455 for ( i=0; SDL_DIdev[i]; ++i ) { | |
456 IDirectInputDevice2_Acquire( | |
457 SDL_DIdev[i]); | |
458 } | |
459 } else { | |
460 for ( i=0; SDL_DIdev[i]; ++i ) { | |
461 IDirectInputDevice2_Unacquire( | |
462 SDL_DIdev[i]); | |
463 } | |
464 mouse_lost = 1; | |
465 } | |
466 } | |
467 break; | |
468 | |
469 case WM_DISPLAYCHANGE: { | |
470 WORD BitsPerPixel; | |
471 WORD SizeX, SizeY; | |
472 | |
473 /* Ack! The display changed size and/or depth! */ | |
474 SizeX = LOWORD(lParam); | |
475 SizeY = HIWORD(lParam); | |
476 BitsPerPixel = wParam; | |
477 /* We cause this message when we go fullscreen */ | |
478 } | |
479 break; | |
480 | |
481 /* The keyboard is handled via DirectInput */ | |
482 case WM_SYSKEYUP: | |
483 case WM_SYSKEYDOWN: | |
484 case WM_KEYUP: | |
485 case WM_KEYDOWN: { | |
486 /* Ignore windows keyboard messages */; | |
487 } | |
488 return(0); | |
489 | |
490 /* Don't allow screen savers or monitor power downs. | |
491 This is because they quietly clear DirectX surfaces. | |
492 It would be better to allow the application to | |
493 decide whether or not to blow these off, but the | |
494 semantics of SDL_PrivateSysWMEvent() don't allow | |
495 the application that choice. | |
496 */ | |
497 case WM_SYSCOMMAND: { | |
498 if ((wParam&0xFFF0)==SC_SCREENSAVE || | |
499 (wParam&0xFFF0)==SC_MONITORPOWER) | |
500 return(0); | |
501 } | |
502 goto custom_processing; | |
503 break; | |
504 | |
505 default: { | |
506 custom_processing: | |
507 /* Only post the event if we're watching for it */ | |
508 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { | |
509 SDL_SysWMmsg wmmsg; | |
510 | |
511 SDL_VERSION(&wmmsg.version); | |
512 wmmsg.hwnd = hwnd; | |
513 wmmsg.msg = msg; | |
514 wmmsg.wParam = wParam; | |
515 wmmsg.lParam = lParam; | |
516 posted = SDL_PrivateSysWMEvent(&wmmsg); | |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
517 |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
518 /* DJM: If the user isn't watching for private messages in her |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
519 SDL event loop, then pass it along to any win32 specific |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
520 window proc. |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
521 */ |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
522 } else if (userWindowProc) { |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
523 return userWindowProc(hwnd, msg, wParam, lParam); |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
524 } |
0 | 525 } |
526 break; | |
527 } | |
528 return(DefWindowProc(hwnd, msg, wParam, lParam)); | |
529 } | |
530 | |
531 /* This function checks the windows message queue and DirectInput and returns | |
532 1 if there was input, 0 if there was no input, or -1 if the application has | |
533 posted a quit message. | |
534 */ | |
535 static int DX5_CheckInput(_THIS, int timeout) | |
536 { | |
537 MSG msg; | |
538 int i; | |
539 HRESULT result; | |
540 DWORD event; | |
541 | |
542 /* Check the normal windows queue (highest preference) */ | |
543 posted = 0; | |
544 while ( ! posted && | |
545 PeekMessage(&msg, NULL, 0, (WM_APP-1), PM_NOREMOVE) ) { | |
546 if ( GetMessage(&msg, NULL, 0, (WM_APP-1)) > 0 ) { | |
547 DispatchMessage(&msg); | |
548 } else { | |
549 return(-1); | |
550 } | |
551 } | |
552 if ( posted ) { | |
553 return(1); | |
554 } | |
555 | |
556 /* Pump the DirectInput flow */ | |
557 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
558 for ( i=0; i<SDL_DIndev; ++i ) { | |
559 result = IDirectInputDevice2_Poll(SDL_DIdev[i]); | |
560 if ( (result == DIERR_INPUTLOST) || | |
561 (result == DIERR_NOTACQUIRED) ) { | |
562 if ( strcmp(inputs[i].name, "mouse") == 0 ) { | |
563 mouse_lost = 1; | |
564 } | |
565 IDirectInputDevice2_Acquire(SDL_DIdev[i]); | |
566 IDirectInputDevice2_Poll(SDL_DIdev[i]); | |
567 } | |
568 } | |
569 } | |
570 | |
571 /* Wait for messages and input events */ | |
572 event = MsgWaitForMultipleObjects(SDL_DIndev, SDL_DIevt, FALSE, | |
573 timeout, QS_ALLEVENTS); | |
574 if ((event >= WAIT_OBJECT_0) && (event < (WAIT_OBJECT_0+SDL_DIndev))) { | |
575 DWORD numevents; | |
576 DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; | |
577 | |
578 event -= WAIT_OBJECT_0; | |
579 numevents = INPUT_QSIZE; | |
580 result = IDirectInputDevice2_GetDeviceData( | |
581 SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), | |
582 evtbuf, &numevents, 0); | |
583 if ( (result == DIERR_INPUTLOST) || | |
584 (result == DIERR_NOTACQUIRED) ) { | |
585 if ( strcmp(inputs[event].name, "mouse") == 0 ) { | |
586 mouse_lost = 1; | |
587 } | |
588 IDirectInputDevice2_Acquire(SDL_DIdev[event]); | |
589 result = IDirectInputDevice2_GetDeviceData( | |
590 SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), | |
591 evtbuf, &numevents, 0); | |
592 } | |
593 /* Handle the events */ | |
594 if ( result == DI_OK ) { | |
595 /* Note: This can post multiple events to event queue | |
596 */ | |
597 (*SDL_DIfun[event])((int)numevents, evtbuf); | |
598 return(1); | |
599 } | |
600 } | |
601 if ( event != WAIT_TIMEOUT ) { | |
602 /* Maybe there was a windows message? */ | |
603 if ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { | |
604 if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { | |
605 DispatchMessage(&msg); | |
606 } else { | |
607 return(-1); | |
608 } | |
609 return(1); | |
610 } | |
611 } | |
612 return(0); | |
613 } | |
614 | |
615 void DX5_PumpEvents(_THIS) | |
616 { | |
617 /* Wait for messages and DirectInput */ | |
618 while ( DX5_CheckInput(this, 0) > 0 ) { | |
619 /* Loop and check again */; | |
620 } | |
621 } | |
622 | |
623 void DX5_InitOSKeymap(_THIS) | |
624 { | |
275
53fc686e9428
Added support for the pause key under DirectX
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
625 #ifndef DIK_PAUSE |
53fc686e9428
Added support for the pause key under DirectX
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
626 #define DIK_PAUSE 0xC5 |
53fc686e9428
Added support for the pause key under DirectX
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
627 #endif |
327
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
628 #ifndef DIK_OEM_102 |
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
629 #define DIK_OEM_102 0x56 /* < > | on UK/Germany keyboards */ |
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
630 #endif |
0 | 631 int i; |
632 | |
633 /* Map the DIK scancodes to SDL keysyms */ | |
634 for ( i=0; i<SDL_TABLESIZE(DIK_keymap); ++i ) | |
635 DIK_keymap[i] = 0; | |
636 | |
637 /* Defined DIK_* constants */ | |
638 DIK_keymap[DIK_ESCAPE] = SDLK_ESCAPE; | |
639 DIK_keymap[DIK_1] = SDLK_1; | |
640 DIK_keymap[DIK_2] = SDLK_2; | |
641 DIK_keymap[DIK_3] = SDLK_3; | |
642 DIK_keymap[DIK_4] = SDLK_4; | |
643 DIK_keymap[DIK_5] = SDLK_5; | |
644 DIK_keymap[DIK_6] = SDLK_6; | |
645 DIK_keymap[DIK_7] = SDLK_7; | |
646 DIK_keymap[DIK_8] = SDLK_8; | |
647 DIK_keymap[DIK_9] = SDLK_9; | |
648 DIK_keymap[DIK_0] = SDLK_0; | |
649 DIK_keymap[DIK_MINUS] = SDLK_MINUS; | |
650 DIK_keymap[DIK_EQUALS] = SDLK_EQUALS; | |
651 DIK_keymap[DIK_BACK] = SDLK_BACKSPACE; | |
652 DIK_keymap[DIK_TAB] = SDLK_TAB; | |
653 DIK_keymap[DIK_Q] = SDLK_q; | |
654 DIK_keymap[DIK_W] = SDLK_w; | |
655 DIK_keymap[DIK_E] = SDLK_e; | |
656 DIK_keymap[DIK_R] = SDLK_r; | |
657 DIK_keymap[DIK_T] = SDLK_t; | |
658 DIK_keymap[DIK_Y] = SDLK_y; | |
659 DIK_keymap[DIK_U] = SDLK_u; | |
660 DIK_keymap[DIK_I] = SDLK_i; | |
661 DIK_keymap[DIK_O] = SDLK_o; | |
662 DIK_keymap[DIK_P] = SDLK_p; | |
663 DIK_keymap[DIK_LBRACKET] = SDLK_LEFTBRACKET; | |
664 DIK_keymap[DIK_RBRACKET] = SDLK_RIGHTBRACKET; | |
665 DIK_keymap[DIK_RETURN] = SDLK_RETURN; | |
666 DIK_keymap[DIK_LCONTROL] = SDLK_LCTRL; | |
667 DIK_keymap[DIK_A] = SDLK_a; | |
668 DIK_keymap[DIK_S] = SDLK_s; | |
669 DIK_keymap[DIK_D] = SDLK_d; | |
670 DIK_keymap[DIK_F] = SDLK_f; | |
671 DIK_keymap[DIK_G] = SDLK_g; | |
672 DIK_keymap[DIK_H] = SDLK_h; | |
673 DIK_keymap[DIK_J] = SDLK_j; | |
674 DIK_keymap[DIK_K] = SDLK_k; | |
675 DIK_keymap[DIK_L] = SDLK_l; | |
676 DIK_keymap[DIK_SEMICOLON] = SDLK_SEMICOLON; | |
677 DIK_keymap[DIK_APOSTROPHE] = SDLK_QUOTE; | |
678 DIK_keymap[DIK_GRAVE] = SDLK_BACKQUOTE; | |
679 DIK_keymap[DIK_LSHIFT] = SDLK_LSHIFT; | |
680 DIK_keymap[DIK_BACKSLASH] = SDLK_BACKSLASH; | |
327
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
681 DIK_keymap[DIK_OEM_102] = SDLK_BACKSLASH; |
0 | 682 DIK_keymap[DIK_Z] = SDLK_z; |
683 DIK_keymap[DIK_X] = SDLK_x; | |
684 DIK_keymap[DIK_C] = SDLK_c; | |
685 DIK_keymap[DIK_V] = SDLK_v; | |
686 DIK_keymap[DIK_B] = SDLK_b; | |
687 DIK_keymap[DIK_N] = SDLK_n; | |
688 DIK_keymap[DIK_M] = SDLK_m; | |
689 DIK_keymap[DIK_COMMA] = SDLK_COMMA; | |
690 DIK_keymap[DIK_PERIOD] = SDLK_PERIOD; | |
691 DIK_keymap[DIK_SLASH] = SDLK_SLASH; | |
692 DIK_keymap[DIK_RSHIFT] = SDLK_RSHIFT; | |
693 DIK_keymap[DIK_MULTIPLY] = SDLK_KP_MULTIPLY; | |
694 DIK_keymap[DIK_LMENU] = SDLK_LALT; | |
695 DIK_keymap[DIK_SPACE] = SDLK_SPACE; | |
696 DIK_keymap[DIK_CAPITAL] = SDLK_CAPSLOCK; | |
697 DIK_keymap[DIK_F1] = SDLK_F1; | |
698 DIK_keymap[DIK_F2] = SDLK_F2; | |
699 DIK_keymap[DIK_F3] = SDLK_F3; | |
700 DIK_keymap[DIK_F4] = SDLK_F4; | |
701 DIK_keymap[DIK_F5] = SDLK_F5; | |
702 DIK_keymap[DIK_F6] = SDLK_F6; | |
703 DIK_keymap[DIK_F7] = SDLK_F7; | |
704 DIK_keymap[DIK_F8] = SDLK_F8; | |
705 DIK_keymap[DIK_F9] = SDLK_F9; | |
706 DIK_keymap[DIK_F10] = SDLK_F10; | |
707 DIK_keymap[DIK_NUMLOCK] = SDLK_NUMLOCK; | |
708 DIK_keymap[DIK_SCROLL] = SDLK_SCROLLOCK; | |
709 DIK_keymap[DIK_NUMPAD7] = SDLK_KP7; | |
710 DIK_keymap[DIK_NUMPAD8] = SDLK_KP8; | |
711 DIK_keymap[DIK_NUMPAD9] = SDLK_KP9; | |
712 DIK_keymap[DIK_SUBTRACT] = SDLK_KP_MINUS; | |
713 DIK_keymap[DIK_NUMPAD4] = SDLK_KP4; | |
714 DIK_keymap[DIK_NUMPAD5] = SDLK_KP5; | |
715 DIK_keymap[DIK_NUMPAD6] = SDLK_KP6; | |
716 DIK_keymap[DIK_ADD] = SDLK_KP_PLUS; | |
717 DIK_keymap[DIK_NUMPAD1] = SDLK_KP1; | |
718 DIK_keymap[DIK_NUMPAD2] = SDLK_KP2; | |
719 DIK_keymap[DIK_NUMPAD3] = SDLK_KP3; | |
720 DIK_keymap[DIK_NUMPAD0] = SDLK_KP0; | |
721 DIK_keymap[DIK_DECIMAL] = SDLK_KP_PERIOD; | |
722 DIK_keymap[DIK_F11] = SDLK_F11; | |
723 DIK_keymap[DIK_F12] = SDLK_F12; | |
724 | |
725 DIK_keymap[DIK_F13] = SDLK_F13; | |
726 DIK_keymap[DIK_F14] = SDLK_F14; | |
727 DIK_keymap[DIK_F15] = SDLK_F15; | |
728 | |
729 DIK_keymap[DIK_NUMPADEQUALS] = SDLK_KP_EQUALS; | |
730 DIK_keymap[DIK_NUMPADENTER] = SDLK_KP_ENTER; | |
731 DIK_keymap[DIK_RCONTROL] = SDLK_RCTRL; | |
732 DIK_keymap[DIK_DIVIDE] = SDLK_KP_DIVIDE; | |
733 DIK_keymap[DIK_SYSRQ] = SDLK_SYSREQ; | |
734 DIK_keymap[DIK_RMENU] = SDLK_RALT; | |
290
9a02597bc1b0
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
275
diff
changeset
|
735 DIK_keymap[DIK_PAUSE] = SDLK_PAUSE; |
0 | 736 DIK_keymap[DIK_HOME] = SDLK_HOME; |
737 DIK_keymap[DIK_UP] = SDLK_UP; | |
738 DIK_keymap[DIK_PRIOR] = SDLK_PAGEUP; | |
739 DIK_keymap[DIK_LEFT] = SDLK_LEFT; | |
740 DIK_keymap[DIK_RIGHT] = SDLK_RIGHT; | |
741 DIK_keymap[DIK_END] = SDLK_END; | |
742 DIK_keymap[DIK_DOWN] = SDLK_DOWN; | |
743 DIK_keymap[DIK_NEXT] = SDLK_PAGEDOWN; | |
744 DIK_keymap[DIK_INSERT] = SDLK_INSERT; | |
745 DIK_keymap[DIK_DELETE] = SDLK_DELETE; | |
746 DIK_keymap[DIK_LWIN] = SDLK_LMETA; | |
747 DIK_keymap[DIK_RWIN] = SDLK_RMETA; | |
748 DIK_keymap[DIK_APPS] = SDLK_MENU; | |
749 } | |
750 | |
751 static SDL_keysym *TranslateKey(UINT scancode, SDL_keysym *keysym, int pressed) | |
752 { | |
753 /* Set the keysym information */ | |
754 keysym->scancode = (unsigned char)scancode; | |
755 keysym->sym = DIK_keymap[scancode]; | |
756 keysym->mod = KMOD_NONE; | |
757 keysym->unicode = 0; | |
758 if ( pressed && SDL_TranslateUNICODE ) { /* Someday use ToUnicode() */ | |
759 UINT vkey; | |
760 BYTE keystate[256]; | |
761 BYTE chars[2]; | |
762 | |
763 vkey = MapVirtualKey(scancode, 1); | |
764 GetKeyboardState(keystate); | |
765 if ( ToAscii(vkey,scancode,keystate,(WORD *)chars,0) == 1 ) { | |
766 keysym->unicode = chars[0]; | |
767 } | |
768 } | |
769 return(keysym); | |
770 } | |
771 | |
772 int DX5_CreateWindow(_THIS) | |
773 { | |
774 int i; | |
775 | |
776 /* Clear out DirectInput variables in case we fail */ | |
777 for ( i=0; i<MAX_INPUTS; ++i ) { | |
778 SDL_DIdev[i] = NULL; | |
779 SDL_DIevt[i] = NULL; | |
780 SDL_DIfun[i] = NULL; | |
781 } | |
782 | |
783 /* Create the SDL window */ | |
784 SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0); | |
785 if ( SDL_windowid ) { | |
786 SDL_Window = (HWND)strtol(SDL_windowid, NULL, 0); | |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
787 |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
788 /* DJM: we want all event's for the user specified |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
789 window to be handled by SDL. |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
790 */ |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
791 if (SDL_Window) { |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
792 userWindowProc = (WNDPROC)GetWindowLong(SDL_Window, GWL_WNDPROC); |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
793 SetWindowLong(SDL_Window, GWL_WNDPROC, (LONG)WinMessage); |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
794 } |
0 | 795 } else { |
796 SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, | |
797 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX), | |
798 0, 0, 0, 0, NULL, NULL, SDL_Instance, NULL); | |
799 if ( SDL_Window == NULL ) { | |
800 SDL_SetError("Couldn't create window"); | |
801 return(-1); | |
802 } | |
803 ShowWindow(SDL_Window, SW_HIDE); | |
804 } | |
805 | |
806 /* Initialize DirectInput */ | |
807 if ( DX5_DInputInit(this) < 0 ) { | |
808 return(-1); | |
809 } | |
810 | |
811 /* Ready to roll */ | |
812 return(0); | |
813 } | |
814 | |
815 void DX5_DestroyWindow(_THIS) | |
816 { | |
817 /* Close down DirectInput */ | |
818 DX5_DInputQuit(this); | |
819 | |
820 /* Destroy our window */ | |
821 DestroyWindow(SDL_Window); | |
822 } |