From 4d6dd3b369253f588068bd1a405d2816dc8247a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 1 Jan 2015 22:40:53 +0100 Subject: [PATCH] Platform: provide range-based-for access to application screens. Similar reasoning as in previous commit for deprecation of frontScreen() etc. --- src/Magnum/Platform/ScreenedApplication.h | 62 ++++++++++++++------- src/Magnum/Platform/ScreenedApplication.hpp | 23 ++++---- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/Magnum/Platform/ScreenedApplication.h b/src/Magnum/Platform/ScreenedApplication.h index c552de591..c9af56fc7 100644 --- a/src/Magnum/Platform/ScreenedApplication.h +++ b/src/Magnum/Platform/ScreenedApplication.h @@ -62,15 +62,21 @@ application gets an event, they are propagated to the screens: @ref BasicScreen::PropagatedEvent::Input enabled. If any screen sets the event as accepted, it is not propagated further. -Traversing through the list of screens is done like following: +Uses @ref Corrade::Containers::LinkedList for efficient screen management. +Traversing front-to-back through the list of screens can be done using +range-based for: @code -// front-to-back -for(Screen* s = app.frontScreen(); s; s = s->nextFartherScreen()) { +MyApplication app; +for(Screen& screen: app.screens()) { // ... } +@endcode -// back-to-front -for(Screen* s = app.backScreen(); s; s = s->nextNearerScreen()) { +Or, if you need more flexibility, like in the following code. Traversing +back-to-front can be done using @ref Corrade::Containers::LinkedList::last() +and @ref BasicScreen::nextNearerScreen(). +@code +for(Screen* s = app.screens().first(); s; s = s->nextFartherScreen()) { // ... } @endcode @@ -148,30 +154,46 @@ template class BasicScreenedApplication: public Application, BasicScreenedApplication& focusScreen(BasicScreen& screen); /** - * @brief Front screen + * @brief Application screens * - * @see @ref BasicScreen::nextFartherScreen(), @ref BasicScreen::nextNearerScreen() + * The screens are sorted front-to-back. + * @see @ref BasicScreen::application(), + * @ref BasicScreen::nextFartherScreen(), + * @ref BasicScreen::nextNearerScreen() */ - BasicScreen* frontScreen() { - return Containers::LinkedList>::first(); + Containers::LinkedList>& screens() { + return static_cast>&>(*this); } + /** @overload */ - const BasicScreen* frontScreen() const { - return Containers::LinkedList>::first(); + const Containers::LinkedList>& screens() const { + return static_cast>&>(*this); } + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * @brief Front screen + * @deprecated Use `screens().first()` instead. + */ + CORRADE_DEPRECATED("use screens().first() instead") BasicScreen* frontScreen() { return screens().first(); } + + /** @overload + * @deprecated Use `screens().first()` instead. + */ + CORRADE_DEPRECATED("use screens().first() instead") const BasicScreen* frontScreen() const { return screens().first(); } + /** * @brief Back screen - * - * @see @ref BasicScreen::nextFartherScreen(), @ref BasicScreen::nextNearerScreen() + * @deprecated Use `screens().last()` instead. */ - BasicScreen* backScreen() { - return Containers::LinkedList>::last(); - } - /** @overload */ - const BasicScreen* backScreen() const { - return Containers::LinkedList>::last(); - } + CORRADE_DEPRECATED("use screens().back() instead") BasicScreen* backScreen() { return screens().last(); } + + /** + * @overload + * @deprecated Use `screens().last()` instead. + */ + CORRADE_DEPRECATED("use screens().back() instead") const BasicScreen* backScreen() const { return screens().last(); } + #endif protected: /* Nobody will need to have (and delete) ScreenedApplication*, thus diff --git a/src/Magnum/Platform/ScreenedApplication.hpp b/src/Magnum/Platform/ScreenedApplication.hpp index 9702f5d3d..e23e75ab7 100644 --- a/src/Magnum/Platform/ScreenedApplication.hpp +++ b/src/Magnum/Platform/ScreenedApplication.hpp @@ -49,7 +49,7 @@ template BasicScreenedApplication::~BasicScreene template BasicScreenedApplication& BasicScreenedApplication::addScreen(BasicScreen& screen) { Containers::LinkedList>::insert(&screen); - if(frontScreen() == &screen) screen.focusEvent(); + if(screens().first() == &screen) screen.focusEvent(); Application::redraw(); return *this; } @@ -63,10 +63,10 @@ template BasicScreenedApplication& BasicScreened template BasicScreenedApplication& BasicScreenedApplication::focusScreen(BasicScreen& screen) { /* Already focused, nothing to do */ - if(frontScreen() == &screen) return *this; + if(screens().first() == &screen) return *this; - frontScreen()->blurEvent(); - Containers::LinkedList>::move(&screen, frontScreen()); + screens().first()->blurEvent(); + Containers::LinkedList>::move(&screen, screens().first()); screen.focusEvent(); Application::redraw(); return *this; @@ -78,13 +78,12 @@ template void BasicScreenedApplication::viewport /* Call viewport event after all other (because of framebuffer resizing) */ globalViewportEvent(size); - for(BasicScreen* s = Containers::LinkedList>::first(); s; s = s->next()) - s->viewportEvent(size); + for(BasicScreen& s: *this) s.viewportEvent(size); } template void BasicScreenedApplication::drawEvent() { /* Back-to-front rendering */ - for(BasicScreen* s = backScreen(); s; s = s->nextNearerScreen()) + for(BasicScreen* s = screens().last(); s; s = s->nextNearerScreen()) if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Draw) s->drawEvent(); /* Call global event after all other (because of buffer swapping) */ @@ -93,7 +92,7 @@ template void BasicScreenedApplication::drawEven template void BasicScreenedApplication::keyPressEvent(typename Application::KeyEvent& event) { /* Front-to-back event propagation, stop when the event gets accepted */ - for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + for(BasicScreen* s = screens().first(); s; s = s->nextFartherScreen()) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { s->keyPressEvent(event); if(event.isAccepted()) break; @@ -103,7 +102,7 @@ template void BasicScreenedApplication::keyPress template void BasicScreenedApplication::keyReleaseEvent(typename Application::KeyEvent& event) { /* Front-to-back event propagation, stop when the event gets accepted */ - for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + for(BasicScreen* s = screens().first(); s; s = s->nextFartherScreen()) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { s->keyReleaseEvent(event); if(event.isAccepted()) break; @@ -113,7 +112,7 @@ template void BasicScreenedApplication::keyRelea template void BasicScreenedApplication::mousePressEvent(typename Application::MouseEvent& event) { /* Front-to-back event propagation, stop when the event gets accepted */ - for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + for(BasicScreen* s = screens().first(); s; s = s->nextFartherScreen()) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { s->mousePressEvent(event); if(event.isAccepted()) break; @@ -123,7 +122,7 @@ template void BasicScreenedApplication::mousePre template void BasicScreenedApplication::mouseReleaseEvent(typename Application::MouseEvent& event) { /* Front-to-back event propagation, stop when the event gets accepted */ - for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + for(BasicScreen* s = screens().first(); s; s = s->nextFartherScreen()) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { s->mouseReleaseEvent(event); if(event.isAccepted()) break; @@ -133,7 +132,7 @@ template void BasicScreenedApplication::mouseRel template void BasicScreenedApplication::mouseMoveEvent(typename Application::MouseMoveEvent& event) { /* Front-to-back event propagation, stop when the event gets accepted */ - for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + for(BasicScreen* s = screens().first(); s; s = s->nextFartherScreen()) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { s->mouseMoveEvent(event); if(event.isAccepted()) break;