First pass at Windows multi-touch gesture support
This commit is contained in:
parent
f7fc00e75c
commit
56c7ba92fb
6 changed files with 381 additions and 307 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "SDL_syswm.h"
|
||||
#include "SDL_vkeys.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#include "../../events/SDL_touch_c.h"
|
||||
|
||||
|
||||
|
||||
|
@ -55,13 +56,11 @@
|
|||
#ifndef WM_INPUT
|
||||
#define WM_INPUT 0x00ff
|
||||
#endif
|
||||
#ifndef WM_GESTURE
|
||||
#define WM_GESTURE 0x0119
|
||||
#endif
|
||||
#ifndef WM_TOUCH
|
||||
#define WM_TOUCH 0x0240
|
||||
#endif
|
||||
|
||||
|
||||
static WPARAM
|
||||
RemapVKEY(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
|
@ -519,39 +518,68 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
}
|
||||
returnCode = 0;
|
||||
break;
|
||||
|
||||
case WM_TOUCH:
|
||||
{
|
||||
//printf("Got Touch Event!\n");
|
||||
UINT i, num_inputs = LOWORD(wParam);
|
||||
PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs);
|
||||
if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) {
|
||||
RECT rect;
|
||||
float x, y;
|
||||
|
||||
#ifdef WMMSG_DEBUG
|
||||
FILE *log = fopen("wmmsg.txt", "a");
|
||||
fprintf(log, "Received Touch Message: %p ", hwnd);
|
||||
if (msg > MAX_WMMSG) {
|
||||
fprintf(log, "%d", msg);
|
||||
} else {
|
||||
fprintf(log, "%s", wmtab[msg]);
|
||||
}
|
||||
fprintf(log, "WM_TOUCH = %d -- 0x%X, 0x%X\n",msg, wParam, lParam);
|
||||
fclose(log);
|
||||
#endif
|
||||
|
||||
}
|
||||
if (!GetClientRect(hwnd, &rect) ||
|
||||
(rect.right == rect.left && rect.bottom == rect.top)) {
|
||||
break;
|
||||
case WM_GESTURE:
|
||||
{
|
||||
//printf("Got Touch Event!\n");
|
||||
|
||||
#ifdef WMMSG_DEBUG
|
||||
FILE *log = fopen("wmmsg.txt", "a");
|
||||
fprintf(log, "Received Gesture Message: %p ", hwnd);
|
||||
if (msg > MAX_WMMSG) {
|
||||
fprintf(log, "%d", msg);
|
||||
} else {
|
||||
fprintf(log, "%s", wmtab[msg]);
|
||||
}
|
||||
fprintf(log, "WM_GESTURE = %d -- 0x%X, 0x%X\n",msg, wParam, lParam);
|
||||
fclose(log);
|
||||
#endif
|
||||
ClientToScreen(hwnd, (LPPOINT) & rect);
|
||||
ClientToScreen(hwnd, (LPPOINT) & rect + 1);
|
||||
rect.top *= 100;
|
||||
rect.left *= 100;
|
||||
rect.bottom *= 100;
|
||||
rect.right *= 100;
|
||||
|
||||
for (i = 0; i < num_inputs; ++i) {
|
||||
PTOUCHINPUT input = &inputs[i];
|
||||
|
||||
SDL_TouchID touchId = (SDL_TouchID)input->hSource;
|
||||
if (!SDL_GetTouch(touchId)) {
|
||||
SDL_Touch touch;
|
||||
|
||||
touch.id = touchId;
|
||||
touch.x_min = 0;
|
||||
touch.x_max = 1;
|
||||
touch.native_xres = touch.x_max - touch.x_min;
|
||||
touch.y_min = 0;
|
||||
touch.y_max = 1;
|
||||
touch.native_yres = touch.y_max - touch.y_min;
|
||||
touch.pressure_min = 0;
|
||||
touch.pressure_max = 1;
|
||||
touch.native_pressureres = touch.pressure_max - touch.pressure_min;
|
||||
|
||||
if (SDL_AddTouch(&touch, "") < 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the normalized coordinates for the window
|
||||
x = (float)(input->x - rect.left)/(rect.right - rect.left);
|
||||
y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
|
||||
|
||||
if (input->dwFlags & TOUCHEVENTF_DOWN) {
|
||||
SDL_SendFingerDown(touchId, input->dwID, SDL_TRUE, x, y, 1);
|
||||
}
|
||||
if (input->dwFlags & TOUCHEVENTF_MOVE) {
|
||||
SDL_SendTouchMotion(touchId, input->dwID, SDL_FALSE, x, y, 1);
|
||||
}
|
||||
if (input->dwFlags & TOUCHEVENTF_UP) {
|
||||
SDL_SendFingerDown(touchId, input->dwID, SDL_FALSE, x, y, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_stack_free(inputs);
|
||||
|
||||
data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -82,6 +82,10 @@ WIN_DeleteDevice(SDL_VideoDevice * device)
|
|||
FreeLibrary(data->hAygShell);
|
||||
}
|
||||
#endif
|
||||
if (data->userDLL) {
|
||||
FreeLibrary(data->userDLL);
|
||||
}
|
||||
|
||||
SDL_free(device->driverdata);
|
||||
SDL_free(device);
|
||||
}
|
||||
|
@ -155,6 +159,13 @@ WIN_CreateDevice(int devindex)
|
|||
data->CoordTransform = NULL;
|
||||
#endif
|
||||
|
||||
data->userDLL = LoadLibrary(TEXT("USER32.DLL"));
|
||||
if (data->userDLL) {
|
||||
data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) GetProcAddress(data->userDLL, "CloseTouchInputHandle");
|
||||
data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) GetProcAddress(data->userDLL, "GetTouchInputInfo");
|
||||
data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) GetProcAddress(data->userDLL, "RegisterTouchWindow");
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
device->VideoInit = WIN_VideoInit;
|
||||
device->VideoQuit = WIN_VideoQuit;
|
||||
|
|
|
@ -80,6 +80,32 @@ extern void WIN_SetError(const char *prefix);
|
|||
|
||||
enum { RENDER_NONE, RENDER_D3D, RENDER_DDRAW, RENDER_GDI, RENDER_GAPI, RENDER_RAW };
|
||||
|
||||
#if WINVER < 0x0601
|
||||
/* Touch input definitions */
|
||||
#define TWF_FINETOUCH 1
|
||||
#define TWF_WANTPALM 2
|
||||
|
||||
#define TOUCHEVENTF_MOVE 0x0001
|
||||
#define TOUCHEVENTF_DOWN 0x0002
|
||||
#define TOUCHEVENTF_UP 0x0004
|
||||
|
||||
DECLARE_HANDLE(HTOUCHINPUT);
|
||||
|
||||
typedef struct _TOUCHINPUT {
|
||||
LONG x;
|
||||
LONG y;
|
||||
HANDLE hSource;
|
||||
DWORD dwID;
|
||||
DWORD dwFlags;
|
||||
DWORD dwMask;
|
||||
DWORD dwTime;
|
||||
ULONG_PTR dwExtraInfo;
|
||||
DWORD cxContact;
|
||||
DWORD cyContact;
|
||||
} TOUCHINPUT, *PTOUCHINPUT;
|
||||
|
||||
#endif /* WINVER < 0x0601 */
|
||||
|
||||
typedef BOOL (*PFNSHFullScreen)(HWND, DWORD);
|
||||
typedef void (*PFCoordTransform)(SDL_Window*, POINT*);
|
||||
|
||||
|
@ -137,6 +163,12 @@ typedef struct SDL_VideoData
|
|||
const SDL_scancode *key_layout;
|
||||
DWORD clipboard_count;
|
||||
|
||||
/* Touch input functions */
|
||||
HANDLE userDLL;
|
||||
BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT );
|
||||
BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int );
|
||||
BOOL (WINAPI *RegisterTouchWindow)( HWND, ULONG );
|
||||
|
||||
SDL_bool ime_com_initialized;
|
||||
struct ITfThreadMgr *ime_threadmgr;
|
||||
SDL_bool ime_initialized;
|
||||
|
|
|
@ -144,6 +144,9 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
|
|||
}
|
||||
}
|
||||
|
||||
/* Enable multi-touch */
|
||||
videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
|
||||
|
||||
/* All done! */
|
||||
window->driverdata = data;
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue