Mercurial > sdl-ios-xcode
diff src/video/win32/SDL_win32window.c @ 2710:44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Many-mouse and tablet support
by Szymon Wilczek, mentored by Ryan C. Gordon
Everything concerning the project is noted on the wiki:
http://wilku.ravenlord.ws/doku.php?id=start
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 25 Aug 2008 06:33:00 +0000 |
parents | ba0d62354872 |
children | 0906692aa6a4 |
line wrap: on
line diff
--- a/src/video/win32/SDL_win32window.c Mon Aug 25 05:30:28 2008 +0000 +++ b/src/video/win32/SDL_win32window.c Mon Aug 25 06:33:00 2008 +0000 @@ -19,6 +19,14 @@ Sam Lantinga slouken@libsdl.org */ + +/* we need to define it, so that raw input is included */ + +#if (_WIN32_WINNT < 0x0501) +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 +#endif + #include "SDL_config.h" #include "../SDL_sysvideo.h" @@ -29,6 +37,15 @@ /* This is included after SDL_win32video.h, which includes windows.h */ #include "SDL_syswm.h" +#include <wintab.h> + +/* we're telling wintab that we want to receive movement, button events and pressure information in packets */ +#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_CURSOR) +#define PACKETMODE 0 +#include <pktdef.h> + +extern HCTX *g_hCtx; /* the table of tablet event contexts, each windows has to have it's own tablet context */ +int highestId = 0; /* the highest id of the tablet context */ static int SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) @@ -132,6 +149,9 @@ int WIN_CreateWindow(_THIS, SDL_Window * window) { + RAWINPUTDEVICE Rid; + AXIS TabX, TabY; + LOGCONTEXT lc; HWND hwnd; HWND top; RECT rect; @@ -180,13 +200,53 @@ hwnd = CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL, SDL_Instance, NULL); - WIN_PumpEvents(_this); - if (!hwnd) { WIN_SetError("Couldn't create window"); return -1; } + /* we're configuring the tablet data. See Wintab reference for more info */ + if (WTInfo(WTI_DEFSYSCTX, 0, &lc) != 0) { + lc.lcPktData = PACKETDATA; + lc.lcPktMode = PACKETMODE; + lc.lcOptions |= CXO_MESSAGES; + lc.lcOptions |= CXO_SYSTEM; + lc.lcMoveMask = PACKETDATA; + lc.lcBtnDnMask = lc.lcBtnUpMask = PACKETDATA; + WTInfo(WTI_DEVICES, DVC_X, &TabX); + WTInfo(WTI_DEVICES, DVC_Y, &TabY); + lc.lcInOrgX = 0; + lc.lcInOrgY = 0; + lc.lcInExtX = TabX.axMax; + lc.lcInExtY = TabY.axMax; + lc.lcOutOrgX = 0; + lc.lcOutOrgY = 0; + lc.lcOutExtX = GetSystemMetrics(SM_CXSCREEN); + lc.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN); + if (window->id > highestId) { + HCTX *tmp_hctx; + highestId = window->id; + tmp_hctx = + (HCTX *) SDL_realloc(g_hCtx, (highestId + 1) * sizeof(HCTX)); + if (!tmp_hctx) { + SDL_OutOfMemory(); + DestroyWindow(hwnd); + return -1; + } + g_hCtx = tmp_hctx; + } + g_hCtx[window->id] = WTOpen(hwnd, &lc, TRUE); + } + + /* we're telling the window, we want it to report raw input events from mice */ + Rid.usUsagePage = 0x01; + Rid.usUsage = 0x02; + Rid.dwFlags = RIDEV_INPUTSINK; + Rid.hwndTarget = hwnd; + RegisterRawInputDevices(&Rid, 1, sizeof(Rid)); + + WIN_PumpEvents(_this); + if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) { DestroyWindow(hwnd); return -1; @@ -389,6 +449,7 @@ #endif ReleaseDC(data->hwnd, data->hdc); if (data->created) { + WTClose(g_hCtx[window->id]); DestroyWindow(data->hwnd); } SDL_free(data);