Skip to content

Commit

Permalink
Extend JoyGetPos in the WinMM wrapper to output status for all button…
Browse files Browse the repository at this point in the history
…s, even though only 4 buttons are allowed, per documentation.
  • Loading branch information
samuelgr committed Dec 14, 2024
1 parent 37a5518 commit 4659936
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Source/WrapperJoyWinMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,12 @@ namespace Xidi
pji->wYpos = (WORD)joyStateData[Controller::EAxis::Y];
pji->wZpos = (WORD)joyStateData[Controller::EAxis::Z];
pji->wButtons = 0;
if (true == joyStateData.button[0]) pji->wButtons |= JOY_BUTTON1;
if (true == joyStateData.button[1]) pji->wButtons |= JOY_BUTTON2;
if (true == joyStateData.button[2]) pji->wButtons |= JOY_BUTTON3;
if (true == joyStateData.button[3]) pji->wButtons |= JOY_BUTTON4;

constexpr size_t maxButtonIndex = 8 * sizeof(pji->wButtons);
for (size_t i = 0; ((i < joyStateData.button.size()) && (i < maxButtonIndex)); ++i)
{
if (true == joyStateData.button[i]) pji->wButtons |= (1 << i);
}

const MMRESULT result = JOYERR_NOERROR;
LOG_INVOCATION(Infra::Message::ESeverity::SuperDebug, (unsigned int)uJoyID, result);
Expand Down Expand Up @@ -819,7 +821,8 @@ namespace Xidi
pji->dwVpos = joyStateData[Controller::EAxis::RotX];
pji->dwButtons = 0;

for (size_t i = 0; i < joyStateData.button.size(); ++i)
constexpr size_t maxButtonIndex = 8 * sizeof(pji->dwButtons);
for (size_t i = 0; ((i < joyStateData.button.size()) && (i < maxButtonIndex)); ++i)
{
if (true == joyStateData.button[i]) pji->dwButtons |= (1 << i);
}
Expand Down

0 comments on commit 4659936

Please sign in to comment.