Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Dynamically load wintab32.dll
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 26, 2008
1 parent a8daaa4 commit 93c32a5
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/video/win32/SDL_win32events.c
Expand Up @@ -136,7 +136,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WT_PACKET:
{
/* if we receive such data we need to update the pressure */
if (WTPacket((HCTX) lParam, wParam, &packet)) {
SDL_VideoData *videodata = data->videodata;
if (videodata->wintabDLL
&& videodata->WTPacket((HCTX) lParam, wParam, &packet)) {
SDL_ChangeEnd(tablet, (int) packet.pkCursor);
pressure = (int) packet.pkNormalPressure;
}
Expand Down
6 changes: 4 additions & 2 deletions src/video/win32/SDL_win32keyboard.c
Expand Up @@ -55,7 +55,8 @@ WIN_InitKeyboard(_THIS)
/* Make sure the alpha scancodes are correct. T isn't usually remapped */
if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) {
#if 0
printf("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
printf
("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
#endif
for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
Expand All @@ -66,7 +67,8 @@ WIN_InitKeyboard(_THIS)
}
if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
#if 0
printf("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
printf
("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
#endif
for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
keypad_scancodes[i] =
Expand Down
6 changes: 3 additions & 3 deletions src/video/win32/SDL_win32mouse.c
Expand Up @@ -154,7 +154,7 @@ WIN_InitMouse(_THIS)
l = SDL_strlen(device_name);

/* we're checking if the device isn't by any chance a tablet */
if (tablet == -1) {
if (data->wintabDLL && tablet == -1) {
for (j = 0; j < l - 5; ++j) {
for (k = 0; k < 5; ++k) {
if (tab[k] !=
Expand All @@ -173,8 +173,8 @@ WIN_InitMouse(_THIS)
if (tablet == index) {
AXIS pressure;
int cursors;
WTInfo(WTI_DEVICES, DVC_NPRESSURE, &pressure);
WTInfo(WTI_DEVICES, DVC_NCSRTYPES, &cursors);
data->WTInfo(WTI_DEVICES, DVC_NPRESSURE, &pressure);
data->WTInfo(WTI_DEVICES, DVC_NCSRTYPES, &cursors);
data->mouse =
SDL_AddMouse(&mouse, index, device_name, pressure.axMax,
pressure.axMin, cursors);
Expand Down
29 changes: 29 additions & 0 deletions src/video/win32/SDL_win32video.c
Expand Up @@ -60,6 +60,9 @@ WIN_DeleteDevice(SDL_VideoDevice * device)
FreeLibrary(data->d3dDLL);
}
#endif
if (data->wintabDLL) {
FreeLibrary(data->wintabDLL);
}
SDL_free(device->driverdata);
SDL_free(device);
}
Expand Down Expand Up @@ -104,6 +107,32 @@ WIN_CreateDevice(int devindex)
}
#endif /* SDL_VIDEO_RENDER_D3D */

data->wintabDLL = LoadLibrary(TEXT("WINTAB32.DLL"));
if (data->wintabDLL) {
#define PROCNAME(X) #X
data->WTInfo =
(UINT(*)(UINT, UINT, LPVOID)) GetProcAddress(data->wintabDLL,
PROCNAME(WTInfo));
data->WTOpen =
(HCTX(*)(HWND, LPLOGCONTEXT, BOOL)) GetProcAddress(data->
wintabDLL,
PROCNAME
(WTOpen));
data->WTPacket =
(int (*)(HCTX, UINT, LPVOID)) GetProcAddress(data->wintabDLL,
PROCNAME(WTPacket));
data->WTClose =
(BOOL(*)(HCTX)) GetProcAddress(data->wintabDLL,
PROCNAME(WTClose));
#undef PROCNAME

if (!data->WTInfo || !data->WTOpen || !data->WTPacket
|| !data->WTClose) {
FreeLibrary(data->wintabDLL);
data->wintabDLL = NULL;
}
}

/* Set the function pointers */
device->VideoInit = WIN_VideoInit;
device->VideoQuit = WIN_VideoQuit;
Expand Down
9 changes: 9 additions & 0 deletions src/video/win32/SDL_win32video.h
Expand Up @@ -66,6 +66,15 @@ typedef struct SDL_VideoData
HANDLE d3dDLL;
IDirect3D9 *d3d;
#endif
/* *INDENT-OFF* */
/* Function pointers for the Wacom API */
HANDLE wintabDLL;
UINT (*WTInfo) (UINT, UINT, LPVOID);
HCTX (*WTOpen) (HWND, LPLOGCONTEXT, BOOL);
int (*WTPacket) (HCTX, UINT, LPVOID);
BOOL (*WTClose) (HCTX);
/* *INDENT-ON* */

int mouse;
int keyboard;
SDL_scancode *key_layout;
Expand Down
14 changes: 9 additions & 5 deletions src/video/win32/SDL_win32window.c
Expand Up @@ -148,6 +148,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
int
WIN_CreateWindow(_THIS, SDL_Window * window)
{
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
RAWINPUTDEVICE Rid;
AXIS TabX, TabY;
LOGCONTEXT lc;
Expand Down Expand Up @@ -205,15 +206,15 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
}

/* we're configuring the tablet data. See Wintab reference for more info */
if (WTInfo(WTI_DEFSYSCTX, 0, &lc) != 0) {
if (videodata->wintabDLL && videodata->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);
videodata->WTInfo(WTI_DEVICES, DVC_X, &TabX);
videodata->WTInfo(WTI_DEVICES, DVC_Y, &TabY);
lc.lcInOrgX = 0;
lc.lcInOrgY = 0;
lc.lcInExtX = TabX.axMax;
Expand All @@ -234,7 +235,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
}
g_hCtx = tmp_hctx;
}
g_hCtx[window->id] = WTOpen(hwnd, &lc, TRUE);
g_hCtx[window->id] = videodata->WTOpen(hwnd, &lc, TRUE);
}

/* we're telling the window, we want it to report raw input events from mice */
Expand Down Expand Up @@ -438,6 +439,7 @@ WIN_SetWindowGrab(_THIS, SDL_Window * window)
void
WIN_DestroyWindow(_THIS, SDL_Window * window)
{
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;

if (data) {
Expand All @@ -448,7 +450,9 @@ WIN_DestroyWindow(_THIS, SDL_Window * window)
#endif
ReleaseDC(data->hwnd, data->hdc);
if (data->created) {
WTClose(g_hCtx[window->id]);
if (videodata->wintabDLL) {
videodata->WTClose(g_hCtx[window->id]);
}
DestroyWindow(data->hwnd);
}
SDL_free(data);
Expand Down
1 change: 1 addition & 0 deletions src/video/win32/wactab/pktdef.h
@@ -1,3 +1,4 @@
/* *INDENT-OFF* */
/* -------------------------------- pktdef.h -------------------------------- */
/* Combined 16 & 32-bit version. */

Expand Down
1 change: 1 addition & 0 deletions src/video/win32/wactab/wintab.h
@@ -1,3 +1,4 @@
/* *INDENT-OFF* */
/* -------------------------------- wintab.h -------------------------------- */
/* Combined 16 & 32-bit version. */

Expand Down
1 change: 1 addition & 0 deletions src/video/win32/wactab/wintabx.h
@@ -1,3 +1,4 @@
/* *INDENT-OFF* */
/* ------------------------------- wintabx.h -------------------------------- */
/* Combined 16 & 32-bit version. */

Expand Down

0 comments on commit 93c32a5

Please sign in to comment.