Fix Wintab button tracking logic.

Shifted flag for buttons changed was incorrectly compared with
unshifted packet flag to determine button press state.

Also fix button tracking storage; button flags are 32 bits whereas the
member variable was 8.

Differential Revision: https://developer.blender.org/D14915
This commit is contained in:
Nicholas Rishel 2022-05-06 23:33:59 -07:00
parent db5ffdd1a4
commit e230ccaf8c
2 changed files with 9 additions and 12 deletions

View File

@ -310,7 +310,7 @@ void GHOST_Wintab::getInput(std::vector<GHOST_WintabInfoWin32> &outWintabInfo)
outWintabInfo.reserve(numPackets);
for (int i = 0; i < numPackets; i++) {
PACKET pkt = m_pkts[i];
const PACKET pkt = m_pkts[i];
GHOST_WintabInfoWin32 out;
/* % 3 for multiple devices ("DualTrack"). */
@ -367,11 +367,12 @@ void GHOST_Wintab::getInput(std::vector<GHOST_WintabInfoWin32> &outWintabInfo)
/* Some Wintab libraries don't handle relative button input, so we track button presses
* manually. */
DWORD buttonsChanged = m_buttons ^ pkt.pkButtons;
WORD buttonIndex = 0;
/* We only needed the prior button state to compare to current, so we can overwrite it now. */
m_buttons = pkt.pkButtons;
while (buttonsChanged) {
/* Iterate over button flag indices until all flags are clear. */
for (WORD buttonIndex = 0; buttonsChanged; buttonIndex++, buttonsChanged >>= 1) {
if (buttonsChanged & 1) {
/* Find the index for the changed button from the button map. */
GHOST_TButtonMask button = mapWintabToGhostButton(pkt.pkCursor, buttonIndex);
if (button != GHOST_kButtonMaskNone) {
@ -381,15 +382,11 @@ void GHOST_Wintab::getInput(std::vector<GHOST_WintabInfoWin32> &outWintabInfo)
}
out.button = button;
out.type = buttonsChanged & pkt.pkButtons ? GHOST_kEventButtonDown :
GHOST_kEventButtonUp;
DWORD buttonFlag = 1 << buttonIndex;
out.type = pkt.pkButtons & buttonFlag ? GHOST_kEventButtonDown : GHOST_kEventButtonUp;
}
m_buttons ^= 1 << buttonIndex;
}
buttonsChanged >>= 1;
buttonIndex++;
}
outWintabInfo.push_back(out);

View File

@ -187,7 +187,7 @@ class GHOST_Wintab {
bool m_focused = false;
/** Pressed button map. */
uint8_t m_buttons = 0;
DWORD m_buttons = 0;
/** Range of a coordinate space. */
struct Range {