Blender  V3.3
GHOST_Wintab.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 /* Wacom's Wintab documentation is periodically offline, moved, and increasingly hidden away. You
9  * can find a (painstakingly) archived copy of the documentation at
10  * https://web.archive.org/web/20201122230125/https://developer-docs-legacy.wacom.com/display/DevDocs/Windows+Wintab+Documentation
11  */
12 
13 #pragma once
14 
15 #include <memory>
16 #include <stdio.h>
17 #include <vector>
18 #include <wtypes.h>
19 
20 #include "GHOST_Types.h"
21 
22 #include <wintab.h>
23 /* PACKETDATA and PACKETMODE modify structs in pktdef.h, so make sure they come first. */
24 #define PACKETDATA \
25  (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR | PK_X | PK_Y | PK_TIME)
26 #define PACKETMODE 0
27 #include <pktdef.h>
28 
29 #define WINTAB_PRINTF(x, ...) \
30  { \
31  if (GHOST_Wintab::getDebug()) { \
32  printf(x, __VA_ARGS__); \
33  } \
34  } \
35  (void)0
36 
37 /* Typedefs for Wintab functions to allow dynamic loading. */
38 typedef UINT(API *GHOST_WIN32_WTInfo)(UINT, UINT, LPVOID);
39 typedef BOOL(API *GHOST_WIN32_WTGet)(HCTX, LPLOGCONTEXTA);
40 typedef BOOL(API *GHOST_WIN32_WTSet)(HCTX, LPLOGCONTEXTA);
41 typedef HCTX(API *GHOST_WIN32_WTOpen)(HWND, LPLOGCONTEXTA, BOOL);
42 typedef BOOL(API *GHOST_WIN32_WTClose)(HCTX);
43 typedef int(API *GHOST_WIN32_WTPacketsGet)(HCTX, int, LPVOID);
44 typedef int(API *GHOST_WIN32_WTQueueSizeGet)(HCTX);
45 typedef BOOL(API *GHOST_WIN32_WTQueueSizeSet)(HCTX, int);
46 typedef BOOL(API *GHOST_WIN32_WTEnable)(HCTX, BOOL);
47 typedef BOOL(API *GHOST_WIN32_WTOverlap)(HCTX, BOOL);
48 
49 /* Typedefs for Wintab and Windows resource management. */
50 typedef std::unique_ptr<std::remove_pointer_t<HMODULE>, decltype(&::FreeLibrary)> unique_hmodule;
51 typedef std::unique_ptr<std::remove_pointer_t<HCTX>, GHOST_WIN32_WTClose> unique_hctx;
52 
54  int32_t x = 0;
55  int32_t y = 0;
60 };
61 
62 class GHOST_Wintab {
63  public:
69  static GHOST_Wintab *loadWintab(HWND hwnd);
70 
71  ~GHOST_Wintab();
72 
76  void enable();
77 
81  void disable();
82 
86  void gainFocus();
87 
91  void loseFocus();
92 
96  void leaveRange();
97 
101  void remapCoordinates();
102 
110  void mapWintabToSysCoordinates(int x_in, int y_in, int &x_out, int &y_out);
111 
115  void updateCursorInfo();
116 
121  void processInfoChange(LPARAM lParam);
122 
127  bool devicesPresent();
128 
133  void getInput(std::vector<GHOST_WintabInfoWin32> &outWintabInfo);
134 
139  bool trustCoordinates();
140 
153  bool testCoordinates(int sysX, int sysY, int wtX, int wtY);
154 
160 
161  /* Sets Wintab debugging.
162  * \param debug: True to enable Wintab debugging.
163  */
164  static void setDebug(bool debug);
165 
166  /* Returns whether Wintab logging should occur.
167  * \return True if Wintab logging should occur.
168  */
169  static bool getDebug();
170 
171  private:
173  unique_hmodule m_handle;
175  GHOST_WIN32_WTInfo m_fpInfo = nullptr;
176  GHOST_WIN32_WTGet m_fpGet = nullptr;
177  GHOST_WIN32_WTSet m_fpSet = nullptr;
178  GHOST_WIN32_WTPacketsGet m_fpPacketsGet = nullptr;
179  GHOST_WIN32_WTEnable m_fpEnable = nullptr;
180  GHOST_WIN32_WTOverlap m_fpOverlap = nullptr;
181 
183  unique_hctx m_context;
185  bool m_enabled = false;
187  bool m_focused = false;
188 
190  DWORD m_buttons = 0;
191 
193  struct Range {
195  int org = 0;
197  int ext = 1;
198  };
199 
201  struct Coord {
203  Range x = {};
205  Range y = {};
206  };
208  bool m_coordTrusted = false;
210  Coord m_tabletCoord = {};
212  Coord m_systemCoord = {};
213 
214  int m_maxPressure = 0;
215  int m_maxAzimuth = 0;
216  int m_maxAltitude = 0;
217 
219  UINT m_numDevices = 0;
221  std::vector<PACKET> m_pkts;
223  GHOST_TabletData m_lastTabletData = GHOST_TABLET_DATA_NONE;
224 
226  static bool m_debug;
227 
229  GHOST_WIN32_WTInfo info,
230  GHOST_WIN32_WTGet get,
231  GHOST_WIN32_WTSet set,
232  GHOST_WIN32_WTPacketsGet packetsGet,
234  GHOST_WIN32_WTOverlap overlap,
235  unique_hctx hctx,
236  Coord tablet,
237  Coord system,
238  int queueSize);
239 
246  GHOST_TButton mapWintabToGhostButton(UINT cursor, WORD physicalButton);
247 
252  static void modifyContext(LOGCONTEXT &lc);
253 
260  static void extractCoordinates(LOGCONTEXT &lc, Coord &tablet, Coord &system);
261 
262  /* Prints Wintab Context information. */
263  void printContextDebugInfo();
264 };
GHOST_TEventType
Definition: GHOST_Types.h:169
@ GHOST_kEventCursorMove
Definition: GHOST_Types.h:172
static const GHOST_TabletData GHOST_TABLET_DATA_NONE
Definition: GHOST_Types.h:104
GHOST_TButton
Definition: GHOST_Types.h:156
@ GHOST_kButtonMaskNone
Definition: GHOST_Types.h:157
typedef UINT(API *GHOST_WIN32_GetDpiForWindow)(HWND)
BOOL(API * GHOST_WIN32_WTOverlap)(HCTX, BOOL)
Definition: GHOST_Wintab.h:47
BOOL(API * GHOST_WIN32_WTEnable)(HCTX, BOOL)
Definition: GHOST_Wintab.h:46
std::unique_ptr< std::remove_pointer_t< HCTX >, GHOST_WIN32_WTClose > unique_hctx
Definition: GHOST_Wintab.h:51
HCTX(API * GHOST_WIN32_WTOpen)(HWND, LPLOGCONTEXTA, BOOL)
Definition: GHOST_Wintab.h:41
BOOL(API * GHOST_WIN32_WTClose)(HCTX)
Definition: GHOST_Wintab.h:42
BOOL(API * GHOST_WIN32_WTGet)(HCTX, LPLOGCONTEXTA)
Definition: GHOST_Wintab.h:39
std::unique_ptr< std::remove_pointer_t< HMODULE >, decltype(&::FreeLibrary)> unique_hmodule
Definition: GHOST_Wintab.h:50
BOOL(API * GHOST_WIN32_WTQueueSizeSet)(HCTX, int)
Definition: GHOST_Wintab.h:45
BOOL(API * GHOST_WIN32_WTSet)(HCTX, LPLOGCONTEXTA)
Definition: GHOST_Wintab.h:40
UINT(API * GHOST_WIN32_WTInfo)(UINT, UINT, LPVOID)
Definition: GHOST_Wintab.h:38
int(API * GHOST_WIN32_WTPacketsGet)(HCTX, int, LPVOID)
Definition: GHOST_Wintab.h:43
int(API * GHOST_WIN32_WTQueueSizeGet)(HCTX)
Definition: GHOST_Wintab.h:44
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void mapWintabToSysCoordinates(int x_in, int y_in, int &x_out, int &y_out)
GHOST_TabletData getLastTabletData()
bool devicesPresent()
void getInput(std::vector< GHOST_WintabInfoWin32 > &outWintabInfo)
void processInfoChange(LPARAM lParam)
void updateCursorInfo()
void remapCoordinates()
static GHOST_Wintab * loadWintab(HWND hwnd)
bool trustCoordinates()
static bool getDebug()
bool testCoordinates(int sysX, int sysY, int wtX, int wtY)
static void setDebug(bool debug)
signed int int32_t
Definition: stdint.h:77
unsigned __int64 uint64_t
Definition: stdint.h:90
GHOST_TEventType type
Definition: GHOST_Wintab.h:56
GHOST_TabletData tabletData
Definition: GHOST_Wintab.h:59
GHOST_TButton button
Definition: GHOST_Wintab.h:57