diff options
Diffstat (limited to 'intern/ghost/intern/GHOST_WindowWin32.h')
-rw-r--r-- | intern/ghost/intern/GHOST_WindowWin32.h | 199 |
1 files changed, 156 insertions, 43 deletions
diff --git a/intern/ghost/intern/GHOST_WindowWin32.h b/intern/ghost/intern/GHOST_WindowWin32.h index ac1ec0ee852..d4427f67e9b 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.h +++ b/intern/ghost/intern/GHOST_WindowWin32.h @@ -36,8 +36,9 @@ #endif #include <wintab.h> -#define PACKETDATA (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR) -#define PACKETMODE PK_BUTTONS +#define PACKETDATA \ + (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR | PK_X | PK_Y | PK_TIME) +#define PACKETMODE 0 #include <pktdef.h> class GHOST_SystemWin32; @@ -45,9 +46,13 @@ class GHOST_DropTargetWin32; // typedefs for WinTab functions to allow dynamic loading typedef UINT(API *GHOST_WIN32_WTInfo)(UINT, UINT, LPVOID); +typedef BOOL(API *GHOST_WIN32_WTGet)(HCTX, LPLOGCONTEXTA); +typedef BOOL(API *GHOST_WIN32_WTSet)(HCTX, LPLOGCONTEXTA); typedef HCTX(API *GHOST_WIN32_WTOpen)(HWND, LPLOGCONTEXTA, BOOL); typedef BOOL(API *GHOST_WIN32_WTClose)(HCTX); -typedef BOOL(API *GHOST_WIN32_WTPacket)(HCTX, UINT, LPVOID); +typedef BOOL(API *GHOST_WIN32_WTPacketsGet)(HCTX, int, LPVOID); +typedef int(API *GHOST_WIN32_WTQueueSizeGet)(HCTX); +typedef BOOL(API *GHOST_WIN32_WTQueueSizeSet)(HCTX, int); typedef BOOL(API *GHOST_WIN32_WTEnable)(HCTX, BOOL); typedef BOOL(API *GHOST_WIN32_WTOverlap)(HCTX, BOOL); @@ -88,6 +93,26 @@ typedef enum tagPOINTER_BUTTON_CHANGE_TYPE { typedef DWORD POINTER_INPUT_TYPE; typedef UINT32 POINTER_FLAGS; +#define POINTER_FLAG_NONE 0x00000000 +#define POINTER_FLAG_NEW 0x00000001 +#define POINTER_FLAG_INRANGE 0x00000002 +#define POINTER_FLAG_INCONTACT 0x00000004 +#define POINTER_FLAG_FIRSTBUTTON 0x00000010 +#define POINTER_FLAG_SECONDBUTTON 0x00000020 +#define POINTER_FLAG_THIRDBUTTON 0x00000040 +#define POINTER_FLAG_FOURTHBUTTON 0x00000080 +#define POINTER_FLAG_FIFTHBUTTON 0x00000100 +#define POINTER_FLAG_PRIMARY 0x00002000 +#define POINTER_FLAG_CONFIDENCE 0x000004000 +#define POINTER_FLAG_CANCELED 0x000008000 +#define POINTER_FLAG_DOWN 0x00010000 +#define POINTER_FLAG_UPDATE 0x00020000 +#define POINTER_FLAG_UP 0x00040000 +#define POINTER_FLAG_WHEEL 0x00080000 +#define POINTER_FLAG_HWHEEL 0x00100000 +#define POINTER_FLAG_CAPTURECHANGED 0x00200000 +#define POINTER_FLAG_HASTRANSFORM 0x00400000 + typedef struct tagPOINTER_INFO { POINTER_INPUT_TYPE pointerType; UINT32 pointerId; @@ -192,20 +217,40 @@ typedef struct tagPOINTER_TOUCH_INFO { #define IS_POINTER_CANCELED_WPARAM(wParam) \ IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_CANCELED) -typedef BOOL(API *GHOST_WIN32_GetPointerInfo)(UINT32 pointerId, POINTER_INFO *pointerInfo); -typedef BOOL(API *GHOST_WIN32_GetPointerPenInfo)(UINT32 pointerId, POINTER_PEN_INFO *penInfo); -typedef BOOL(API *GHOST_WIN32_GetPointerTouchInfo)(UINT32 pointerId, POINTER_TOUCH_INFO *penInfo); +typedef BOOL(WINAPI *GHOST_WIN32_GetPointerInfoHistory)(UINT32 pointerId, + UINT32 *entriesCount, + POINTER_INFO *pointerInfo); +typedef BOOL(WINAPI *GHOST_WIN32_GetPointerPenInfoHistory)(UINT32 pointerId, + UINT32 *entriesCount, + POINTER_PEN_INFO *penInfo); +typedef BOOL(WINAPI *GHOST_WIN32_GetPointerTouchInfoHistory)(UINT32 pointerId, + UINT32 *entriesCount, + POINTER_TOUCH_INFO *touchInfo); struct GHOST_PointerInfoWin32 { GHOST_TInt32 pointerId; - GHOST_TInt32 isInContact; GHOST_TInt32 isPrimary; - GHOST_TSuccess hasButtonMask; GHOST_TButtonMask buttonMask; POINT pixelLocation; + GHOST_TUns64 time; + GHOST_TabletData tabletData; +}; + +struct GHOST_WintabInfoWin32 { + GHOST_TInt32 x, y; + GHOST_TEventType type; + GHOST_TButtonMask button; + GHOST_TUns64 time; GHOST_TabletData tabletData; }; +typedef enum { + MousePressed, + MouseReleased, + OperatorGrab, + OperatorUngrab +} GHOST_MouseCaptureEventWin32; + /** * GHOST window on M$ Windows OSs. */ @@ -364,17 +409,14 @@ class GHOST_WindowWin32 : public GHOST_Window { GHOST_TSuccess endProgressBar(); /** - * Register a mouse click event (should be called + * Register a mouse capture state (should be called * for any real button press, controls mouse * capturing). * - * \param press - * 0 - mouse pressed - * 1 - mouse released - * 2 - operator grab - * 3 - operator ungrab + * \param event Whether mouse was pressed and released, or an operator grabbed or ungrabbed the + * mouse */ - void registerMouseClickEvent(int press); + void updateMouseCapture(GHOST_MouseCaptureEventWin32 event); /** * Inform the window that it has lost mouse capture, @@ -392,20 +434,50 @@ class GHOST_WindowWin32 : public GHOST_Window { HCURSOR getStandardCursor(GHOST_TStandardCursor shape) const; void loadCursor(bool visible, GHOST_TStandardCursor cursorShape) const; - const GHOST_TabletData &GetTabletData() - { - return m_tabletData; - } + /** + * Handle setup and switch between Wintab and Pointer APIs + * \param active Whether the window is or will be in an active state + */ + void updateWintab(bool active); - void setTabletData(GHOST_TabletData *tabletData); + /** + * Query whether given tablet API should be used. + * \param api Tablet API to test. + */ bool useTabletAPI(GHOST_TTabletAPI api) const; - void getPointerInfo(WPARAM wParam); - void processWin32PointerEvent(WPARAM wParam); - void processWin32TabletActivateEvent(WORD state); - void processWin32TabletInitEvent(); - void processWin32TabletEvent(WPARAM wParam, LPARAM lParam); - void bringTabletContextToFront(); + /** + * Translate WM_POINTER events into GHOST_PointerInfoWin32 structs. + * \param outPointerInfo Storage to return resulting GHOST_PointerInfoWin32 structs + * \param wParam WPARAM of the event + * \param lParam LPARAM of the event + */ + GHOST_TSuccess getPointerInfo(std::vector<GHOST_PointerInfoWin32> &outPointerInfo, + WPARAM wParam, + LPARAM lParam); + + /** + * Handle Wintab coordinate changes when DisplayChange events occur. + */ + void processWintabDisplayChangeEvent(); + + /** + * Set tablet details when a cursor enters range + */ + void processWintabProximityEvent(bool inRange); + + /** + * Handle Wintab info changes such as change in number of connected tablets. + * \param lParam LPARAM of the event + */ + void processWintabInfoChangeEvent(LPARAM lParam); + + /** + * Translate Wintab packets into GHOST_WintabInfoWin32 structs. + * \param outWintabInfo Storage to return resulting GHOST_WintabInfoWin32 structs + * \return Success if able to read packets, even if there are none + */ + GHOST_TSuccess getWintabInfo(std::vector<GHOST_WintabInfoWin32> &outWintabInfo); GHOST_TSuccess beginFullScreen() const { @@ -419,7 +491,27 @@ class GHOST_WindowWin32 : public GHOST_Window { GHOST_TUns16 getDPIHint() override; - GHOST_TSuccess getPointerInfo(GHOST_PointerInfoWin32 *pointerInfo, WPARAM wParam, LPARAM lParam); + /** + * Get whether there are currently any mouse buttons pressed + * \return True if there are any currently pressed mouse buttons + */ + bool getMousePressed() const; + + /** + * Get if there are currently pressed Wintab buttons associated to a Windows mouse button press + * \return True if there are currently any pressed Wintab buttons associated to a Windows + * mouse button press + */ + bool wintabSysButPressed() const; + + /** + * Register a Wintab button has been associated to a Windows mouse button press + * \param event Whether the button was pressed or released + */ + void updateWintabSysBut(GHOST_MouseCaptureEventWin32 event); + + /** Whether a tablet stylus is being tracked */ + bool m_tabletInRange; /** if the window currently resizing */ bool m_inLiveResize; @@ -501,35 +593,56 @@ class GHOST_WindowWin32 : public GHOST_Window { static const wchar_t *s_windowClassName; static const int s_maxTitleLength; - /** Tablet data for GHOST */ - GHOST_TabletData m_tabletData; - /* Wintab API */ struct { /** WinTab dll handle */ - HMODULE handle; + HMODULE handle = NULL; /** API functions */ - GHOST_WIN32_WTInfo info; - GHOST_WIN32_WTOpen open; - GHOST_WIN32_WTClose close; - GHOST_WIN32_WTPacket packet; - GHOST_WIN32_WTEnable enable; - GHOST_WIN32_WTOverlap overlap; + GHOST_WIN32_WTInfo info = NULL; + GHOST_WIN32_WTGet get = NULL; + GHOST_WIN32_WTSet set = NULL; + GHOST_WIN32_WTOpen open = NULL; + GHOST_WIN32_WTClose close = NULL; + GHOST_WIN32_WTPacketsGet packetsGet = NULL; + GHOST_WIN32_WTQueueSizeGet queueSizeGet = NULL; + GHOST_WIN32_WTQueueSizeSet queueSizeSet = NULL; + GHOST_WIN32_WTEnable enable = NULL; + GHOST_WIN32_WTOverlap overlap = NULL; /** Stores the Tablet context if detected Tablet features using WinTab.dll */ - HCTX tablet; - LONG maxPressure; - LONG maxAzimuth, maxAltitude; + HCTX context = NULL; + /** Number of connected Wintab digitizers */ + UINT numDevices = 0; + /** Number of cursors currently in contact mapped to system buttons */ + GHOST_TUns8 numSysButtons = 0; + /** Cursors currently in contact mapped to system buttons */ + DWORD sysButtonsPressed = 0; + LONG maxPressure = 0; + LONG maxAzimuth = 0, maxAltitude = 0; + /* Queue size doesn't change once set, so reuse the same buffer */ + std::vector<PACKET> pkts; } m_wintab; + /** + * Wintab setup + */ + void initializeWintab(); + + /** + * Convert Wintab system mapped (mouse) buttons into Ghost button mask + */ + GHOST_TSuccess wintabMouseToGhost(UINT cursor, + DWORD physicalButton, + GHOST_TButtonMask &buttonMask); + GHOST_TWindowState m_normal_state; /** user32 dll handle*/ HMODULE m_user32; - GHOST_WIN32_GetPointerInfo m_fpGetPointerInfo; - GHOST_WIN32_GetPointerPenInfo m_fpGetPointerPenInfo; - GHOST_WIN32_GetPointerTouchInfo m_fpGetPointerTouchInfo; + GHOST_WIN32_GetPointerInfoHistory m_fpGetPointerInfoHistory; + GHOST_WIN32_GetPointerPenInfoHistory m_fpGetPointerPenInfoHistory; + GHOST_WIN32_GetPointerTouchInfoHistory m_fpGetPointerTouchInfoHistory; HWND m_parentWindowHwnd; |