From f64ebc6219bbff7c99a0bf889228c17d83289704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 19 Feb 2017 20:29:22 +0100 Subject: [PATCH] Platform: use Flag::Redraw instead of a boolean in GlfwApplication. Also properly reset it before drawEvent() so the users can control the amount of redrawing themselves. --- src/Magnum/Platform/GlfwApplication.cpp | 5 +++-- src/Magnum/Platform/GlfwApplication.h | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index e5ac6e50b..7b851e785 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -52,7 +52,7 @@ GlfwApplication::GlfwApplication(const Arguments& arguments, const Configuration GlfwApplication::GlfwApplication(const Arguments& arguments, std::nullptr_t): _context{new Context{NoCreate, arguments.argc, arguments.argv}}, - _needsRedraw(true) + _flags{Flag::Redraw} { /* Save global instance */ _instance = this; @@ -154,7 +154,8 @@ void GlfwApplication::setSwapInterval(const Int interval) { int GlfwApplication::exec() { while(!glfwWindowShouldClose(_window)) { - if(_needsRedraw) { + if(_flags & Flag::Redraw) { + _flags &= ~Flag::Redraw; drawEvent(); } glfwPollEvents(); diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 785ba4199..fae1fbcde 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -183,7 +183,7 @@ class GlfwApplication { void setSwapInterval(Int interval); /** @copydoc Sdl2Application::redraw() */ - void redraw() { _needsRedraw = true; } + void redraw() { _flags |= Flag::Redraw; } #ifdef DOXYGEN_GENERATING_OUTPUT protected: @@ -241,6 +241,13 @@ class GlfwApplication { /*@}*/ private: + enum class Flag: UnsignedByte { + Redraw = 1 << 0 + }; + + typedef Containers::EnumSet Flags; + CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) + static void staticViewportEvent(GLFWwindow*, int w, int h) { _instance->viewportEvent({w, h}); } @@ -259,9 +266,11 @@ class GlfwApplication { GLFWwindow* _window; std::unique_ptr _context; - bool _needsRedraw; + Flags _flags; }; +CORRADE_ENUMSET_OPERATORS(GlfwApplication::Flags) + /** @brief Configuration