#pragma once #include #undef main #include #include #include #include #include #include #define _DECL_DEPRECATED __declspec(deprecated) #define _DECL_DEPRECATED_MSG(InfoString) __declspec(deprecated(InfoString)) namespace MiniEngine { class Rect { public: int x, y, w, h; Rect(int X, int Y, int W, int H); Rect(); SDL_Rect toSDLRect(); }; class Point { public: int x, y; Point(int X, int Y); Point(); SDL_Point toSDLPoint(); bool inRect(Rect rect); }; class ColorMode { public: int r, g, b; ColorMode(int R, int G, int B); ColorMode(); }; class RGBA { public: int r, g, b, a; RGBA(int R, int G, int B, int A); RGBA(ColorMode mode, int A); RGBA(); SDL_Color toSDLColor(); ColorMode toColorMode(); }; class NonCopyable { protected: NonCopyable() = default; ~NonCopyable() = default; NonCopyable(const NonCopyable&) = delete; NonCopyable& operator = (const NonCopyable&) = delete; }; class ErrorViewer : public std::exception { public: void fetch(); std::string getError(); const char* what() const throw() override; private: std::string str; }; enum class BlendMode { None = SDL_BLENDMODE_NONE, Blend = SDL_BLENDMODE_BLEND, Add = SDL_BLENDMODE_ADD, Mod = SDL_BLENDMODE_MOD }; class Surface { public: ~Surface() = default; protected: Surface() = default; private: std::shared_ptr surf; friend class Window; friend class Renderer; friend class Font; }; class Texture { public: Texture(); ~Texture() = default; Rect getSize(); int getw(); int geth(); bool isReady(); int setBlendMode(BlendMode mode); BlendMode getBlendMode(); /// Alpha: 0: Transparent 255: opaque int setAlphaMode(int alpha); int getAlphaMode(); ColorMode getColorMode(); int setColorMode(ColorMode mode); RGBA getRGBA(); void setRGBA(RGBA pack); protected: /// updateInfo() must be called after Texture is changed. void updateInfo(); private: std::shared_ptr text; Rect rect; friend class Renderer; }; enum class RendererType { Software = SDL_RENDERER_SOFTWARE, Accelerated = SDL_RENDERER_ACCELERATED, PresentSync = SDL_RENDERER_PRESENTVSYNC, TargetTexture = SDL_RENDERER_TARGETTEXTURE }; enum class FlipMode { None, Horizontal, Vertical }; class Renderer { public: int setColor(RGBA pack); RGBA getColor(); int setBlendMode(BlendMode mode); BlendMode getBlendMode(); int setTarget(Texture& t); int setTarget(); int fillRect(Rect rect); int drawRect(Rect rect); int drawPoint(Point p); int clear(); void update(); int copy(Texture t, Rect src, Rect dst); int copyTo(Texture t, Rect dst); int copyTo(Texture t, Point lupoint); int copyFill(Texture t, Rect src); int copyFullFill(Texture t); int supercopy(Texture t,bool srcfull,Rect src,bool dstfull,Rect dst,double angle,bool haspoint,Point center,FlipMode mode); Surface loadSurface(std::string FileName) throw(ErrorViewer); Texture render(Surface surf) throw (ErrorViewer); Texture loadTexture(std::string FileName) throw(ErrorViewer); Texture createTexture(int Width, int Height) throw(ErrorViewer); Renderer() = default; bool isReady(); private: std::shared_ptr rnd; friend class Window; }; enum class MessageBoxType { Error,Warning,Information }; class Window { public: Window(std::string Title, int Width, int Height, std::initializer_list RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture }) throw(ErrorViewer); Renderer getRenderer() const; void setRenderer(std::initializer_list RendererFlags); Rect getSize(); void setSize(Rect sizeRect); void setSize(int w, int h); Rect getPosition(); void setPosition(int x, int y); /// FIXME: Use class Point or class Rect ? void setPosition(Point point); void setTitle(std::string Title); std::string getTitle(); void setResizable(bool resizable); /// Use UTF8 in Title and Message please. int showSimpleMessageBox(MessageBoxType type,std::string Title,std::string Message); void show(); void hide(); void raise(); void minimize(); void maximize(); void restore(); _DECL_DEPRECATED Surface getSurface(); private: void _setRenderer_Real(Uint32 flags); std::shared_ptr wnd; Renderer winrnd; }; class Font { public: enum class Style { Normal, Bold, Italic, UnderLine, StrikeThrough }; Font() = default; Font(std::string FontFileName, int size) throw(ErrorViewer); int use(std::string FontFileName, int size); bool isReady(); template void setFontStyle(Style style,Args&&... args) { _internal_fontcalc=0; _setFontStyle(style,std::forward(args...)); } void setFontStyle(Style style) { _real_setFontStyle(_style_caster(style)); } std::tuple