diff --git a/doc/changelog.dox b/doc/changelog.dox index f35fe803c..910b84a85 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -1399,8 +1399,10 @@ See also: @relativeref{Platform::Sdl2Application,PointerMoveEvent} APIs that provide a better abstraction over general pointer input, not just a mouse alone. The same change is done in @ref Platform::AbstractXApplication, - @ref Platform::AndroidApplication, @ref Platform::EmscriptenApplication and - @ref Platform::GlfwApplication. + @ref Platform::AndroidApplication, @ref Platform::EmscriptenApplication, + @ref Platform::GlfwApplication and the + @ref Platform::BasicScreenedApplication / @ref Platform::BasicScreen + wrappers as well. - @cpp Platform::AbstractXApplication::MouseEvent::Button::WheelUp @ce and `WheelDown` members are deprecated in favor of a dedicated @ref Platform::AbstractXApplication::mouseScrollEvent(). Similar change was diff --git a/doc/snippets/Platform.cpp b/doc/snippets/Platform.cpp index 308a2280d..24ce9b188 100644 --- a/doc/snippets/Platform.cpp +++ b/doc/snippets/Platform.cpp @@ -163,6 +163,13 @@ MyApplication::MyApplication(const Arguments& arguments): namespace F { +/* On MSVC 2017, deprecation warning suppression doesn't work on virtual + function overrides, so ScreenedApplication overriding mousePressEvent(), + mouseReleaseEvent() mouseMoveEvent() and mouseScrollEvent() causes warnings. + Disable them at a higher level instead. */ +#if defined(MAGNUM_BUILD_DEPRECATED) && defined(CORRADE_TARGET_MSVC) && !defined(CORRADE_TARGET_CLANG) && _MSC_VER < 1920 +CORRADE_IGNORE_DEPRECATED_PUSH +#endif int argc = 0; struct MyApplication: Platform::ScreenedApplication { MyApplication(): Platform::ScreenedApplication{Arguments{argc, nullptr}} {} @@ -170,6 +177,9 @@ struct MyApplication: Platform::ScreenedApplication { void globalViewportEvent(ViewportEvent& event) override; void globalDrawEvent() override; }; +#if defined(MAGNUM_BUILD_DEPRECATED) && defined(CORRADE_TARGET_MSVC) && !defined(CORRADE_TARGET_CLANG) && _MSC_VER < 1920 +CORRADE_IGNORE_DEPRECATED_POP +#endif /* [ScreenedApplication-global-events] */ void MyApplication::globalViewportEvent(ViewportEvent& event) { diff --git a/src/Magnum/Platform/AbstractXApplication.h b/src/Magnum/Platform/AbstractXApplication.h index 072faffa5..22f1a42c3 100644 --- a/src/Magnum/Platform/AbstractXApplication.h +++ b/src/Magnum/Platform/AbstractXApplication.h @@ -421,6 +421,12 @@ class AbstractXApplication { explicit AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments& arguments, NoCreateT); private: + #ifdef MAGNUM_BUILD_DEPRECATED + /* Calls the base pointer*Event() in order to delegate to deprecated + mouse events */ + template friend class BasicScreenedApplication; + #endif + enum class Flag: unsigned int { Redraw = 1 << 0, Exit = 1 << 1 diff --git a/src/Magnum/Platform/AndroidApplication.h b/src/Magnum/Platform/AndroidApplication.h index 8cfd9bcfd..9e5534809 100644 --- a/src/Magnum/Platform/AndroidApplication.h +++ b/src/Magnum/Platform/AndroidApplication.h @@ -495,6 +495,12 @@ class AndroidApplication { */ private: + #ifdef MAGNUM_BUILD_DEPRECATED + /* Calls the base pointer*Event() in order to delegate to deprecated + mouse events */ + template friend class BasicScreenedApplication; + #endif + struct LogOutput; enum class Flag: UnsignedByte; diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h index 8cca7518b..70b08ca34 100644 --- a/src/Magnum/Platform/EmscriptenApplication.h +++ b/src/Magnum/Platform/EmscriptenApplication.h @@ -980,6 +980,12 @@ class EmscriptenApplication { */ private: + #ifdef MAGNUM_BUILD_DEPRECATED + /* Calls the base pointer*Event() in order to delegate to deprecated + mouse events */ + template friend class BasicScreenedApplication; + #endif + enum class Flag: UnsignedByte; typedef Containers::EnumSet Flags; CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 27f621ab3..1865e412a 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -1168,7 +1168,17 @@ auto GlfwApplication::MouseScrollEvent::modifiers() -> Modifiers { return *_modifiers; } +/* On MSVC 2017, deprecation warning suppression doesn't work on virtual + function overrides, so ScreenedApplication overriding mousePressEvent(), + mouseReleaseEvent(), and mouseMoveEvent() causes warnings. Disable them at a + higher level instead. */ +#if defined(MAGNUM_BUILD_DEPRECATED) && defined(CORRADE_TARGET_MSVC) && !defined(CORRADE_TARGET_CLANG) && _MSC_VER < 1920 +CORRADE_IGNORE_DEPRECATED_PUSH +#endif template class BasicScreen; template class BasicScreenedApplication; +#if defined(MAGNUM_BUILD_DEPRECATED) && defined(CORRADE_TARGET_MSVC) && !defined(CORRADE_TARGET_CLANG) && _MSC_VER < 1920 +CORRADE_IGNORE_DEPRECATED_POP +#endif }} diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 1542213ad..d025b4359 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -866,6 +866,12 @@ class GlfwApplication { virtual void tickEvent(); private: + #ifdef MAGNUM_BUILD_DEPRECATED + /* Calls the base pointer*Event() in order to delegate to deprecated + mouse events */ + template friend class BasicScreenedApplication; + #endif + enum class Flag: UnsignedByte; typedef Containers::EnumSet Flags; CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) diff --git a/src/Magnum/Platform/Screen.h b/src/Magnum/Platform/Screen.h index e871340b2..8e4b40490 100644 --- a/src/Magnum/Platform/Screen.h +++ b/src/Magnum/Platform/Screen.h @@ -146,8 +146,8 @@ template class BasicScreen: * Input events. * * When enabled, @ref keyPressEvent(), @ref keyReleaseEvent(), - * @ref mousePressEvent(), @ref mouseReleaseEvent(), - * @ref mouseMoveEvent(), @ref mouseScrollEvent(), + * @ref pointerPressEvent(), @ref pointerReleaseEvent(), + * @ref pointerMoveEvent(), @ref mouseScrollEvent(), * @ref textInputEvent() and @ref textEditingEvent() are propagated * to this screen. */ @@ -181,11 +181,52 @@ template class BasicScreen: typedef typename BasicScreenedApplication::KeyEvent KeyEvent; #endif - /** @brief Mouse event */ - typedef typename BasicScreenedApplication::MouseEvent MouseEvent; + /** + * @brief Pointer type + * @m_since_latest + */ + typedef typename BasicScreenedApplication::Pointer Pointer; + + /** + * @brief Set of pointer types + * @m_since_latest + */ + typedef typename BasicScreenedApplication::Pointers Pointers; + + /** + * @brief Pointer event + * @m_since_latest + */ + typedef typename BasicScreenedApplication::PointerEvent PointerEvent; + + /** + * @brief Pointer move event + * @m_since_latest + */ + typedef typename BasicScreenedApplication::PointerMoveEvent PointerMoveEvent; + + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * @brief Mouse event + * @m_deprecated_since_latest Use @ref PointerEvent, + * @ref pointerPressEvent() and @ref pointerReleaseEvent() + * instead, which is a better abstraction for covering both mouse + * and touch / pen input. + */ + CORRADE_IGNORE_DEPRECATED_PUSH + typedef CORRADE_DEPRECATED("use PointerEvent, pointerPressEvent() and pointerReleaseEvent() instead") typename BasicScreenedApplication::MouseEvent MouseEvent; + CORRADE_IGNORE_DEPRECATED_POP - /** @brief Mouse move event */ - typedef typename BasicScreenedApplication::MouseMoveEvent MouseMoveEvent; + /** + * @brief Mouse move event + * @m_deprecated_since_latest Use @ref PointerMoveEvent and + * @ref pointerMoveEvent() instead, which is a better abstraction + * for covering both mouse and touch / pen input. + */ + CORRADE_IGNORE_DEPRECATED_PUSH + typedef CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead") typename BasicScreenedApplication::MouseMoveEvent MouseMoveEvent; + CORRADE_IGNORE_DEPRECATED_POP + #endif #ifdef DOXYGEN_GENERATING_OUTPUT /** @@ -401,34 +442,84 @@ template class BasicScreen: * @} */ - /** @{ @name Mouse handling */ + /** @{ @name Pointer handling */ + /** + * @brief Pointer press event + * @m_since_latest + * + * Called when @ref PropagatedEvent::Input is enabled and a pointer is + * pressed. See @ref Sdl2Application::pointerPressEvent() "*Application::pointerPressEvent()" + * for more information. + */ + virtual void pointerPressEvent(PointerEvent& event); + + #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Mouse press event + * @m_deprecated_since_latest Use @ref pointerPressEvent() instead, + * which is a better abstraction for covering both mouse and touch + * / pen input. * * Called when @ref PropagatedEvent::Input is enabled and mouse button * is pressed. See @ref Sdl2Application::mousePressEvent() "*Application::mousePressEvent()" * for more information. */ - virtual void mousePressEvent(MouseEvent& event); + CORRADE_IGNORE_DEPRECATED_PUSH + virtual CORRADE_DEPRECATED("use pointerPressEvent() instead") void mousePressEvent(MouseEvent& event); + CORRADE_IGNORE_DEPRECATED_POP + #endif + + /** + * @brief Pointer release event + * @m_since_latest + * + * Called when @ref PropagatedEvent::Input is enabled and a pointer is + * released. See @ref Sdl2Application::pointerReleaseEvent() "*Application::pointerReleaseEvent()" + * for more information. + */ + virtual void pointerReleaseEvent(PointerEvent& event); + #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Mouse release event + * @m_deprecated_since_latest Use @ref pointerReleaseEvent() instead, + * which is a better abstraction for covering both mouse and touch + * / pen input. * * Called when @ref PropagatedEvent::Input is enabled and mouse button * is released. See @ref Sdl2Application::mouseReleaseEvent() "*Application::mouseReleaseEvent()" * for more information. */ - virtual void mouseReleaseEvent(MouseEvent& event); + CORRADE_IGNORE_DEPRECATED_PUSH + virtual CORRADE_DEPRECATED("use pointerReleaseEvent() instead") void mouseReleaseEvent(MouseEvent& event); + CORRADE_IGNORE_DEPRECATED_POP + #endif + /** + * @brief Pointer move event + * + * Called when @ref PropagatedEvent::Input is enabled and a pointer is + * moved. See @ref Sdl2Application::pointerMoveEvent() "*Application::pointerMoveEvent()" + * for more information. + */ + virtual void pointerMoveEvent(PointerMoveEvent& event); + + #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Mouse move event + * @m_deprecated_since_latest Use @ref pointerMoveEvent() instead, + * which is a better abstraction for covering both mouse and touch + * / pen input. * * Called when @ref PropagatedEvent::Input is enabled and mouse is * moved. See @ref Sdl2Application::mouseMoveEvent() "*Application::mouseMoveEvent()" * for more information. */ - virtual void mouseMoveEvent(MouseMoveEvent& event); + CORRADE_IGNORE_DEPRECATED_PUSH + virtual CORRADE_DEPRECATED("use pointerMoveEvent() instead") void mouseMoveEvent(MouseMoveEvent& event); + CORRADE_IGNORE_DEPRECATED_POP + #endif #ifdef DOXYGEN_GENERATING_OUTPUT /** diff --git a/src/Magnum/Platform/ScreenedApplication.h b/src/Magnum/Platform/ScreenedApplication.h index cb21aa90e..3487164f9 100644 --- a/src/Magnum/Platform/ScreenedApplication.h +++ b/src/Magnum/Platform/ScreenedApplication.h @@ -122,14 +122,14 @@ event, they are propagated to the screens: - @ref Sdl2Application::drawEvent() "drawEvent()" is propagated in back-to-front order to screens which have @ref BasicScreen::PropagatedEvent::Draw enabled. -- Input events (@ref Sdl2Application::keyPressEvent() "keyPressEvent()", - @ref Sdl2Application::keyReleaseEvent() "keyReleaseEvent()", - @ref Sdl2Application::mousePressEvent() "mousePressEvent()", - @ref Sdl2Application::mouseReleaseEvent() "mouseReleaseEvent()", - @ref Sdl2Application::mouseMoveEvent() "mouseMoveEvent()", - @ref Sdl2Application::mouseMoveEvent() "mouseScrollEvent()", - @ref Sdl2Application::textInputEvent() "textInputEvent()" and - @ref Sdl2Application::textEditingEvent() "textEditingEvent()") +- Input events (@relativeref{Sdl2Application,keyPressEvent()}, + @relativeref{Sdl2Application,keyReleaseEvent()}, + @relativeref{Sdl2Application,pointerPressEvent()}, + @relativeref{Sdl2Application,pointerReleaseEvent()}, + @relativeref{Sdl2Application,pointerMoveEvent()}, + @relativeref{Sdl2Application,mouseScrollEvent()}, + @relativeref{Sdl2Application,textInputEvent()} and + @relativeref{Sdl2Application,textEditingEvent()}) are propagated in front-to-back order to screens which have @ref BasicScreen::PropagatedEvent::Input enabled. If any screen sets the event as accepted, it is not propagated further. @@ -324,9 +324,16 @@ template class BasicScreenedApplication: implementations are dispatching the events to attached screens. */ void viewportEvent(typename Application::ViewportEvent& event) override final; void drawEvent() override final; + void pointerPressEvent(typename Application::PointerEvent& event) override final; + void pointerReleaseEvent(typename Application::PointerEvent& event) override final; + void pointerMoveEvent(typename Application::PointerMoveEvent& event) override final; + #ifdef MAGNUM_BUILD_DEPRECATED + CORRADE_IGNORE_DEPRECATED_PUSH void mousePressEvent(typename Application::MouseEvent& event) override final; void mouseReleaseEvent(typename Application::MouseEvent& event) override final; void mouseMoveEvent(typename Application::MouseMoveEvent& event) override final; + CORRADE_IGNORE_DEPRECATED_POP + #endif /* These events are not available in all cases, so if the Application doesn't have them, they're overriding a mixin dummy */ diff --git a/src/Magnum/Platform/ScreenedApplication.hpp b/src/Magnum/Platform/ScreenedApplication.hpp index 37f87d074..b5688234d 100644 --- a/src/Magnum/Platform/ScreenedApplication.hpp +++ b/src/Magnum/Platform/ScreenedApplication.hpp @@ -143,9 +143,17 @@ template void BasicScreen::viewportEvent(Viewpor static_cast(event); } +template void BasicScreen::pointerPressEvent(PointerEvent&) {} +template void BasicScreen::pointerReleaseEvent(PointerEvent&) {} +template void BasicScreen::pointerMoveEvent(PointerMoveEvent&) {} + +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH template void BasicScreen::mousePressEvent(MouseEvent&) {} template void BasicScreen::mouseReleaseEvent(MouseEvent&) {} template void BasicScreen::mouseMoveEvent(MouseMoveEvent&) {} +CORRADE_IGNORE_DEPRECATED_POP +#endif #ifdef MAGNUM_TARGET_GL template BasicScreenedApplication::BasicScreenedApplication(const typename Application::Arguments& arguments, const typename Application::Configuration& configuration, const typename Application::GLConfiguration& glConfiguration): Application(arguments, configuration, glConfiguration) {} @@ -225,6 +233,65 @@ template void BasicScreenedApplication::keyRelea this->callKeyReleaseEvent(event, screens()); } +template void BasicScreenedApplication::pointerPressEvent(typename Application::PointerEvent& event) { + /* Front-to-back event propagation, stop when the event gets accepted */ + for(BasicScreen* s = screens().first(); s; s = s->nextFartherScreen()) { + if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { + s->pointerPressEvent(event); + if(event.isAccepted()) break; + } + } + + #ifdef MAGNUM_BUILD_DEPRECATED + /* If the event wasn't accepted, it's possible that the screens still only + implement the deprecated mouse events. Call into the base + implementation and assume it appropriately delegates to + mousePressEvent(). */ + if(!event.isAccepted()) + Application::pointerPressEvent(event); + #endif +} + +template void BasicScreenedApplication::pointerReleaseEvent(typename Application::PointerEvent& event) { + /* Front-to-back event propagation, stop when the event gets accepted */ + for(BasicScreen* s = screens().first(); s; s = s->nextFartherScreen()) { + if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { + s->pointerReleaseEvent(event); + if(event.isAccepted()) break; + } + } + + #ifdef MAGNUM_BUILD_DEPRECATED + /* If the event wasn't accepted, it's possible that the screens still only + implement the deprecated mouse events. Call into the base + implementation and assume it appropriately delegates to + mouseReleaseEvent(). */ + if(!event.isAccepted()) + Application::pointerReleaseEvent(event); + #endif +} + +template void BasicScreenedApplication::pointerMoveEvent(typename Application::PointerMoveEvent& event) { + /* Front-to-back event propagation, stop when the event gets accepted */ + for(BasicScreen* s = screens().first(); s; s = s->nextFartherScreen()) { + if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { + s->pointerMoveEvent(event); + if(event.isAccepted()) break; + } + } + + #ifdef MAGNUM_BUILD_DEPRECATED + /* If the event wasn't accepted, it's possible that the screens still only + implement the deprecated mouse events. Call into the base + implementation and assume it appropriately delegates to + mouseMoveEvent(), mousePressEvent() or mouseReleaseEvent(). */ + if(!event.isAccepted()) + Application::pointerMoveEvent(event); + #endif +} + +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH template void BasicScreenedApplication::mousePressEvent(typename Application::MouseEvent& event) { /* Front-to-back event propagation, stop when the event gets accepted */ for(BasicScreen* s = screens().first(); s; s = s->nextFartherScreen()) { @@ -254,6 +321,8 @@ template void BasicScreenedApplication::mouseMov } } } +CORRADE_IGNORE_DEPRECATED_POP +#endif template void BasicScreenedApplication::mouseScrollEvent(typename BasicScreenedApplication::MouseScrollEvent& event) { this->callMouseScrollEvent(event, screens()); diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index cd1c4eace..76479fa0c 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -1485,7 +1485,18 @@ Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseScrollEvent::modifi return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState()))); } +/* WinRT builds by default have deprecation warnings as errors. Combined with a + MSVC 2017 bug where deprecation warning suppression doesn't work on virtual + function overrides this make the build fail on deprecation warnings due to + ScreenedApplication overriding mousePressEvent(), mouseReleaseEvent() and + mouseMoveEvent(). Disable the warnings at a higher level instead. */ +#if defined(MAGNUM_BUILD_DEPRECATED) && defined(CORRADE_TARGET_MSVC) && !defined(CORRADE_TARGET_CLANG) && _MSC_VER < 1920 +CORRADE_IGNORE_DEPRECATED_PUSH +#endif template class BasicScreen; template class BasicScreenedApplication; +#if defined(MAGNUM_BUILD_DEPRECATED) && defined(CORRADE_TARGET_MSVC) && !defined(CORRADE_TARGET_CLANG) && _MSC_VER < 1920 +CORRADE_IGNORE_DEPRECATED_POP +#endif }} diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 0f0ac9a41..47be1a338 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -1323,6 +1323,12 @@ class Sdl2Application { */ private: + #ifdef MAGNUM_BUILD_DEPRECATED + /* Calls the base pointer*Event() in order to delegate to deprecated + mouse events */ + template friend class BasicScreenedApplication; + #endif + enum class Flag: UnsignedByte; typedef Containers::EnumSet Flags; CORRADE_ENUMSET_FRIEND_OPERATORS(Flags)