#ifndef Magnum_Platform_ScreenedApplication_hpp #define Magnum_Platform_ScreenedApplication_hpp /* This file is part of Magnum. Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025 Vladimír Vondruš Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** @file * @brief @ref compilation-speedup-hpp "Template implementation" for @ref ScreenedApplication.h and @ref Screen.h */ #include "Magnum/Platform/Screen.h" #include "Magnum/Platform/ScreenedApplication.h" namespace Magnum { namespace Platform { namespace Implementation { template void ApplicationKeyEventMixin::callKeyPressEvent(KeyEvent&, Containers::LinkedList>&) {} template void ApplicationKeyEventMixin::callKeyPressEvent(typename Application::KeyEvent& event, Containers::LinkedList>& screens) { /* 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->keyPressEvent(event); if(event.isAccepted()) break; } } } template void ApplicationKeyEventMixin::callKeyReleaseEvent(KeyEvent&, Containers::LinkedList>&) {} template void ApplicationKeyEventMixin::callKeyReleaseEvent(typename Application::KeyEvent& event, Containers::LinkedList>& screens) { /* 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->keyReleaseEvent(event); if(event.isAccepted()) break; } } } template void ApplicationScrollEventMixin::callScrollEvent(Application&, ScrollEvent&, Containers::LinkedList>&) {} template void ApplicationScrollEventMixin::callScrollEvent(Application& application, typename Application::ScrollEvent& event, Containers::LinkedList>& screens) { /* 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->scrollEvent(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 mouseScrollEvent(). */ if(!event.isAccepted()) application.scrollEvent(event); #else static_cast(application); #endif } #ifdef MAGNUM_BUILD_DEPRECATED CORRADE_IGNORE_DEPRECATED_PUSH template void ApplicationMouseScrollEventMixin::callMouseScrollEvent(MouseScrollEvent&, Containers::LinkedList>&) {} template void ApplicationMouseScrollEventMixin::callMouseScrollEvent(typename Application::MouseScrollEvent& event, Containers::LinkedList>& screens) { /* 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->mouseScrollEvent(event); if(event.isAccepted()) break; } } } CORRADE_IGNORE_DEPRECATED_POP #endif template void ApplicationTextInputEventMixin::callTextInputEvent(TextInputEvent&, Containers::LinkedList>&) {} template void ApplicationTextInputEventMixin::callTextInputEvent(typename Application::TextInputEvent& event, Containers::LinkedList>& screens) { /* 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->textInputEvent(event); if(event.isAccepted()) break; } } } template void ApplicationTextEditingEventMixin::callTextEditingEvent(TextEditingEvent&, Containers::LinkedList>&) {} template void ApplicationTextEditingEventMixin::callTextEditingEvent(typename Application::TextEditingEvent& event, Containers::LinkedList>& screens) { /* 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->textEditingEvent(event); if(event.isAccepted()) break; } } } template void ScreenKeyEventMixin::keyPressEvent(KeyEvent&) {} template void ScreenKeyEventMixin::keyReleaseEvent(KeyEvent&) {} template void ScreenScrollEventMixin::scrollEvent(ScrollEvent&) {} #ifdef MAGNUM_BUILD_DEPRECATED CORRADE_IGNORE_DEPRECATED_PUSH template void ScreenMouseScrollEventMixin::mouseScrollEvent(MouseScrollEvent&) {} CORRADE_IGNORE_DEPRECATED_POP #endif template void ScreenTextInputEventMixin::textInputEvent(TextInputEvent&) {} template void ScreenTextEditingEventMixin::textEditingEvent(TextEditingEvent&) {} } template BasicScreen::BasicScreen() = default; template BasicScreen::BasicScreen(BasicScreenedApplication& application, PropagatedEvents events) { /* A superset of this (together with focusEvent()) is done in BasicScreenedApplication::addScreen() as well. Keep in sync. */ application.Containers::template LinkedList>::insert(this); redraw(); setPropagatedEvents(events); } template BasicScreen::~BasicScreen() = default; template BasicScreenedApplication& BasicScreen::application() { BasicScreenedApplication* application = Containers::LinkedListItem, BasicScreenedApplication>::list(); CORRADE_ASSERT(application, "Platform::Screen::application(): the screen is not added to any application", *application); return *application; } template const BasicScreenedApplication& BasicScreen::application() const { const BasicScreenedApplication* application = Containers::LinkedListItem, BasicScreenedApplication>::list(); CORRADE_ASSERT(application, "Platform::Screen::application(): the screen is not added to any application", *application); return *application; } template void BasicScreen::redraw() { BasicScreenedApplication* application = Containers::LinkedListItem, BasicScreenedApplication>::list(); CORRADE_ASSERT(application, "Platform::Screen::redraw(): the screen is not added to any application", ); application->redraw(); } template void BasicScreen::focusEvent() {} template void BasicScreen::blurEvent() {} template void BasicScreen::viewportEvent(ViewportEvent& event) { 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) {} #endif template BasicScreenedApplication::BasicScreenedApplication(const typename Application::Arguments& arguments, const typename Application::Configuration& configuration): Application(arguments, configuration) {} template BasicScreenedApplication::BasicScreenedApplication(const typename Application::Arguments& arguments, NoCreateT): Application(arguments, NoCreate) {} template BasicScreenedApplication::~BasicScreenedApplication() = default; template BasicScreenedApplication& BasicScreenedApplication::addScreen(BasicScreen& screen) { CORRADE_ASSERT(!screen.hasApplication(), "Platform::ScreenedApplication::addScreen(): screen already added to an application", *this); /* A subset of this (except focusEvent()) is done in BasicScreen(BasicScreenedApplication&, PropagatedEvents) as well. Keep in sync. */ Containers::LinkedList>::insert(&screen); if(screens().first() == &screen) screen.focusEvent(); Application::redraw(); return *this; } template BasicScreenedApplication& BasicScreenedApplication::removeScreen(BasicScreen& screen) { CORRADE_ASSERT(screen.hasApplication() && &screen.application() == this, "Platform::ScreenedApplication::removeScreen(): screen not owned by this application", *this); screen.blurEvent(); Containers::LinkedList>::erase(&screen); Application::redraw(); return *this; } template BasicScreenedApplication& BasicScreenedApplication::focusScreen(BasicScreen& screen) { CORRADE_ASSERT(screen.hasApplication() && &screen.application() == this, "Platform::ScreenedApplication::focusScreen(): screen not owned by this application", *this); /* Already focused, nothing to do */ if(screens().first() == &screen) return *this; screens().first()->blurEvent(); Containers::LinkedList>::move(&screen, screens().first()); screen.focusEvent(); Application::redraw(); return *this; } template void BasicScreenedApplication::globalViewportEvent(typename Application::ViewportEvent&) {} template void BasicScreenedApplication::viewportEvent(typename Application::ViewportEvent& event) { /* Call global event before all other (to resize framebuffer first) */ globalViewportEvent(event); for(BasicScreen& s: *this) s.viewportEvent(event); } template void BasicScreenedApplication::globalBeforeDrawEvent() {} template void BasicScreenedApplication::drawEvent() { /* Call the "before" global event before all other */ globalBeforeDrawEvent(); /* Back-to-front rendering */ for(BasicScreen* s = screens().last(); s; s = s->nextNearerScreen()) if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Draw) s->drawEvent(); /* Call global event after all other (to swap buffers last) */ globalDrawEvent(); } template void BasicScreenedApplication::keyPressEvent(typename BasicScreenedApplication::KeyEvent& event) { this->callKeyPressEvent(event, screens()); } template void BasicScreenedApplication::keyReleaseEvent(typename BasicScreenedApplication::KeyEvent& event) { 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()) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { s->mousePressEvent(event); if(event.isAccepted()) break; } } } template void BasicScreenedApplication::mouseReleaseEvent(typename Application::MouseEvent& 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->mouseReleaseEvent(event); if(event.isAccepted()) break; } } } template void BasicScreenedApplication::mouseMoveEvent(typename Application::MouseMoveEvent& 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->mouseMoveEvent(event); if(event.isAccepted()) break; } } } CORRADE_IGNORE_DEPRECATED_POP #endif template void BasicScreenedApplication::scrollEvent(typename BasicScreenedApplication::ScrollEvent& event) { this->callScrollEvent(*this, event, screens()); } #ifdef MAGNUM_BUILD_DEPRECATED CORRADE_IGNORE_DEPRECATED_PUSH template void BasicScreenedApplication::mouseScrollEvent(typename BasicScreenedApplication::MouseScrollEvent& event) { this->callMouseScrollEvent(event, screens()); } CORRADE_IGNORE_DEPRECATED_POP #endif template void BasicScreenedApplication::textInputEvent(typename BasicScreenedApplication::TextInputEvent& event) { this->callTextInputEvent(event, screens()); } template void BasicScreenedApplication::textEditingEvent(typename BasicScreenedApplication::TextEditingEvent& event) { this->callTextEditingEvent(event, screens()); } }} #endif