From 80e682d04616ae2b5606f62f3652877b9700ddac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Jun 2018 02:04:05 +0200 Subject: [PATCH] Platform: implemented GlfwApplication::MouseMoveEvent::buttons(). Improves feature parity with Sdl2Application. --- doc/changelog.dox | 5 +++++ src/Magnum/Platform/GlfwApplication.cpp | 14 +++++++++++++ src/Magnum/Platform/GlfwApplication.h | 26 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/doc/changelog.dox b/doc/changelog.dox index 29d3b4159..e90081d11 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -55,6 +55,11 @@ See also: - Ability to convert @ref Math::BoolVector from and to external representation +@subsubsection changelog-latest-new-platform Platform libraries + +- Implemented @ref Platform::GlfwApplication::MouseMoveEvent::buttons() for + feature parity with @ref Platform::Sdl2Application + @subsection changelog-latest-changes Changes and improvements @subsubsection changelog-latest-changes-audio Audio library diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 809edbdce..78a6d31ef 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -395,6 +395,20 @@ void GlfwApplication::staticKeyEvent(GLFWwindow* const window, const int key, in } } +auto GlfwApplication::MouseMoveEvent::buttons() -> Buttons { + if(!_buttons) { + _buttons = Buttons{}; + for(const Int button: {GLFW_MOUSE_BUTTON_LEFT, + GLFW_MOUSE_BUTTON_MIDDLE, + GLFW_MOUSE_BUTTON_RIGHT}) { + if(glfwGetMouseButton(_window, button) == GLFW_PRESS) + *_buttons |= Button(1 << button); + } + } + + return *_buttons; +} + auto GlfwApplication::MouseMoveEvent::modifiers() -> Modifiers { if(!_modifiers) _modifiers = currentGlfwModifiers(_window); return *_modifiers; diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 066c15bf2..f20083d0b 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -1193,6 +1193,31 @@ class GlfwApplication::MouseMoveEvent: public GlfwApplication::InputEvent { friend GlfwApplication; public: + /** + * @brief Mouse button + * + * @see @ref Buttons, @ref buttons() + */ + enum class Button: UnsignedInt { + Left = 1 << GLFW_MOUSE_BUTTON_LEFT, /**< Left button */ + Middle = 1 << GLFW_MOUSE_BUTTON_MIDDLE, /**< Middle button */ + Right = 1 << GLFW_MOUSE_BUTTON_RIGHT /**< Right button */ + }; + + /** + * @brief Set of mouse buttons + * + * @see @ref buttons() + */ + typedef Containers::EnumSet