From 5c89c89ff8295f347425d12d0283bd4f806d2c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 4 Apr 2013 16:22:04 +0200 Subject: [PATCH] Platform: added window flags to Sdl2Application. Making resizable window the default to be consistent with GLUT and others. --- src/Platform/Sdl2Application.cpp | 8 +++++-- src/Platform/Sdl2Application.h | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 89c0cf290..d5e5b3855 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -86,10 +86,14 @@ bool Sdl2Application::tryCreateContext(Configuration* configuration) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, configuration->sampleCount() > 1 ? 1 : 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, configuration->sampleCount()); + /* Flags: if not hidden, set as shown */ + Uint32 flags(configuration->flags()); + if(!(configuration->flags() & Configuration::Flag::Hidden)) flags |= SDL_WINDOW_SHOWN; + if(!(window = SDL_CreateWindow(configuration->title().c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, configuration->size().x(), configuration->size().y(), - SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN))) { + SDL_WINDOW_OPENGL|flags))) { Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create window"; std::exit(2); } @@ -183,7 +187,7 @@ void Sdl2Application::setMouseLocked(bool enabled) { SDL_SetRelativeMouseMode(enabled ? SDL_TRUE : SDL_FALSE); } -Sdl2Application::Configuration::Configuration(): _title("Magnum SDL2 Application"), _size(800, 600), _sampleCount(0) {} +Sdl2Application::Configuration::Configuration(): _title("Magnum SDL2 Application"), _size(800, 600), _flags(Flag::Resizable), _sampleCount(0) {} Sdl2Application::Configuration::~Configuration() = default; Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseEvent::modifiers() { diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index ed901ec56..5ed06ed7a 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -196,6 +196,29 @@ class Sdl2Application::Configuration { Configuration& operator=(Configuration&&) = delete; public: + /** + * @brief Window flag + * + * @see Flags, setFlags() + */ + enum class Flag: Uint32 { + Resizable = SDL_WINDOW_RESIZABLE, /**< Resizable window */ + Fullscreen = SDL_WINDOW_FULLSCREEN, /**< Fullscreen window */ + Hidden = SDL_WINDOW_HIDDEN, /**< Hidden window */ + Maximized = SDL_WINDOW_MAXIMIZED, /**< Maximized window */ + Minimized = SDL_WINDOW_MINIMIZED, /**< Minimized window */ + MouseLocked = SDL_WINDOW_INPUT_GRABBED /**< Window with mouse locked */ + }; + + /** + * @brief Window flags + * + * @see setFlags() + */ + typedef Corrade::Containers::EnumSet Flags; + explicit Configuration(); ~Configuration(); @@ -227,6 +250,20 @@ class Sdl2Application::Configuration { return this; } + /** @brief Window flags */ + inline Flags flags() const { return _flags; } + + /** + * @brief Set window flags + * @return Pointer to self (for method chaining) + * + * Default is @ref Flag "Flag::Resizable". + */ + inline Configuration* setFlags(const Flags flags) { + _flags = flags; + return this; + } + /** @brief Sample count */ inline Int sampleCount() const { return _sampleCount; } @@ -245,9 +282,12 @@ class Sdl2Application::Configuration { private: std::string _title; Vector2i _size; + Flags _flags; Int _sampleCount; }; +CORRADE_ENUMSET_OPERATORS(Sdl2Application::Configuration::Flags) + /** @brief Base for input events