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