Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32events.c @ 3768:1b87a8beab9d gsoc2008_manymouse
Project part1
author | Szymon Wilczek <kazeuser@gmail.com> |
---|---|
date | Wed, 30 Jul 2008 16:09:24 +0000 |
parents | abc8acb8e3d7 |
children | 81b649bad6d2 |
comparison
equal
deleted
inserted
replaced
3767:abc8acb8e3d7 | 3768:1b87a8beab9d |
---|---|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | 18 |
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 | |
23 #if (_WIN32_WINNT < 0x0501) | |
24 #undef _WIN32_WINNT | |
25 #define _WIN32_WINNT 0x0501 | |
26 #endif | |
27 | |
22 #include "SDL_config.h" | 28 #include "SDL_config.h" |
23 | 29 |
24 #include "SDL_win32video.h" | 30 #include "SDL_win32video.h" |
25 #include "SDL_syswm.h" | 31 #include "SDL_syswm.h" |
26 #include "SDL_vkeys.h" | 32 #include "SDL_vkeys.h" |
51 #endif | 57 #endif |
52 #ifndef GET_XBUTTON_WPARAM | 58 #ifndef GET_XBUTTON_WPARAM |
53 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) | 59 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) |
54 #endif | 60 #endif |
55 | 61 |
56 #define pi 1.0 | 62 extern HCTX* g_hCtx; |
57 | 63 extern HANDLE* mice; |
58 int first=1; | 64 extern int total_mice; |
59 | 65 |
60 LOGCONTEXT lc; | 66 int pressure=0; |
61 | 67 |
62 static WPARAM | 68 static WPARAM |
63 RemapVKEY(WPARAM wParam, LPARAM lParam) | 69 RemapVKEY(WPARAM wParam, LPARAM lParam) |
64 { | 70 { |
65 int i; | 71 int i; |
92 | 98 |
93 LRESULT CALLBACK | 99 LRESULT CALLBACK |
94 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | 100 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
95 { | 101 { |
96 SDL_WindowData *data; | 102 SDL_WindowData *data; |
97 | 103 RAWINPUT* raw; |
98 PACKET packet; | 104 PACKET packet; |
99 | 105 |
100 /* Send a SDL_SYSWMEVENT if the application wants them */ | 106 /* Send a SDL_SYSWMEVENT if the application wants them */ |
101 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { | 107 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { |
102 SDL_SysWMmsg wmmsg; | 108 SDL_SysWMmsg wmmsg; |
127 fclose(log); | 133 fclose(log); |
128 } | 134 } |
129 #endif | 135 #endif |
130 | 136 |
131 switch (msg) { | 137 switch (msg) { |
132 case WT_PACKET: | 138 case WT_PACKET: |
133 { | 139 { |
134 if (WTPacket((HCTX)lParam, wParam, &packet)) | 140 if (WTPacket((HCTX)lParam, wParam, &packet)) |
135 { | 141 { |
136 SDL_SendMouseMotion(0,0,(int)packet.pkX,(int)packet.pkY,(int)packet.pkNormalPressure); | 142 pressure=(int)packet.pkNormalPressure; |
137 } | 143 } |
138 } | 144 } |
139 break; | 145 break; |
140 case WT_PROXIMITY: | 146 case WT_PROXIMITY: |
141 { | 147 { |
199 case WT_CTXOPEN: | 205 case WT_CTXOPEN: |
200 { | 206 { |
201 SDL_SendMouseMotion(0,1,1,0,0); | 207 SDL_SendMouseMotion(0,1,1,0,0); |
202 SDL_SendMouseMotion(0,1,-1,0,0); | 208 SDL_SendMouseMotion(0,1,-1,0,0); |
203 } | 209 } |
204 case WM_MOUSEMOVE: | 210 /*case WM_MOUSEMOVE: |
205 { | 211 { |
212 LPBYTE lpb; | |
213 const RAWINPUTHEADER *header; | |
206 int index; | 214 int index; |
215 int i; | |
216 int size=0; | |
207 SDL_Mouse *mouse; | 217 SDL_Mouse *mouse; |
208 int x, y; | 218 int x, y; |
209 | 219 |
210 index = data->videodata->mouse; | 220 //index = data->videodata->mouse; |
221 GetRawInputData((HRAWINPUT) lParam, RID_INPUT, NULL, &size, sizeof (RAWINPUTHEADER)); | |
222 lpb = SDL_malloc(size*sizeof(LPBYTE)); | |
223 GetRawInputData((HRAWINPUT) lParam, RID_INPUT, lpb, &size, sizeof (RAWINPUTHEADER)); | |
224 raw = (RAWINPUT *) lpb; | |
225 header = &raw->header; | |
226 for(i=0;i<total_mice;++i) | |
227 { | |
228 if(mice[i]==header->hDevice) | |
229 { | |
230 index=i; | |
231 break; | |
232 } | |
233 } | |
211 mouse = SDL_GetMouse(index); | 234 mouse = SDL_GetMouse(index); |
212 | 235 |
213 if (mouse->focus != data->windowID) { | 236 if (mouse->focus != data->windowID) { |
214 TRACKMOUSEEVENT tme; | 237 TRACKMOUSEEVENT tme; |
215 | 238 |
220 | 243 |
221 SDL_SetMouseFocus(index, data->windowID); | 244 SDL_SetMouseFocus(index, data->windowID); |
222 } | 245 } |
223 | 246 |
224 /* mouse has moved within the window */ | 247 /* mouse has moved within the window */ |
225 x = LOWORD(lParam); | 248 //x = LOWORD(lParam); |
226 y = HIWORD(lParam); | 249 //y = HIWORD(lParam); |
227 //printf("index: %d\n",index); | 250 //printf("index: %d\n",index); |
228 if (mouse->relative_mode) { | 251 /*if (WTPacketsPeek(g_hCtx[data->windowID],1,&packet)) |
252 { | |
253 pressure=(int)packet.pkNormalPressure; | |
254 }*/ | |
255 /*if (mouse->relative_mode) { | |
229 int w, h; | 256 int w, h; |
230 POINT center; | 257 POINT center; |
231 SDL_GetWindowSize(data->windowID, &w, &h); | 258 SDL_GetWindowSize(data->windowID, &w, &h); |
232 center.x = (w / 2); | 259 center.x = (w / 2); |
233 center.y = (h / 2); | 260 center.y = (h / 2); |
234 x -= center.x; | 261 x -= center.x; |
235 y -= center.y; | 262 y -= center.y; |
236 if (x || y) { | 263 if (x || y) { |
237 ClientToScreen(hwnd, ¢er); | 264 ClientToScreen(hwnd, ¢er); |
238 SetCursorPos(center.x, center.y); | 265 SetCursorPos(center.x, center.y); |
239 SDL_SendMouseMotion(index, 1, x, y,0); | 266 SDL_SendMouseMotion(index, 1, x, y,pressure); |
240 } | 267 } |
241 } else { | 268 } else { |
242 SDL_SendMouseMotion(index, 0, x, y,0); | 269 SDL_SendMouseMotion(index, 0, x, y,pressure); |
243 } | 270 } |
244 } | 271 } |
245 return (0); | 272 return (0);*/ |
246 | 273 case WM_INPUT: |
274 { | |
275 LPBYTE lpb; | |
276 int w, h; | |
277 const RAWINPUTHEADER *header; | |
278 int index; | |
279 int i; | |
280 int size=0; | |
281 SDL_Mouse *mouse; | |
282 const RAWMOUSE *raw_mouse=NULL; | |
283 LPPOINT point; | |
284 USHORT flags; | |
285 GetRawInputData((HRAWINPUT) lParam, RID_INPUT, NULL, &size, sizeof (RAWINPUTHEADER)); | |
286 lpb = SDL_malloc(size*sizeof(LPBYTE)); | |
287 GetRawInputData((HRAWINPUT) lParam, RID_INPUT, lpb, &size, sizeof (RAWINPUTHEADER)); | |
288 raw = (RAWINPUT *) lpb; | |
289 header = &raw->header; | |
290 //raw_mouse=&raw->data.mouse; | |
291 flags=raw->data.mouse.usButtonFlags; | |
292 for(i=0;i<total_mice;++i) | |
293 { | |
294 if(mice[i]==header->hDevice) | |
295 { | |
296 index=i; | |
297 break; | |
298 } | |
299 } | |
300 mouse = SDL_GetMouse(index); | |
301 GetCursorPos(&point); | |
302 ScreenToClient(hwnd, &point); | |
303 SDL_GetWindowSize(data->windowID, &w, &h); | |
304 SDL_UpdateCoordinates(w,h); | |
305 SDL_SendMouseMotion(index,0,(int)(&point->x),(int)(&point->y),pressure); | |
306 if(flags & RI_MOUSE_BUTTON_1_DOWN) | |
307 { | |
308 SDL_SendMouseButton(index,SDL_PRESSED,SDL_BUTTON_LEFT); | |
309 } | |
310 else if(flags & RI_MOUSE_BUTTON_1_UP) | |
311 { | |
312 SDL_SendMouseButton(index,SDL_RELEASED,SDL_BUTTON_LEFT); | |
313 } | |
314 if(flags & RI_MOUSE_BUTTON_2_DOWN) | |
315 { | |
316 SDL_SendMouseButton(index,SDL_PRESSED,SDL_BUTTON_MIDDLE); | |
317 } | |
318 else if(flags & RI_MOUSE_BUTTON_2_UP) | |
319 { | |
320 SDL_SendMouseButton(index,SDL_RELEASED,SDL_BUTTON_MIDDLE); | |
321 } | |
322 if(flags & RI_MOUSE_BUTTON_3_DOWN) | |
323 { | |
324 SDL_SendMouseButton(index,SDL_PRESSED,SDL_BUTTON_RIGHT); | |
325 } | |
326 else if(flags & RI_MOUSE_BUTTON_3_UP) | |
327 { | |
328 SDL_SendMouseButton(index,SDL_RELEASED,SDL_BUTTON_RIGHT); | |
329 } | |
330 } | |
331 return(0); | |
247 case WM_MOUSELEAVE: | 332 case WM_MOUSELEAVE: |
248 { | 333 { |
249 int index; | 334 int index; |
250 SDL_Mouse *mouse; | 335 SDL_Mouse *mouse; |
251 | 336 |
256 SDL_SetMouseFocus(index, 0); | 341 SDL_SetMouseFocus(index, 0); |
257 } | 342 } |
258 } | 343 } |
259 return (0); | 344 return (0); |
260 | 345 |
261 case WM_LBUTTONDOWN: | 346 |
262 case WM_LBUTTONUP: | 347 |
263 case WM_MBUTTONDOWN: | 348 /* case WM_MOUSEWHEEL: |
264 case WM_MBUTTONUP: | |
265 case WM_RBUTTONDOWN: | |
266 case WM_RBUTTONUP: | |
267 case WM_XBUTTONDOWN: | |
268 case WM_XBUTTONUP: | |
269 { | |
270 int xbuttonval = 0; | |
271 int index; | |
272 SDL_Mouse *mouse; | |
273 Uint8 button, state; | |
274 | |
275 /* DJM: | |
276 We want the SDL window to take focus so that | |
277 it acts like a normal windows "component" | |
278 (e.g. gains keyboard focus on a mouse click). | |
279 */ | |
280 SetFocus(hwnd); | |
281 | |
282 index = data->videodata->mouse; | |
283 mouse = SDL_GetMouse(index); | |
284 | |
285 /* Figure out which button to use */ | |
286 switch (msg) { | |
287 case WM_LBUTTONDOWN: | |
288 button = SDL_BUTTON_LEFT; | |
289 state = SDL_PRESSED; | |
290 break; | |
291 case WM_LBUTTONUP: | |
292 button = SDL_BUTTON_LEFT; | |
293 state = SDL_RELEASED; | |
294 break; | |
295 case WM_MBUTTONDOWN: | |
296 button = SDL_BUTTON_MIDDLE; | |
297 state = SDL_PRESSED; | |
298 break; | |
299 case WM_MBUTTONUP: | |
300 button = SDL_BUTTON_MIDDLE; | |
301 state = SDL_RELEASED; | |
302 break; | |
303 case WM_RBUTTONDOWN: | |
304 button = SDL_BUTTON_RIGHT; | |
305 state = SDL_PRESSED; | |
306 break; | |
307 case WM_RBUTTONUP: | |
308 button = SDL_BUTTON_RIGHT; | |
309 state = SDL_RELEASED; | |
310 break; | |
311 case WM_XBUTTONDOWN: | |
312 xbuttonval = GET_XBUTTON_WPARAM(wParam); | |
313 button = SDL_BUTTON_X1 + xbuttonval - 1; | |
314 state = SDL_PRESSED; | |
315 break; | |
316 case WM_XBUTTONUP: | |
317 xbuttonval = GET_XBUTTON_WPARAM(wParam); | |
318 button = SDL_BUTTON_X1 + xbuttonval - 1; | |
319 state = SDL_RELEASED; | |
320 break; | |
321 default: | |
322 /* Eh? Unknown button? */ | |
323 return (0); | |
324 } | |
325 if (state == SDL_PRESSED) { | |
326 /* Grab mouse so we get up events */ | |
327 if (++data->mouse_pressed > 0) { | |
328 SetCapture(hwnd); | |
329 } | |
330 } else { | |
331 /* Release mouse after all up events */ | |
332 if (--data->mouse_pressed <= 0) { | |
333 ReleaseCapture(); | |
334 data->mouse_pressed = 0; | |
335 } | |
336 } | |
337 | |
338 if (!mouse->relative_mode) { | |
339 int x, y; | |
340 x = LOWORD(lParam); | |
341 y = HIWORD(lParam); | |
342 SDL_SendMouseMotion(index, 0, x, y,0); | |
343 } | |
344 SDL_SendMouseButton(index, state, button); | |
345 | |
346 /* | |
347 * MSDN says: | |
348 * "Unlike the WM_LBUTTONUP, WM_MBUTTONUP, and WM_RBUTTONUP | |
349 * messages, an application should return TRUE from [an | |
350 * XBUTTON message] if it processes it. Doing so will allow | |
351 * software that simulates this message on Microsoft Windows | |
352 * systems earlier than Windows 2000 to determine whether | |
353 * the window procedure processed the message or called | |
354 * DefWindowProc to process it. | |
355 */ | |
356 if (xbuttonval > 0) { | |
357 return (TRUE); | |
358 } | |
359 } | |
360 return (0); | |
361 | |
362 case WM_MOUSEWHEEL: | |
363 { | 349 { |
364 int index; | 350 int index; |
365 int motion = (short) HIWORD(wParam); | 351 int motion = (short) HIWORD(wParam); |
366 | 352 |
367 index = data->videodata->mouse; | 353 index = data->videodata->mouse; |
368 SDL_SendMouseWheel(index, 0, motion); | 354 SDL_SendMouseWheel(index, 0, motion); |
369 } | 355 } |
370 return (0); | 356 return (0);*/ |
371 | 357 |
372 case WM_SYSKEYDOWN: | 358 case WM_SYSKEYDOWN: |
373 case WM_KEYDOWN: | 359 case WM_KEYDOWN: |
374 { | 360 { |
375 int index; | 361 int index; |
661 void | 647 void |
662 WIN_PumpEvents(_THIS) | 648 WIN_PumpEvents(_THIS) |
663 { | 649 { |
664 MSG msg; | 650 MSG msg; |
665 | 651 |
666 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { | 652 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) { |
667 TranslateMessage(&msg); | 653 TranslateMessage(&msg); |
668 DispatchMessage(&msg); | 654 DispatchMessageA(&msg); |
669 | 655 |
670 } | 656 } |
671 /*while (GetMessage(&msg, NULL, 0, 0)) { | |
672 TranslateMessage(&msg); | |
673 DispatchMessage(&msg); | |
674 }*/ | |
675 //WTClose(g_hCtx); | |
676 } | 657 } |
677 | 658 |
678 static int app_registered = 0; | 659 static int app_registered = 0; |
679 LPTSTR SDL_Appname = NULL; | 660 LPTSTR SDL_Appname = NULL; |
680 Uint32 SDL_Appstyle = 0; | 661 Uint32 SDL_Appstyle = 0; |