Browse Source

Platform: provide range-based-for access to application screens.

Similar reasoning as in previous commit for deprecation of frontScreen()
etc.
pull/87/head
Vladimír Vondruš 12 years ago
parent
commit
4d6dd3b369
  1. 62
      src/Magnum/Platform/ScreenedApplication.h
  2. 23
      src/Magnum/Platform/ScreenedApplication.hpp

62
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 @ref BasicScreen::PropagatedEvent::Input enabled. If any screen sets the
event as accepted, it is not propagated further. 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 @code
// front-to-back MyApplication app;
for(Screen* s = app.frontScreen(); s; s = s->nextFartherScreen()) { for(Screen& screen: app.screens()) {
// ... // ...
} }
@endcode
// back-to-front Or, if you need more flexibility, like in the following code. Traversing
for(Screen* s = app.backScreen(); s; s = s->nextNearerScreen()) { 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 @endcode
@ -148,30 +154,46 @@ template<class Application> class BasicScreenedApplication: public Application,
BasicScreenedApplication<Application>& focusScreen(BasicScreen<Application>& screen); BasicScreenedApplication<Application>& focusScreen(BasicScreen<Application>& 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<Application>* frontScreen() { Containers::LinkedList<BasicScreen<Application>>& screens() {
return Containers::LinkedList<BasicScreen<Application>>::first(); return static_cast<Containers::LinkedList<BasicScreen<Application>>&>(*this);
} }
/** @overload */ /** @overload */
const BasicScreen<Application>* frontScreen() const { const Containers::LinkedList<BasicScreen<Application>>& screens() const {
return Containers::LinkedList<BasicScreen<Application>>::first(); return static_cast<const Containers::LinkedList<BasicScreen<Application>>&>(*this);
} }
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Front screen
* @deprecated Use `screens().first()` instead.
*/
CORRADE_DEPRECATED("use screens().first() instead") BasicScreen<Application>* frontScreen() { return screens().first(); }
/** @overload
* @deprecated Use `screens().first()` instead.
*/
CORRADE_DEPRECATED("use screens().first() instead") const BasicScreen<Application>* frontScreen() const { return screens().first(); }
/** /**
* @brief Back screen * @brief Back screen
* * @deprecated Use `screens().last()` instead.
* @see @ref BasicScreen::nextFartherScreen(), @ref BasicScreen::nextNearerScreen()
*/ */
BasicScreen<Application>* backScreen() { CORRADE_DEPRECATED("use screens().back() instead") BasicScreen<Application>* backScreen() { return screens().last(); }
return Containers::LinkedList<BasicScreen<Application>>::last();
} /**
/** @overload */ * @overload
const BasicScreen<Application>* backScreen() const { * @deprecated Use `screens().last()` instead.
return Containers::LinkedList<BasicScreen<Application>>::last(); */
} CORRADE_DEPRECATED("use screens().back() instead") const BasicScreen<Application>* backScreen() const { return screens().last(); }
#endif
protected: protected:
/* Nobody will need to have (and delete) ScreenedApplication*, thus /* Nobody will need to have (and delete) ScreenedApplication*, thus

23
src/Magnum/Platform/ScreenedApplication.hpp

@ -49,7 +49,7 @@ template<class Application> BasicScreenedApplication<Application>::~BasicScreene
template<class Application> BasicScreenedApplication<Application>& BasicScreenedApplication<Application>::addScreen(BasicScreen<Application>& screen) { template<class Application> BasicScreenedApplication<Application>& BasicScreenedApplication<Application>::addScreen(BasicScreen<Application>& screen) {
Containers::LinkedList<BasicScreen<Application>>::insert(&screen); Containers::LinkedList<BasicScreen<Application>>::insert(&screen);
if(frontScreen() == &screen) screen.focusEvent(); if(screens().first() == &screen) screen.focusEvent();
Application::redraw(); Application::redraw();
return *this; return *this;
} }
@ -63,10 +63,10 @@ template<class Application> BasicScreenedApplication<Application>& BasicScreened
template<class Application> BasicScreenedApplication<Application>& BasicScreenedApplication<Application>::focusScreen(BasicScreen<Application>& screen) { template<class Application> BasicScreenedApplication<Application>& BasicScreenedApplication<Application>::focusScreen(BasicScreen<Application>& screen) {
/* Already focused, nothing to do */ /* Already focused, nothing to do */
if(frontScreen() == &screen) return *this; if(screens().first() == &screen) return *this;
frontScreen()->blurEvent(); screens().first()->blurEvent();
Containers::LinkedList<BasicScreen<Application>>::move(&screen, frontScreen()); Containers::LinkedList<BasicScreen<Application>>::move(&screen, screens().first());
screen.focusEvent(); screen.focusEvent();
Application::redraw(); Application::redraw();
return *this; return *this;
@ -78,13 +78,12 @@ template<class Application> void BasicScreenedApplication<Application>::viewport
/* Call viewport event after all other (because of framebuffer resizing) */ /* Call viewport event after all other (because of framebuffer resizing) */
globalViewportEvent(size); globalViewportEvent(size);
for(BasicScreen<Application>* s = Containers::LinkedList<BasicScreen<Application>>::first(); s; s = s->next()) for(BasicScreen<Application>& s: *this) s.viewportEvent(size);
s->viewportEvent(size);
} }
template<class Application> void BasicScreenedApplication<Application>::drawEvent() { template<class Application> void BasicScreenedApplication<Application>::drawEvent() {
/* Back-to-front rendering */ /* Back-to-front rendering */
for(BasicScreen<Application>* s = backScreen(); s; s = s->nextNearerScreen()) for(BasicScreen<Application>* s = screens().last(); s; s = s->nextNearerScreen())
if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Draw) s->drawEvent(); if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Draw) s->drawEvent();
/* Call global event after all other (because of buffer swapping) */ /* Call global event after all other (because of buffer swapping) */
@ -93,7 +92,7 @@ template<class Application> void BasicScreenedApplication<Application>::drawEven
template<class Application> void BasicScreenedApplication<Application>::keyPressEvent(typename Application::KeyEvent& event) { template<class Application> void BasicScreenedApplication<Application>::keyPressEvent(typename Application::KeyEvent& event) {
/* Front-to-back event propagation, stop when the event gets accepted */ /* Front-to-back event propagation, stop when the event gets accepted */
for(BasicScreen<Application>* s = frontScreen(); s; s = s->nextFartherScreen()) { for(BasicScreen<Application>* s = screens().first(); s; s = s->nextFartherScreen()) {
if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) {
s->keyPressEvent(event); s->keyPressEvent(event);
if(event.isAccepted()) break; if(event.isAccepted()) break;
@ -103,7 +102,7 @@ template<class Application> void BasicScreenedApplication<Application>::keyPress
template<class Application> void BasicScreenedApplication<Application>::keyReleaseEvent(typename Application::KeyEvent& event) { template<class Application> void BasicScreenedApplication<Application>::keyReleaseEvent(typename Application::KeyEvent& event) {
/* Front-to-back event propagation, stop when the event gets accepted */ /* Front-to-back event propagation, stop when the event gets accepted */
for(BasicScreen<Application>* s = frontScreen(); s; s = s->nextFartherScreen()) { for(BasicScreen<Application>* s = screens().first(); s; s = s->nextFartherScreen()) {
if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) {
s->keyReleaseEvent(event); s->keyReleaseEvent(event);
if(event.isAccepted()) break; if(event.isAccepted()) break;
@ -113,7 +112,7 @@ template<class Application> void BasicScreenedApplication<Application>::keyRelea
template<class Application> void BasicScreenedApplication<Application>::mousePressEvent(typename Application::MouseEvent& event) { template<class Application> void BasicScreenedApplication<Application>::mousePressEvent(typename Application::MouseEvent& event) {
/* Front-to-back event propagation, stop when the event gets accepted */ /* Front-to-back event propagation, stop when the event gets accepted */
for(BasicScreen<Application>* s = frontScreen(); s; s = s->nextFartherScreen()) { for(BasicScreen<Application>* s = screens().first(); s; s = s->nextFartherScreen()) {
if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) {
s->mousePressEvent(event); s->mousePressEvent(event);
if(event.isAccepted()) break; if(event.isAccepted()) break;
@ -123,7 +122,7 @@ template<class Application> void BasicScreenedApplication<Application>::mousePre
template<class Application> void BasicScreenedApplication<Application>::mouseReleaseEvent(typename Application::MouseEvent& event) { template<class Application> void BasicScreenedApplication<Application>::mouseReleaseEvent(typename Application::MouseEvent& event) {
/* Front-to-back event propagation, stop when the event gets accepted */ /* Front-to-back event propagation, stop when the event gets accepted */
for(BasicScreen<Application>* s = frontScreen(); s; s = s->nextFartherScreen()) { for(BasicScreen<Application>* s = screens().first(); s; s = s->nextFartherScreen()) {
if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) {
s->mouseReleaseEvent(event); s->mouseReleaseEvent(event);
if(event.isAccepted()) break; if(event.isAccepted()) break;
@ -133,7 +132,7 @@ template<class Application> void BasicScreenedApplication<Application>::mouseRel
template<class Application> void BasicScreenedApplication<Application>::mouseMoveEvent(typename Application::MouseMoveEvent& event) { template<class Application> void BasicScreenedApplication<Application>::mouseMoveEvent(typename Application::MouseMoveEvent& event) {
/* Front-to-back event propagation, stop when the event gets accepted */ /* Front-to-back event propagation, stop when the event gets accepted */
for(BasicScreen<Application>* s = frontScreen(); s; s = s->nextFartherScreen()) { for(BasicScreen<Application>* s = screens().first(); s; s = s->nextFartherScreen()) {
if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) {
s->mouseMoveEvent(event); s->mouseMoveEvent(event);
if(event.isAccepted()) break; if(event.isAccepted()) break;

Loading…
Cancel
Save