comparison src/video/windx5/SDL_dx5events.c @ 1662:782fd950bd46 SDL-1.3

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