Browse Source

Platform: implement AndroidApplication::MouseMoveEvent::relativePosition().

pull/388/head
Vladimír Vondruš 7 years ago
parent
commit
9fad16182e
  1. 11
      doc/changelog.dox
  2. 10
      src/Magnum/Platform/AndroidApplication.cpp
  3. 15
      src/Magnum/Platform/AndroidApplication.h

11
doc/changelog.dox

@ -518,11 +518,12 @@ See also:
[mosra/magnum#332](https://github.com/mosra/magnum/pull/332)) [mosra/magnum#332](https://github.com/mosra/magnum/pull/332))
- @ref Platform::Sdl2Application::mainLoopIteration() now returns a - @ref Platform::Sdl2Application::mainLoopIteration() now returns a
@cpp bool @ce to indicate if the application should exit @cpp bool @ce to indicate if the application should exit
- @ref Platform::GlfwApplication and @ref Platform::EmscriptenApplication now - @ref Platform::GlfwApplication, @ref Platform::EmscriptenApplication and
implement @ref Platform::GlfwApplication::MouseMoveEvent::relativePosition() @ref Platform::AndroidApplication now implement
as well for better compatibility with @ref Platform::Sdl2Application. The @ref Platform::GlfwApplication::MouseMoveEvent::relativePosition() as well
relative position is not supplied by the underlying toolkits, so it's for better compatibility with @ref Platform::Sdl2Application. The relative
emulated on the application side. position is not supplied by the underlying toolkits, so it's emulated on
the application side.
- Extended @ref Platform::BasicScreen with - Extended @ref Platform::BasicScreen with
@ref Platform::BasicScreen::mouseScrollEvent() "mouseScrollEvent()", @ref Platform::BasicScreen::mouseScrollEvent() "mouseScrollEvent()",
@ref Platform::BasicScreen::textInputEvent() "textInputEvent()" and @ref Platform::BasicScreen::textInputEvent() "textInputEvent()" and

10
src/Magnum/Platform/AndroidApplication.cpp

@ -250,13 +250,21 @@ std::int32_t AndroidApplication::inputEvent(android_app* state, AInputEvent* eve
switch(action) { switch(action) {
case AMOTION_EVENT_ACTION_DOWN: case AMOTION_EVENT_ACTION_DOWN:
case AMOTION_EVENT_ACTION_UP: { case AMOTION_EVENT_ACTION_UP: {
/* On a touch screen move events aren't reported when the
finger is moving above (of course), so remember the position
always */
app._previousMouseMovePosition = {Int(AMotionEvent_getX(event, 0)), Int(AMotionEvent_getY(event, 0))};
MouseEvent e(event); MouseEvent e(event);
action == AMOTION_EVENT_ACTION_DOWN ? app.mousePressEvent(e) : app.mouseReleaseEvent(e); action == AMOTION_EVENT_ACTION_DOWN ? app.mousePressEvent(e) : app.mouseReleaseEvent(e);
return e.isAccepted() ? 1 : 0; return e.isAccepted() ? 1 : 0;
} }
case AMOTION_EVENT_ACTION_MOVE: { case AMOTION_EVENT_ACTION_MOVE: {
MouseMoveEvent e(event); Vector2i position{Int(AMotionEvent_getX(event, 0)), Int(AMotionEvent_getY(event, 0))};
MouseMoveEvent e{event,
app._previousMouseMovePosition == Vector2i{-1} ? Vector2i{} :
position - app._previousMouseMovePosition};
app._previousMouseMovePosition = position;
app.mouseMoveEvent(e); app.mouseMoveEvent(e);
return e.isAccepted() ? 1 : 0; return e.isAccepted() ? 1 : 0;
} }

15
src/Magnum/Platform/AndroidApplication.h

@ -418,6 +418,7 @@ class AndroidApplication {
EGLDisplay _display; EGLDisplay _display;
EGLSurface _surface; EGLSurface _surface;
EGLContext _glContext; EGLContext _glContext;
Vector2i _previousMouseMovePosition{-1};
Containers::Pointer<Platform::GLContext> _context; Containers::Pointer<Platform::GLContext> _context;
Containers::Pointer<LogOutput> _logOutput; Containers::Pointer<LogOutput> _logOutput;
@ -765,6 +766,16 @@ class AndroidApplication::MouseMoveEvent: public InputEvent {
Int(AMotionEvent_getY(_event, 0))}; Int(AMotionEvent_getY(_event, 0))};
} }
/**
* @brief Relative position
*
* Position relative to previous move event. Unlike
* @ref Sdl2Application, Android APIs don't provide relative position
* directly, so this is calculated explicitly as a delta from previous
* move event position.
*/
Vector2i relativePosition() const { return _relativePosition; }
/** @brief Mouse buttons */ /** @brief Mouse buttons */
Buttons buttons() const { Buttons buttons() const {
#if __ANDROID_API__ >= 14 #if __ANDROID_API__ >= 14
@ -775,7 +786,9 @@ class AndroidApplication::MouseMoveEvent: public InputEvent {
} }
private: private:
explicit MouseMoveEvent(AInputEvent* event): InputEvent(event) {} explicit MouseMoveEvent(AInputEvent* event, Vector2i relativePosition): InputEvent{event}, _relativePosition{relativePosition} {}
const Vector2i _relativePosition;
}; };
CORRADE_ENUMSET_OPERATORS(AndroidApplication::MouseMoveEvent::Buttons) CORRADE_ENUMSET_OPERATORS(AndroidApplication::MouseMoveEvent::Buttons)

Loading…
Cancel
Save