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
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 Application> class BasicScreenedApplication: public Application,
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() {
return Containers::LinkedList<BasicScreen<Application>>::first();
Containers::LinkedList<BasicScreen<Application>>& screens() {
return static_cast<Containers::LinkedList<BasicScreen<Application>>&>(*this);
}
/** @overload */
const BasicScreen<Application>* frontScreen() const {
return Containers::LinkedList<BasicScreen<Application>>::first();
const Containers::LinkedList<BasicScreen<Application>>& screens() const {
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
*
* @see @ref BasicScreen::nextFartherScreen(), @ref BasicScreen::nextNearerScreen()
* @deprecated Use `screens().last()` instead.
*/
BasicScreen<Application>* backScreen() {
return Containers::LinkedList<BasicScreen<Application>>::last();
}
/** @overload */
const BasicScreen<Application>* backScreen() const {
return Containers::LinkedList<BasicScreen<Application>>::last();
}
CORRADE_DEPRECATED("use screens().back() instead") BasicScreen<Application>* backScreen() { return screens().last(); }
/**
* @overload
* @deprecated Use `screens().last()` instead.
*/
CORRADE_DEPRECATED("use screens().back() instead") const BasicScreen<Application>* backScreen() const { return screens().last(); }
#endif
protected:
/* 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) {
Containers::LinkedList<BasicScreen<Application>>::insert(&screen);
if(frontScreen() == &screen) screen.focusEvent();
if(screens().first() == &screen) screen.focusEvent();
Application::redraw();
return *this;
}
@ -63,10 +63,10 @@ template<class Application> BasicScreenedApplication<Application>& BasicScreened
template<class Application> BasicScreenedApplication<Application>& BasicScreenedApplication<Application>::focusScreen(BasicScreen<Application>& screen) {
/* Already focused, nothing to do */
if(frontScreen() == &screen) return *this;
if(screens().first() == &screen) return *this;
frontScreen()->blurEvent();
Containers::LinkedList<BasicScreen<Application>>::move(&screen, frontScreen());
screens().first()->blurEvent();
Containers::LinkedList<BasicScreen<Application>>::move(&screen, screens().first());
screen.focusEvent();
Application::redraw();
return *this;
@ -78,13 +78,12 @@ template<class Application> void BasicScreenedApplication<Application>::viewport
/* Call viewport event after all other (because of framebuffer resizing) */
globalViewportEvent(size);
for(BasicScreen<Application>* s = Containers::LinkedList<BasicScreen<Application>>::first(); s; s = s->next())
s->viewportEvent(size);
for(BasicScreen<Application>& s: *this) s.viewportEvent(size);
}
template<class Application> void BasicScreenedApplication<Application>::drawEvent() {
/* 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();
/* 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) {
/* 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) {
s->keyPressEvent(event);
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) {
/* 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) {
s->keyReleaseEvent(event);
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) {
/* 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) {
s->mousePressEvent(event);
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) {
/* 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) {
s->mouseReleaseEvent(event);
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) {
/* 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) {
s->mouseMoveEvent(event);
if(event.isAccepted()) break;

Loading…
Cancel
Save