Browse Source

Platform: expose MouseButton4 and 5 in EmscriptenApplication.

And the spec is again a total mess, as those are listed in the singular
button field, but not the buttons bitmask.
pull/651/head
Vladimír Vondruš 2 years ago
parent
commit
4773fc20a6
  1. 17
      src/Magnum/Platform/EmscriptenApplication.cpp
  2. 8
      src/Magnum/Platform/EmscriptenApplication.h
  3. 4
      src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp

17
src/Magnum/Platform/EmscriptenApplication.cpp

@ -512,6 +512,10 @@ EmscriptenApplication::Pointer buttonToPointer(const std::int32_t button) {
return EmscriptenApplication::Pointer::MouseMiddle;
case 2:
return EmscriptenApplication::Pointer::MouseRight;
case 3:
return EmscriptenApplication::Pointer::MouseButton4;
case 4:
return EmscriptenApplication::Pointer::MouseButton5;
}
/* W3C spec allows other, platform-specific buttons:
@ -532,6 +536,19 @@ EmscriptenApplication::Pointers buttonsToPointers(const std::uint32_t buttons) {
pointers |= EmscriptenApplication::Pointer::MouseMiddle;
if(buttons & (1 << 1))
pointers |= EmscriptenApplication::Pointer::MouseRight;
/* https://www.w3.org/TR/uievents/#dom-mouseevent-buttons doesn't list
those even though the X1 and X2 buttons from
https://www.w3.org/TR/uievents/#dom-mouseevent-button
don't have any matching value here. In addition to the order swap and
the spec trying to describe bit flags in a *really* roundabout and
complicated way, this isn't entirely surprising. Chrome reports the
extra buttons, and the bit flags match here as well, so assume that's
correct. Firefox doesn't report X1 and X2 at all, so they're not present
here either. */
if(buttons & (1 << 3))
pointers |= EmscriptenApplication::Pointer::MouseButton4;
if(buttons & (1 << 4))
pointers |= EmscriptenApplication::Pointer::MouseButton5;
return pointers;
}

8
src/Magnum/Platform/EmscriptenApplication.h

@ -1057,7 +1057,13 @@ enum class EmscriptenApplication::Pointer: UnsignedByte {
MouseMiddle = 1 << 1,
/** Right mouse button */
MouseRight = 1 << 2
MouseRight = 1 << 2,
/** Fourth mouse button, such as wheel left */
MouseButton4 = 1 << 3,
/** Fourth mouse button, such as wheel right */
MouseButton5 = 1 << 4,
};
CORRADE_ENUMSET_OPERATORS(EmscriptenApplication::Pointers)

4
src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp

@ -73,6 +73,8 @@ static Debug& operator<<(Debug& debug, Application::Pointer value) {
_c(MouseLeft)
_c(MouseMiddle)
_c(MouseRight)
_c(MouseButton4)
_c(MouseButton5)
#undef _c
}
@ -113,6 +115,8 @@ Debug& operator<<(Debug& debug, Application::Pointers value) {
Application::Pointer::MouseLeft,
Application::Pointer::MouseMiddle,
Application::Pointer::MouseRight,
Application::Pointer::MouseButton4,
Application::Pointer::MouseButton5,
});
}

Loading…
Cancel
Save