Browse Source

Platform: fix EmscriptenApplication mouse events with Emscripten master.

The canvasX/Y properties were silently deprecated (I wouldn't know
without looking at the source, the docs say no such thing) and when
-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 is enabled, these are
not initialized to any meaningful value.
pull/415/head
Vladimír Vondruš 6 years ago
parent
commit
e603771cef
  1. 3
      doc/changelog.dox
  2. 24
      src/Magnum/Platform/EmscriptenApplication.cpp

3
doc/changelog.dox

@ -172,6 +172,9 @@ See also:
@ref Platform::EmscriptenApplication::KeyEvent::Key::Semicolon "Key::Semicolon" and @ref Platform::EmscriptenApplication::KeyEvent::Key::Semicolon "Key::Semicolon" and
@ref Platform::EmscriptenApplication::KeyEvent::Key::Backquote "Key::Backquote" @ref Platform::EmscriptenApplication::KeyEvent::Key::Backquote "Key::Backquote"
in @ref Platform::EmscriptenApplication in @ref Platform::EmscriptenApplication
- Fixed broken @ref Platform::EmscriptenApplication mouse event coordinates
when `-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1` is enabled (see
[mosra/magnum#408](https://github.com/mosra/magnum/issues/408))
@subsection changelog-latest-deprecated Deprecated APIs @subsection changelog-latest-deprecated Deprecated APIs

24
src/Magnum/Platform/EmscriptenApplication.cpp

@ -476,10 +476,13 @@ void EmscriptenApplication::setupCallbacks(bool resizable) {
emscripten_set_mousemove_callback("#canvas", this, false, emscripten_set_mousemove_callback("#canvas", this, false,
([](int, const EmscriptenMouseEvent* event, void* userData) -> Int { ([](int, const EmscriptenMouseEvent* event, void* userData) -> Int {
auto& app = *static_cast<EmscriptenApplication*>(userData); auto& app = *static_cast<EmscriptenApplication*>(userData);
/* Avoid bogus offset at first -- report 0 when the event is called /* With DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR, canvasX/Y is
for the first time */ not initialized, so we have to rely on the target being the
Vector2i position{Int(event->canvasX), Int(event->canvasY)}; canvas. That's always true for mouse events. */
Vector2i position{Int(event->targetX), Int(event->targetY)};
MouseMoveEvent e{*event, MouseMoveEvent e{*event,
/* Avoid bogus offset at first -- report 0 when the event is
called for the first time. */
app._previousMouseMovePosition == Vector2i{-1} ? Vector2i{} : app._previousMouseMovePosition == Vector2i{-1} ? Vector2i{} :
position - app._previousMouseMovePosition}; position - app._previousMouseMovePosition};
app._previousMouseMovePosition = position; app._previousMouseMovePosition = position;
@ -735,7 +738,10 @@ EmscriptenApplication::MouseEvent::Button EmscriptenApplication::MouseEvent::but
} }
Vector2i EmscriptenApplication::MouseEvent::position() const { Vector2i EmscriptenApplication::MouseEvent::position() const {
return {Int(_event.canvasX), Int(_event.canvasY)}; /* With DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR, canvasX/Y is not
initialized, so we have to rely on the target being the canvas. That's
always true for mouse events. */
return {Int(_event.targetX), Int(_event.targetY)};
} }
EmscriptenApplication::MouseEvent::Modifiers EmscriptenApplication::MouseEvent::modifiers() const { EmscriptenApplication::MouseEvent::Modifiers EmscriptenApplication::MouseEvent::modifiers() const {
@ -752,7 +758,10 @@ EmscriptenApplication::MouseMoveEvent::Buttons EmscriptenApplication::MouseMoveE
} }
Vector2i EmscriptenApplication::MouseMoveEvent::position() const { Vector2i EmscriptenApplication::MouseMoveEvent::position() const {
return {Int(_event.canvasX), Int(_event.canvasY)}; /* With DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR, canvasX/Y is not
initialized, so we have to rely on the target being the canvas. That's
always true for mouse events. */
return {Int(_event.targetX), Int(_event.targetY)};
} }
EmscriptenApplication::MouseMoveEvent::Modifiers EmscriptenApplication::MouseMoveEvent::modifiers() const { EmscriptenApplication::MouseMoveEvent::Modifiers EmscriptenApplication::MouseMoveEvent::modifiers() const {
@ -778,7 +787,10 @@ Vector2 EmscriptenApplication::MouseScrollEvent::offset() const {
} }
Vector2i EmscriptenApplication::MouseScrollEvent::position() const { Vector2i EmscriptenApplication::MouseScrollEvent::position() const {
return {Int(_event.mouse.canvasX), Int(_event.mouse.canvasY)}; /* With DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR, canvasX/Y is not
initialized, so we have to rely on the target being the canvas. That's
always true for mouse events. */
return {Int(_event.mouse.targetX), Int(_event.mouse.targetY)};
} }
EmscriptenApplication::InputEvent::Modifiers EmscriptenApplication::MouseScrollEvent::modifiers() const { EmscriptenApplication::InputEvent::Modifiers EmscriptenApplication::MouseScrollEvent::modifiers() const {

Loading…
Cancel
Save