diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 588c301..222503d 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -458,179 +458,11 @@ namespace MiniEngine return _vec.at(index); } - //private - void Window::_set(SDL_Window* p) - { - _wnd.reset(p,SDL_DestroyWindow); - } - //private - void Window::_clear() - { - _wnd.reset(); - } - //private - SDL_Window* Window::_get() const - { - return _wnd.get(); - } - Window::Window(std::string Title, int Width, int Height, - std::initializer_list WindowFlags , int WindowPositionX, int WindowPositionY) throw(ErrorViewer) - { - /// 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; - e.fetch(); - throw e; - } - _set(temp); - } - - Renderer::Renderer(Window& wnd,std::initializer_list RendererFlags) throw (ErrorViewer) - { - if(createRenderer(wnd,RendererFlags)!=0) - { - throw ErrorViewer(); - } - } - - int Renderer::createRenderer(Window& wnd,std::initializer_list RendererFlags) - { - Uint32 flag = 0; - for (auto v : RendererFlags) - { - flag |= _rendertype_caster(v); - } - return _createRenderer_Real(wnd,flag); - } - - Rect Window::getSize() const - { - int w, h; - SDL_GetWindowSize(_get(), &w, &h); - return Rect(0, 0, w, h); - } - - void Window::setSize(const Rect& sizeRect) - { - setSize(sizeRect.w, sizeRect.h); - } - - void Window::setSize(int w, int h) - { - SDL_SetWindowSize(_get(), w, h); - } - - Point Window::getPosition() const - { - int x, y; - SDL_GetWindowPosition(_get(), &x, &y); - return Point(x, y); - } - - void Window::setPosition(int x, int y) - { - SDL_SetWindowPosition(_get(), x, y); - } - - void Window::setPosition(const Point& point) - { - SDL_SetWindowPosition(_get(), point.x, point.y); - } - - void Window::setTitle(const std::string& Title) - { - SDL_SetWindowTitle(_get(), Title.c_str()); - } - - std::string Window::getTitle() const - { - return std::string(SDL_GetWindowTitle(_get())); - } - - void Window::setGrab(bool isGrab) - { - SDL_SetWindowGrab(_get(),isGrab?SDL_TRUE:SDL_FALSE); - } - - bool Window::getGrab() const - { - return (SDL_GetWindowGrab(_get())==SDL_TRUE)?true:false; - } - - #if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5) - int Window::setOpacity(float opacity) - { - return SDL_SetWindowOpacity(_get(),opacity); - } - float Window::getOpacity() const - { - float op=-1; - SDL_GetWindowOpacity(_get(),&op); - return op; - } - #endif /// End of SDL2 2.0.5 Require. - - /// FIXME: Not Implemented. - void Window::setResizable(bool resizable) - { - //SDL_SetWindowResizable(_get(), resizable?SDL_TRUE:SDL_FALSE); - } - - void Window::show() - { - SDL_ShowWindow(_get()); - } - - void Window::hide() - { - SDL_HideWindow(_get()); - } - - void Window::raise() - { - SDL_RaiseWindow(_get()); - } - - void Window::minimize() - { - SDL_MinimizeWindow(_get()); - } - - void Window::maximize() - { - SDL_MaximizeWindow(_get()); - } - - void Window::restore() - { - SDL_RestoreWindow(_get()); - } - - _DECL_DEPRECATED Surface Window::getSurface() - { - SDL_Surface* temp = SDL_GetWindowSurface(_get()); - Surface s; - /// Don't Free This Surface - s._set_no_delete(temp); - return s; - } - - void Window::release() - { - _clear(); - } // private Uint32 Renderer::_rendertype_caster(RendererType Type) diff --git a/MiniEngine.h b/MiniEngine.h index 51da470..229eef8 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -136,63 +136,7 @@ namespace MiniEngine std::vector _vec; }; - class Window - { - public: - Window()=default; - Window(std::string Title, int Width, int Height, - std::initializer_list WindowFlags = {WindowType::Shown} , - int WindowPositionX=SDL_WINDOWPOS_CENTERED, int WindowPositionY=SDL_WINDOWPOS_CENTERED) throw(ErrorViewer); - Rect getSize() const; - void setSize(const Rect& sizeRect); - void setSize(int w, int h); - - Point getPosition() const; - void setPosition(int x, int y); - void setPosition(const Point& point); - - void setTitle(const std::string& Title); - std::string getTitle() const; - - void setGrab(bool isGrab); - bool getGrab() const; - - #if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5) - /// SDL2.0.5 Required. - int setOpacity(float opacity); - float getOpacity() const; - #endif - - /// FIXME: Not Implemented. - void setResizable(bool resizable); - - /// Use UTF8 in Title and Message please. - int showSimpleMessageBox(MessageBoxType type,const std::string& Title,const std::string& Message) const; - - int showMessageBox(const WindowMessageBox& box) const; - - void show(); - void hide(); - void raise(); - void minimize(); - void maximize(); - void restore(); - - _DECL_DEPRECATED Surface getSurface(); - - bool isScreenKeyboardShown(); - - void release(); - private: - std::shared_ptr _wnd; - - void _set(SDL_Window*); - void _clear(); - SDL_Window* _get() const; - - friend class Renderer; - }; enum class RendererType { Software, Accelerated, PresentSync, TargetTexture }; diff --git a/SDLWrapper/Renderer.cpp b/SDLWrapper/Renderer.cpp index da4d3fe..5194d00 100644 --- a/SDLWrapper/Renderer.cpp +++ b/SDLWrapper/Renderer.cpp @@ -19,6 +19,24 @@ SDL_Renderer* Renderer::_get() const return _rnd.get(); } +Renderer::Renderer(Window& wnd,std::initializer_list RendererFlags) throw (ErrorViewer) +{ + if(createRenderer(wnd,RendererFlags)!=0) + { + throw ErrorViewer(); + } +} + +int Renderer::createRenderer(Window& wnd,std::initializer_list RendererFlags) +{ + Uint32 flag = 0; + for (auto v : RendererFlags) + { + flag |= _rendertype_caster(v); + } + return _createRenderer_Real(wnd,flag); +} + int Renderer::setColor(const RGBA& pack) { return SDL_SetRenderDrawColor(_get(), pack.r, pack.g, pack.b, pack.a); diff --git a/SDLWrapper/Window.cpp b/SDLWrapper/Window.cpp new file mode 100644 index 0000000..89a62b6 --- /dev/null +++ b/SDLWrapper/Window.cpp @@ -0,0 +1,158 @@ +#include "Window.h" +#include "begin_code.h" +//private +void Window::_set(SDL_Window* p) +{ + _wnd.reset(p,SDL_DestroyWindow); +} + +//private +void Window::_clear() +{ + _wnd.reset(); +} + +//private +SDL_Window* Window::_get() const +{ + return _wnd.get(); +} + +Window::Window(std::string Title, int Width, int Height, + std::initializer_list WindowFlags, int WindowPositionX, int WindowPositionY) throw(ErrorViewer) +{ + /// 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; + e.fetch(); + throw e; + } + + _set(temp); +} + +Rect Window::getSize() const +{ + int w, h; + SDL_GetWindowSize(_get(), &w, &h); + return Rect(0, 0, w, h); +} + +void Window::setSize(const Rect& sizeRect) +{ + setSize(sizeRect.w, sizeRect.h); +} + +void Window::setSize(int w, int h) +{ + SDL_SetWindowSize(_get(), w, h); +} + +Point Window::getPosition() const +{ + int x, y; + SDL_GetWindowPosition(_get(), &x, &y); + return Point(x, y); +} + +void Window::setPosition(int x, int y) +{ + SDL_SetWindowPosition(_get(), x, y); +} + +void Window::setPosition(const Point& point) +{ + SDL_SetWindowPosition(_get(), point.x, point.y); +} + +void Window::setTitle(const std::string& Title) +{ + SDL_SetWindowTitle(_get(), Title.c_str()); +} + +std::string Window::getTitle() const +{ + return std::string(SDL_GetWindowTitle(_get())); +} + +void Window::setGrab(bool isGrab) +{ + SDL_SetWindowGrab(_get(),isGrab?SDL_TRUE:SDL_FALSE); +} + +bool Window::getGrab() const +{ + return (SDL_GetWindowGrab(_get())==SDL_TRUE)?true:false; +} + +#if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5) +int Window::setOpacity(float opacity) +{ + return SDL_SetWindowOpacity(_get(),opacity); +} +float Window::getOpacity() const +{ + float op=-1; + SDL_GetWindowOpacity(_get(),&op); + return op; +} +#endif /// End of SDL2 2.0.5 Require. + +/// FIXME: Not Implemented. +void Window::setResizable(bool resizable) +{ + //SDL_SetWindowResizable(_get(), resizable?SDL_TRUE:SDL_FALSE); +} + +void Window::show() +{ + SDL_ShowWindow(_get()); +} + +void Window::hide() +{ + SDL_HideWindow(_get()); +} + +void Window::raise() +{ + SDL_RaiseWindow(_get()); +} + +void Window::minimize() +{ + SDL_MinimizeWindow(_get()); +} + +void Window::maximize() +{ + SDL_MaximizeWindow(_get()); +} + +void Window::restore() +{ + SDL_RestoreWindow(_get()); +} + +_DECL_DEPRECATED Surface Window::getSurface() +{ + SDL_Surface* temp = SDL_GetWindowSurface(_get()); + Surface s; + /// Don't Free This Surface + s._set_no_delete(temp); + return s; +} + +void Window::release() +{ + _clear(); +} +#include "end_code.h" diff --git a/SDLWrapper/Window.h b/SDLWrapper/Window.h new file mode 100644 index 0000000..c5439ea --- /dev/null +++ b/SDLWrapper/Window.h @@ -0,0 +1,61 @@ +#pragma once +#include "includes.h" +#include "begin_code.h" +class Window +{ +public: + Window()=default; + Window(std::string Title, int Width, int Height, + std::initializer_list WindowFlags = {WindowType::Shown}, + int WindowPositionX=SDL_WINDOWPOS_CENTERED, int WindowPositionY=SDL_WINDOWPOS_CENTERED) throw(ErrorViewer); + + Rect getSize() const; + void setSize(const Rect& sizeRect); + void setSize(int w, int h); + + Point getPosition() const; + void setPosition(int x, int y); + void setPosition(const Point& point); + + void setTitle(const std::string& Title); + std::string getTitle() const; + + void setGrab(bool isGrab); + bool getGrab() const; + +#if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5) + /// SDL2.0.5 Required. + int setOpacity(float opacity); + float getOpacity() const; +#endif + + /// FIXME: Not Implemented. + void setResizable(bool resizable); + + /// Use UTF8 in Title and Message please. + int showSimpleMessageBox(MessageBoxType type,const std::string& Title,const std::string& Message) const; + + int showMessageBox(const WindowMessageBox& box) const; + + void show(); + void hide(); + void raise(); + void minimize(); + void maximize(); + void restore(); + + _DECL_DEPRECATED Surface getSurface(); + + bool isScreenKeyboardShown(); + + void release(); +private: + std::shared_ptr _wnd; + + void _set(SDL_Window*); + void _clear(); + SDL_Window* _get() const; + + friend class Renderer; +}; +#include "end_code.h"