diff options
author | Mike Erwin <significant.bit@gmail.com> | 2010-08-16 22:59:36 +0400 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2010-08-16 22:59:36 +0400 |
commit | 4bfd915f9c1e2de30617683e2415d6d65bda4627 (patch) | |
tree | 638b42d1adf0fc47adbfab05d4e78399d3909f8b | |
parent | 2c468d9e5a60b60ab70d1daabc3833d3e90d35eb (diff) |
pencils down! additional Windows Wacom wackiness.
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWin32.cpp | 27 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_TabletManagerWin32.cpp | 111 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_TabletManagerWin32.h | 33 |
3 files changed, 138 insertions, 33 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index 11ba695a4f9..0315fa5870a 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -841,7 +841,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, bool GHOST_SystemWin32::handleEvent(GHOST_WindowWin32* window, UINT msg, WPARAM wParam, LPARAM lParam) { GHOST_Event* event = NULL; - bool eventSent = false; + bool eventHandled = false; static int mousePosX = 0, mousePosY = 0; // track mouse position between calls @@ -1014,10 +1014,19 @@ bool GHOST_SystemWin32::handleEvent(GHOST_WindowWin32* window, UINT msg, WPARAM case WM_MOUSEMOVE: { - if (!eventIsFromTablet() && !m_tabletManager->anyButtonsDown()) + if (!eventIsFromTablet()) + { // Even with careful checking, a stray cursor event sneaks through just before each // tablet mouse/pen button up event. Keep clean separation between tablet and mouse! - { + if (m_tabletManager->anyButtonsDown()) + { + // tablet manager handles all its own cursor moves. + // ignore 'regular' mouse while a tablet tool is being used. + DefWindowProc(window->getHWND(), WM_MOUSEMOVE, wParam, lParam); + eventHandled = true; + break; + } + int xPrev = mousePosX; int yPrev = mousePosY; // window coordinates are passed in via lParam @@ -1056,10 +1065,10 @@ bool GHOST_SystemWin32::handleEvent(GHOST_WindowWin32* window, UINT msg, WPARAM UINT rawSize = sizeof(RAWINPUT); GetRawInputData((HRAWINPUT)lParam, RID_INPUT, raw_ptr, &rawSize, sizeof(RAWINPUTHEADER)); - eventSent |= processRawInput(raw, window); + eventHandled |= processRawInput(raw, window); if (processRawInput(raw, window)) - eventSent = true; + eventHandled = true; // else // DefRawInputProc(&raw_ptr, 1, sizeof(RAWINPUTHEADER)); @@ -1089,7 +1098,7 @@ bool GHOST_SystemWin32::handleEvent(GHOST_WindowWin32* window, UINT msg, WPARAM for (int i = 0; i < n; ++i) { RAWINPUT const& raw = rawBuffer[i]; - eventSent |= processRawInput(raw, window); + eventHandled |= processRawInput(raw, window); } // clear processed events from the queue @@ -1290,13 +1299,13 @@ bool GHOST_SystemWin32::handleEvent(GHOST_WindowWin32* window, UINT msg, WPARAM #endif // illustrative code } - if (!eventSent) + if (!eventHandled) if (event) { pushEvent(event); - eventSent = true; + eventHandled = true; } - return eventSent; + return eventHandled; } GHOST_TUns8* GHOST_SystemWin32::getClipboard(bool selection) const diff --git a/intern/ghost/intern/GHOST_TabletManagerWin32.cpp b/intern/ghost/intern/GHOST_TabletManagerWin32.cpp index a34d6730cee..868b5dcc162 100644 --- a/intern/ghost/intern/GHOST_TabletManagerWin32.cpp +++ b/intern/ghost/intern/GHOST_TabletManagerWin32.cpp @@ -171,27 +171,6 @@ void GHOST_TabletManagerWin32::getExtraInfo() printf("WinTab version %d.%d (%d.%d)\n", HIBYTE(specV), LOBYTE(specV), HIBYTE(implV), LOBYTE(implV)); - UINT ndevices, ncursors; - func_Info(WTI_INTERFACE, IFC_NDEVICES, &ndevices); - func_Info(WTI_INTERFACE, IFC_NCURSORS, &ncursors); - - printf("%d tablets, %d tools\n", ndevices, ncursors); - if (ndevices > 1) - ; // support this? - - // query for overall capabilities and ranges - char tabletName[LC_NAMELEN]; - if (func_Info(WTI_DEVICES, DVC_NAME, tabletName)) - puts(tabletName); - - puts("\nactive tablet area"); - AXIS xRange, yRange; - func_Info(WTI_DEVICES, DVC_X, &xRange); - func_Info(WTI_DEVICES, DVC_Y, &yRange); - print(xRange,"x"); print(yRange,"y"); - - putchar('\n'); - UINT extensionCount; func_Info(WTI_INTERFACE, IFC_NEXTENSIONS, &extensionCount); for (UINT i = 0; i < extensionCount; ++i) @@ -201,8 +180,84 @@ void GHOST_TabletManagerWin32::getExtraInfo() printf("extension %d: %s\n", i, name); } -// for (int i = cursorBase; i < cursorBase + cursorCount; ++i) - for (UINT i = 0; i < ncursors; ++i) + UINT deviceCount, cursorCount; + func_Info(WTI_INTERFACE, IFC_NDEVICES, &deviceCount); + func_Info(WTI_INTERFACE, IFC_NCURSORS, &cursorCount); + + printf("%d tablets, %d tools\n", deviceCount, cursorCount); + if (deviceCount > 1) + ; // support this? + + for (UINT i = 0; i < deviceCount; ++i) + { + Tablet tablet; + + // query for overall capabilities and ranges + char tabletName[LC_NAMELEN]; + if (func_Info(WTI_DEVICES, DVC_NAME, tabletName)) + printf("tablet %d: %s\n", i, tabletName); + + puts("\nactive tablet area"); + AXIS xRange, yRange; + func_Info(WTI_DEVICES + i, DVC_X, &xRange); + func_Info(WTI_DEVICES + i, DVC_Y, &yRange); + tablet.size_x = xRange.axMax; + tablet.size_y = yRange.axMax; + print(xRange,"x"); print(yRange,"y"); + + func_Info(WTI_DEVICES + i, DVC_NCSRTYPES, &cursorCount); + func_Info(WTI_DEVICES + i, DVC_FIRSTCSR, &cursorBase); + tablet.cursorBase = cursorBase; + tablet.cursorCount = cursorCount; + printf("owns tools %d to %d\n", cursorBase, cursorBase + cursorCount - 1); + + func_Info(WTI_DEVICES + i, DVC_PKTDATA, &allTools); + puts("\nall tools have"); print(allTools); + func_Info(WTI_DEVICES + i, DVC_CSRDATA, &someTools); + puts("some tools also have"); print(someTools); + + puts("\npressure sensitivity"); + AXIS pressureRange; + hasPressure = (allTools|someTools) & PK_NORMAL_PRESSURE + && func_Info(WTI_DEVICES + i, DVC_NPRESSURE, &pressureRange); + + if (hasPressure) + { + print(pressureRange); + pressureScale = 1.f / pressureRange.axMax; + } + else + pressureScale = 0.f; + + puts("\ntilt sensitivity"); + AXIS tiltRange[3]; + hasTilt = (allTools|someTools) & PK_ORIENTATION + && func_Info(WTI_DEVICES + i, DVC_ORIENTATION, &tiltRange); + + if (hasTilt) + { + // leave this code in place to help support tablets I haven't tested + const char* axisName[] = {"azimuth","altitude","twist"}; + for (int i = 0; i < 3; ++i) + print(tiltRange[i], axisName[i]); + + // cheat by using available data from Intuos4. test on other tablets!!! + // azimuthScale = 1.f / HIWORD(tiltRange[1].axResolution); + // altitudeScale = 1.f / tiltRange[1].axMax; + + azimuthScale = 1.f / tiltRange[0].axMax; + altitudeScale = 1.f / tiltRange[1].axMax; + } + else + { + puts("none"); + azimuthScale = altitudeScale = 0.f; + } + + tablets.push_back(tablet); + } + + for (UINT i = 0; i < cursorCount; ++i) { // what can each cursor do? @@ -415,6 +470,13 @@ bool GHOST_TabletManagerWin32::processPackets(GHOST_WindowWin32* window) int y = packet.pkY; if (activeTool.type == TABLET_MOUSE) + { + // until scaling is working better, use system cursor position instead + POINT systemPos; + GetCursorPos(&systemPos); + x = systemPos.x; + y = systemPos.y; + if (x == prevMouseX && y == prevMouseY && packet.pkButtons == prevButtons) // don't send any "mouse hasn't moved" events continue; @@ -422,6 +484,7 @@ bool GHOST_TabletManagerWin32::processPackets(GHOST_WindowWin32* window) prevMouseX = x; prevMouseY = y; } + } anyProcessed = true; @@ -601,6 +664,7 @@ void GHOST_TabletManagerWin32::changeTool(GHOST_WindowWin32* window, UINT serial activeTool.type = TABLET_NONE; } +//#if 0 // now try another way func_Info(WTI_CURSORS + packet.pkCursor, CSR_TYPE, &cursorType); switch (cursorType & 0xf06) @@ -623,6 +687,7 @@ void GHOST_TabletManagerWin32::changeTool(GHOST_WindowWin32* window, UINT serial default: puts("???"); } +//#endif WTPKT toolData; func_Info(WTI_CURSORS + packet.pkCursor, CSR_PKTDATA, &toolData); diff --git a/intern/ghost/intern/GHOST_TabletManagerWin32.h b/intern/ghost/intern/GHOST_TabletManagerWin32.h index 835711bb6c4..df6f43d0460 100644 --- a/intern/ghost/intern/GHOST_TabletManagerWin32.h +++ b/intern/ghost/intern/GHOST_TabletManagerWin32.h @@ -9,6 +9,7 @@ #include <windows.h> #include "wintab.h" #include <map> +#include <vector> #include "GHOST_Types.h" class GHOST_WindowWin32; @@ -22,6 +23,10 @@ typedef int ( API * WTPACKETSGET ) ( HCTX, int, LPVOID ); typedef BOOL ( API * WTPACKET ) ( HCTX, UINT, LPVOID ); // END +// TabletToolData (and its components) are meant to replace GHOST_TabletData +// and its customdata analogue in the window manager. For now it's confined to the +// TabletManager. + typedef enum { TABLET_NONE, TABLET_PEN, TABLET_ERASER, TABLET_MOUSE } TabletToolType; typedef struct @@ -31,7 +36,7 @@ typedef struct // capabilities bool hasPressure : 1; bool hasTilt : 1; - + } TabletTool; @@ -45,6 +50,30 @@ typedef struct } TabletToolData; +// "Tablet" structure is not active by pencils down +// but will be soon. + +struct Tablet + { + bool hasPressure; + float pressureScale; + + bool hasTilt; + float azimuthScale; + float altitudeScale; + + UINT size_x, size_y; + + UINT cursorCount; + UINT cursorBase; + + WTPKT allTools; // standard info available from any tool (mouse/pen/etc.) + WTPKT someTools; // extra info available from only some tools + + bool ownsCursor(UINT x) + { return (x - cursorBase) < cursorCount; } + }; + class GHOST_TabletManagerWin32 { // the Wintab library @@ -78,6 +107,8 @@ class GHOST_TabletManagerWin32 std::map<GHOST_WindowWin32*,HCTX> contexts; HCTX contextForWindow(GHOST_WindowWin32*); + std::vector<Tablet> tablets; + GHOST_WindowWin32* activeWindow; TabletTool activeTool; BYTE sysButtonMap[32]; // user's custom button assignments for active tool |