Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Rishel <rishel.nick@gmail.com>2022-05-19 10:07:02 +0300
committerNicholas Rishel <rishel.nick@gmail.com>2022-05-19 10:10:25 +0300
commit2ffd8cfd3a9d965ea996e54429a782f3edf79e43 (patch)
tree00eaf94718e8b4cdb64c043df886d81ea31cdb3e
parente5f337aa010bce83ee0bd52b21ab7ad8a2cccf86 (diff)
Add test for Wintab with change detection.wintab
-rw-r--r--intern/ghost/intern/GHOST_Wintab.cpp87
-rw-r--r--intern/ghost/intern/GHOST_Wintab.h2
2 files changed, 55 insertions, 34 deletions
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>