From c83de594c20defdda0c9537ee327d45aae7d13a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 20 Aug 2012 09:47:16 +0200 Subject: [PATCH] AbstractXContext: ability to exit from main loop, added Esc key. --- src/Contexts/AbstractXContext.cpp | 12 ++++++------ src/Contexts/AbstractXContext.h | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Contexts/AbstractXContext.cpp b/src/Contexts/AbstractXContext.cpp index ffc4e10f5..26e108771 100644 --- a/src/Contexts/AbstractXContext.cpp +++ b/src/Contexts/AbstractXContext.cpp @@ -26,7 +26,7 @@ using namespace std; namespace Magnum { namespace Contexts { -AbstractXContext::AbstractXContext(AbstractGlInterface* glInterface, int&, char**, const string& title, const Math::Vector2& size): glInterface(glInterface), viewportSize(size), _redraw(true) { +AbstractXContext::AbstractXContext(AbstractGlInterface* glInterface, int&, char**, const string& title, const Math::Vector2& size): glInterface(glInterface), viewportSize(size), flags(Flag::Redraw) { /* Get default X display */ display = XOpenDisplay(0); @@ -40,7 +40,7 @@ AbstractXContext::AbstractXContext(AbstractGlInterfaceswapBuffers(); } /** @copydoc GlutContext::redraw() */ - inline void redraw() { _redraw = true; } + inline void redraw() { flags |= Flag::Redraw; } /*@}*/ @@ -111,6 +114,8 @@ class AbstractXContext: public AbstractContext { * @see keyPressEvent(), keyReleaseEvent() */ enum class Key: KeySym { + Esc = XK_Escape, /**< Escape */ + Up = XK_Up, /**< Up arrow */ Down = XK_Down, /**< Down arrow */ Left = XK_Left, /**< Left arrow */ @@ -245,6 +250,14 @@ class AbstractXContext: public AbstractContext { /*@}*/ private: + enum class Flag: unsigned int { + Redraw = 1 << 0, + Exit = 1 << 1 + }; + + typedef Corrade::Containers::EnumSet Flags; + CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) + Display* display; Window window; Atom deleteWindow; @@ -254,10 +267,11 @@ class AbstractXContext: public AbstractContext { /** @todo Get this from the created window */ Math::Vector2 viewportSize; - bool _redraw; + Flags flags; }; CORRADE_ENUMSET_OPERATORS(AbstractXContext::Modifiers) +CORRADE_ENUMSET_OPERATORS(AbstractXContext::Flags) /* Implementations for inline functions with unused parameters */ inline void AbstractXContext::keyPressEvent(Key, Modifiers, const Math::Vector2&) {}