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