[Bf-blender-cvs] [2ffd8cfd3a9] wintab: Add test for Wintab with change detection.

Nicholas Rishel noreply at git.blender.org
Thu May 19 09:11:41 CEST 2022


Commit: 2ffd8cfd3a9d965ea996e54429a782f3edf79e43
Author: Nicholas Rishel
Date:   Thu May 19 00:07:02 2022 -0700
Branches: wintab
https://developer.blender.org/rB2ffd8cfd3a9d965ea996e54429a782f3edf79e43

Add test for Wintab with change detection.

===================================================================

M	intern/ghost/intern/GHOST_Wintab.cpp
M	intern/ghost/intern/GHOST_Wintab.h

===================================================================

diff --git a/intern/ghost/intern/GHOST_Wintab.cpp b/intern/ghost/intern/GHOST_Wintab.cpp
index b136acbe098..d8fca457b9a 100644
--- a/intern/ghost/intern/GHOST_Wintab.cpp
+++ b/intern/ghost/intern/GHOST_Wintab.cpp
@@ -310,31 +310,42 @@ void GHOST_Wintab::getInput(std::vector<GHOST_WintabInfoWin32> &outWintabInfo)
   outWintabInfo.reserve(numPackets);
 
   for (int i = 0; i < numPackets; i++) {
+    static GHOST_WintabInfoWin32 lastPacket;
+    static bool first = true;
     const PACKET pkt = m_pkts[i];
     GHOST_WintabInfoWin32 out;
+    if (!first) {
+      out = lastPacket;
+    }
 
     /* % 3 for multiple devices ("DualTrack"). */
-    switch (pkt.pkCursor % 3) {
-      case 0:
-        /* Puck - processed as mouse. */
-        out.tabletData.Active = GHOST_kTabletModeNone;
-        break;
-      case 1:
-        out.tabletData.Active = GHOST_kTabletModeStylus;
-        break;
-      case 2:
-        out.tabletData.Active = GHOST_kTabletModeEraser;
-        break;
+    if (pkt.pkChanged | PK_CURSOR) {
+      switch (pkt.pkCursor % 3) {
+        case 0:
+          /* Puck - processed as mouse. */
+          out.tabletData.Active = GHOST_kTabletModeNone;
+          break;
+        case 1:
+          out.tabletData.Active = GHOST_kTabletModeStylus;
+          break;
+        case 2:
+          out.tabletData.Active = GHOST_kTabletModeEraser;
+          break;
+      }
     }
 
-    out.x = pkt.pkX;
-    out.y = pkt.pkY;
+    if (pkt.pkChanged | PK_X) {
+      out.x = pkt.pkX;
+    }
+    if (pkt.pkChanged | PK_Y) {
+      out.y = pkt.pkY;
+    }
 
-    if (m_maxPressure > 0) {
+    if (pkt.pkChanged | PK_NORMAL_PRESSURE && m_maxPressure > 0) {
       out.tabletData.Pressure = (float)pkt.pkNormalPressure / (float)m_maxPressure;
     }
 
-    if ((m_maxAzimuth > 0) && (m_maxAltitude > 0)) {
+    if (pkt.pkChanged | PK_ORIENTATION && (m_maxAzimuth > 0) && (m_maxAltitude > 0)) {
       /* From the wintab spec:
        * orAzimuth: Specifies the clockwise rotation of the cursor about the z axis through a
        * full circular range.
@@ -362,34 +373,44 @@ void GHOST_Wintab::getInput(std::vector<GHOST_WintabInfoWin32> &outWintabInfo)
       out.tabletData.Ytilt = (float)(sin(M_PI_2 - azmRad) * vecLen);
     }
 
-    out.time = pkt.pkTime;
+    if (pkt.pkChanged | PK_TIME) {
+      out.time = pkt.pkTime;
+    }
 
-    /* Some Wintab libraries don't handle relative button input, so we track button presses
-     * manually. */
-    DWORD buttonsChanged = m_buttons ^ pkt.pkButtons;
-    /* We only needed the prior button state to compare to current, so we can overwrite it now. */
-    m_buttons = pkt.pkButtons;
+    if (pkt.pkChanged | PK_BUTTONS) {
+      /* Some Wintab libraries don't handle relative button input, so we track button presses
+       * manually. */
+      DWORD buttonsChanged = m_buttons ^ pkt.pkButtons;
+      /* We only needed the prior button state to compare to current, so we can overwrite it now.
+       */
+      m_buttons = pkt.pkButtons;
 
-    /* Iterate over button flag indices until all flags are clear. */
-    for (WORD buttonIndex = 0; buttonsChanged; buttonIndex++, buttonsChanged >>= 1) {
-      if (buttonsChanged & 1) {
-        GHOST_TButtonMask button = mapWintabToGhostButton(pkt.pkCursor, buttonIndex);
+      /* Iterate over button flag indices until all flags are clear. */
+      for (WORD buttonIndex = 0; buttonsChanged; buttonIndex++, buttonsChanged >>= 1) {
+        if (buttonsChanged & 1) {
+          GHOST_TButtonMask button = mapWintabToGhostButton(pkt.pkCursor, buttonIndex);
 
-        if (button != GHOST_kButtonMaskNone) {
-          /* If this is not the first button found, push info for the prior Wintab button. */
-          if (out.button != GHOST_kButtonMaskNone) {
-            outWintabInfo.push_back(out);
-          }
+          if (button != GHOST_kButtonMaskNone) {
+            /* If this is not the first button found, push info for the prior Wintab button. */
+            if (out.button != GHOST_kButtonMaskNone) {
+              outWintabInfo.push_back(out);
+            }
 
-          out.button = button;
+            out.button = button;
 
-          DWORD buttonFlag = 1 << buttonIndex;
-          out.type = pkt.pkButtons & buttonFlag ? GHOST_kEventButtonDown : GHOST_kEventButtonUp;
+            DWORD buttonFlag = 1 << buttonIndex;
+            out.type = pkt.pkButtons & buttonFlag ? GHOST_kEventButtonDown : GHOST_kEventButtonUp;
+          }
         }
       }
     }
 
     outWintabInfo.push_back(out);
+    lastPacket = out;
+    // Reset button data since they represent changed values.
+    lastPacket.button = GHOST_kButtonMaskNone;
+    lastPacket.type = GHOST_kEventCursorMove;
+    first = false;
   }
 
   if (!outWintabInfo.empty()) {
diff --git a/intern/ghost/intern/GHOST_Wintab.h b/intern/ghost/intern/GHOST_Wintab.h
index 80eacf1f3fa..24417324cfa 100644
--- a/intern/ghost/intern/GHOST_Wintab.h
+++ b/intern/ghost/intern/GHOST_Wintab.h
@@ -22,7 +22,7 @@
 #include <wintab.h>
 /* PACKETDATA and PACKETMODE modify structs in pktdef.h, so make sure they come first. */
 #define PACKETDATA \
-  (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR | PK_X | PK_Y | PK_TIME)
+  (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR | PK_X | PK_Y | PK_TIME | PK_CHANGED)
 #define PACKETMODE 0
 #include <pktdef.h>



More information about the Bf-blender-cvs mailing list