From b6ecc0f8560db5f9b1603e38a4959db165afefe1 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Tue, 16 May 2017 22:33:21 +0800 Subject: [PATCH] Enhanced Window Constructor --- MiniEngine.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++-- MiniEngine.h | 15 +++++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index c7b9bd1..1f28b1a 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -51,6 +51,56 @@ namespace MiniEngine } } + /// FIXME: return SDL_WindowFlags or Uint32 ? + Uint32 getSDLWindowFlagsFromWindowType(WindowType type) + { + switch(type) + { + case WindowType::FullScreen: + return SDL_WINDOW_FULLSCREEN; + case WindowType::OpenGL: + return SDL_WINDOW_OPENGL; + case WindowType::Shown: + return SDL_WINDOW_SHOWN; + case WindowType::Hidden: + return SDL_WINDOW_HIDDEN; + case WindowType::Borderless: + return SDL_WINDOW_BORDERLESS; + case WindowType::Resizable: + return SDL_WINDOW_RESIZABLE; + case WindowType::Minimized: + return SDL_WINDOW_MINIMIZED; + case WindowType::Maximized: + return SDL_WINDOW_MAXIMIZED; + case WindowType::InputGrabbed: + return SDL_WINDOW_INPUT_GRABBED; + case WindowType::InputFocus: + return SDL_WINDOW_INPUT_FOCUS; + case WindowType::MouseFocus: + return SDL_WINDOW_MOUSE_FOCUS; + case WindowType::FullScreenDesktop: + return SDL_WINDOW_FULLSCREEN_DESKTOP; + case WindowType::Foreign: + return SDL_WINDOW_FOREIGN; + case WindowType::AllowHighDPI: + return SDL_WINDOW_ALLOW_HIGHDPI; + case WindowType::MouseCapture: + return SDL_WINDOW_MOUSE_CAPTURE; + case WindowType::AlwaysOnTop: + return SDL_WINDOW_ALWAYS_ON_TOP; + case WindowType::SkipTaskBar: + return SDL_WINDOW_SKIP_TASKBAR; + case WindowType::Utility: + return SDL_WINDOW_UTILITY; + case WindowType::ToolTip: + return SDL_WINDOW_TOOLTIP; + case WindowType::PopUpMenu: + return SDL_WINDOW_POPUP_MENU; + default: + return 0;/// Return 0 on default. + } + } + SystemCursorType getCursorTypeFromSDLSystemCursor(SDL_SystemCursor id) { switch(id) @@ -978,9 +1028,18 @@ namespace MiniEngine return _wnd.get(); } - Window::Window(std::string Title, int Width, int Height, std::initializer_list RendererFlags) throw(ErrorViewer) + Window::Window(std::string Title, int Width, int Height, + std::initializer_list RendererFlags, + std::initializer_list WindowFlags , int WindowPositionX, int WindowPositionY) throw(ErrorViewer) { - SDL_Window* temp = SDL_CreateWindow(Title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_WINDOW_SHOWN); + /// Calculate Window Flags + Uint32 windowFlag=0; + for(auto v:WindowFlags) + { + windowFlag|=_internal::getSDLWindowFlagsFromWindowType(v); + } + + SDL_Window* temp = SDL_CreateWindow(Title.c_str(), WindowPositionX, WindowPositionY, Width, Height, windowFlag); if (temp == NULL) { ErrorViewer e; diff --git a/MiniEngine.h b/MiniEngine.h index 6d93321..c02f55b 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -252,10 +252,23 @@ namespace MiniEngine enum class MessageBoxType { Error, Warning, Information }; + enum class WindowType + { + FullScreen, OpenGL, Shown, Hidden, + Borderless, Resizable, Minimized, Maximized, + InputGrabbed, InputFocus, MouseFocus, + FullScreenDesktop, Foreign, AllowHighDPI, + MouseCapture, AlwaysOnTop, SkipTaskBar, + Utility, ToolTip, PopUpMenu + }; + class Window { public: - Window(std::string Title, int Width, int Height, std::initializer_list RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture }) throw(ErrorViewer); + Window(std::string Title, int Width, int Height, + std::initializer_list RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture }, + std::initializer_list WindowFlags = {WindowType::Shown} , + int WindowPositionX=SDL_WINDOWPOS_CENTERED, int WindowPositionY=SDL_WINDOWPOS_CENTERED) throw(ErrorViewer); Renderer getRenderer() const; void setRenderer(RendererType Type)