Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32events.c @ 4919:716b2cbf4c9e
First pass at Windows multi-touch gesture support
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 30 Nov 2010 17:58:51 -0800 |
parents | 50d0bff24d81 |
children | 0d1bb1ce9d15 |
comparison
equal
deleted
inserted
replaced
4918:f5f70fed2c4c | 4919:716b2cbf4c9e |
---|---|
25 #include "SDL_win32video.h" | 25 #include "SDL_win32video.h" |
26 #include "SDL_win32shape.h" | 26 #include "SDL_win32shape.h" |
27 #include "SDL_syswm.h" | 27 #include "SDL_syswm.h" |
28 #include "SDL_vkeys.h" | 28 #include "SDL_vkeys.h" |
29 #include "../../events/SDL_events_c.h" | 29 #include "../../events/SDL_events_c.h" |
30 #include "../../events/SDL_touch_c.h" | |
30 | 31 |
31 | 32 |
32 | 33 |
33 /*#define WMMSG_DEBUG*/ | 34 /*#define WMMSG_DEBUG*/ |
34 #ifdef WMMSG_DEBUG | 35 #ifdef WMMSG_DEBUG |
53 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) | 54 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) |
54 #endif | 55 #endif |
55 #ifndef WM_INPUT | 56 #ifndef WM_INPUT |
56 #define WM_INPUT 0x00ff | 57 #define WM_INPUT 0x00ff |
57 #endif | 58 #endif |
58 #ifndef WM_GESTURE | |
59 #define WM_GESTURE 0x0119 | |
60 #endif | |
61 #ifndef WM_TOUCH | 59 #ifndef WM_TOUCH |
62 #define WM_TOUCH 0x0240 | 60 #define WM_TOUCH 0x0240 |
63 #endif | 61 #endif |
62 | |
64 | 63 |
65 static WPARAM | 64 static WPARAM |
66 RemapVKEY(WPARAM wParam, LPARAM lParam) | 65 RemapVKEY(WPARAM wParam, LPARAM lParam) |
67 { | 66 { |
68 int i; | 67 int i; |
517 { | 516 { |
518 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0); | 517 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0); |
519 } | 518 } |
520 returnCode = 0; | 519 returnCode = 0; |
521 break; | 520 break; |
521 | |
522 case WM_TOUCH: | 522 case WM_TOUCH: |
523 { | 523 { |
524 //printf("Got Touch Event!\n"); | 524 UINT i, num_inputs = LOWORD(wParam); |
525 | 525 PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs); |
526 #ifdef WMMSG_DEBUG | 526 if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) { |
527 FILE *log = fopen("wmmsg.txt", "a"); | 527 RECT rect; |
528 fprintf(log, "Received Touch Message: %p ", hwnd); | 528 float x, y; |
529 if (msg > MAX_WMMSG) { | 529 |
530 fprintf(log, "%d", msg); | 530 if (!GetClientRect(hwnd, &rect) || |
531 } else { | 531 (rect.right == rect.left && rect.bottom == rect.top)) { |
532 fprintf(log, "%s", wmtab[msg]); | 532 break; |
533 } | |
534 ClientToScreen(hwnd, (LPPOINT) & rect); | |
535 ClientToScreen(hwnd, (LPPOINT) & rect + 1); | |
536 rect.top *= 100; | |
537 rect.left *= 100; | |
538 rect.bottom *= 100; | |
539 rect.right *= 100; | |
540 | |
541 for (i = 0; i < num_inputs; ++i) { | |
542 PTOUCHINPUT input = &inputs[i]; | |
543 | |
544 SDL_TouchID touchId = (SDL_TouchID)input->hSource; | |
545 if (!SDL_GetTouch(touchId)) { | |
546 SDL_Touch touch; | |
547 | |
548 touch.id = touchId; | |
549 touch.x_min = 0; | |
550 touch.x_max = 1; | |
551 touch.native_xres = touch.x_max - touch.x_min; | |
552 touch.y_min = 0; | |
553 touch.y_max = 1; | |
554 touch.native_yres = touch.y_max - touch.y_min; | |
555 touch.pressure_min = 0; | |
556 touch.pressure_max = 1; | |
557 touch.native_pressureres = touch.pressure_max - touch.pressure_min; | |
558 | |
559 if (SDL_AddTouch(&touch, "") < 0) { | |
560 continue; | |
561 } | |
562 } | |
563 | |
564 // Get the normalized coordinates for the window | |
565 x = (float)(input->x - rect.left)/(rect.right - rect.left); | |
566 y = (float)(input->y - rect.top)/(rect.bottom - rect.top); | |
567 | |
568 if (input->dwFlags & TOUCHEVENTF_DOWN) { | |
569 SDL_SendFingerDown(touchId, input->dwID, SDL_TRUE, x, y, 1); | |
570 } | |
571 if (input->dwFlags & TOUCHEVENTF_MOVE) { | |
572 SDL_SendTouchMotion(touchId, input->dwID, SDL_FALSE, x, y, 1); | |
573 } | |
574 if (input->dwFlags & TOUCHEVENTF_UP) { | |
575 SDL_SendFingerDown(touchId, input->dwID, SDL_FALSE, x, y, 1); | |
576 } | |
577 } | |
533 } | 578 } |
534 fprintf(log, "WM_TOUCH = %d -- 0x%X, 0x%X\n",msg, wParam, lParam); | 579 SDL_stack_free(inputs); |
535 fclose(log); | 580 |
536 #endif | 581 data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam); |
537 | 582 return 0; |
538 } | 583 } |
539 break; | 584 break; |
540 case WM_GESTURE: | |
541 { | |
542 //printf("Got Touch Event!\n"); | |
543 | |
544 #ifdef WMMSG_DEBUG | |
545 FILE *log = fopen("wmmsg.txt", "a"); | |
546 fprintf(log, "Received Gesture Message: %p ", hwnd); | |
547 if (msg > MAX_WMMSG) { | |
548 fprintf(log, "%d", msg); | |
549 } else { | |
550 fprintf(log, "%s", wmtab[msg]); | |
551 } | |
552 fprintf(log, "WM_GESTURE = %d -- 0x%X, 0x%X\n",msg, wParam, lParam); | |
553 fclose(log); | |
554 #endif | |
555 } | |
556 break; | |
557 } | 585 } |
558 | 586 |
559 /* If there's a window proc, assume it's going to handle messages */ | 587 /* If there's a window proc, assume it's going to handle messages */ |
560 if (data->wndproc) { | 588 if (data->wndproc) { |
561 return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam); | 589 return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam); |