Merge branch 'mingw-dev' into pre-merge

This commit is contained in:
Kirigaya Kazuto 2017-04-10 20:49:07 +08:00
commit 7f238b9935
2 changed files with 152 additions and 8 deletions

View File

@ -129,6 +129,32 @@ namespace MiniEngine
return str.c_str();
}
RWOP::RWOP(FILE* fp,bool autoclose)
{
SDL_bool b=autoclose?SDL_TRUE:SDL_FALSE;
op.reset(SDL_RWFromFP(fp,b),[](SDL_RWops* p){SDL_RWclose(p);});
}
RWOP::RWOP(const std::string& filename,const std::string& openmode)
{
op.reset(SDL_RWFromFile(filename.c_str(),openmode.c_str()),[](SDL_RWops* p){SDL_RWclose(p);});
}
RWOP::RWOP(const void* mem,int size)
{
op.reset(SDL_RWFromConstMem(mem,size),[](SDL_RWops* p){SDL_RWclose(p);});
}
RWOP::RWOP(void* mem,int size)
{
op.reset(SDL_RWFromMem(mem,size),[](SDL_RWops* p){SDL_RWclose(p);});
}
int Surface::savePNG(const std::string& filename)
{
return IMG_SavePNG(surf.get(),filename.c_str());
}
Texture::Texture()
{
updateInfo();
@ -435,10 +461,10 @@ namespace MiniEngine
void Window::setRenderer(std::initializer_list<RendererType> RendererFlags)
{
int flag = 0;
Uint32 flag = 0;
for (auto v : RendererFlags)
{
flag |= static_cast<int>(v);
flag |= _render_caster(v);
}
_setRenderer_Real(flag);
}
@ -533,6 +559,24 @@ namespace MiniEngine
return s;
}
Uint32 Window::_render_caster(RendererType Type)
{
switch(Type)
{
case RendererType::Accelerated:
return SDL_RENDERER_ACCELERATED;
case RendererType::PresentSync:
return SDL_RENDERER_PRESENTVSYNC;
case RendererType::Software:
return SDL_RENDERER_SOFTWARE;
case RendererType::TargetTexture:
return SDL_RENDERER_TARGETTEXTURE;
}
/// If an error occurs, return 0 by default.
return 0;
}
void Window::_setRenderer_Real(Uint32 flags)
{
winrnd.rnd.reset(SDL_CreateRenderer(wnd.get(), -1, flags), SDL_DestroyRenderer);
@ -579,6 +623,31 @@ namespace MiniEngine
return (font.get() != nullptr);
}
void Font::_real_setFontStyle(int Style)
{
TTF_SetFontStyle(font.get(),Style);
}
int Font::_style_caster(Style style)
{
switch(style)
{
case Style::Bold:
return TTF_STYLE_BOLD;
case Style::Italic:
return TTF_STYLE_ITALIC;
case Style::Normal:
return TTF_STYLE_NORMAL;
case Style::StrikeThrough:
return TTF_STYLE_STRIKETHROUGH;
case Style::UnderLine:
return TTF_STYLE_UNDERLINE;
}
/// If an error occurs, return 0 instead of -1.
return 0;
}
Texture Font::renderText(Renderer rnd, std::string Text, RGBA fg)
{
Surface surf;

View File

@ -72,6 +72,19 @@ namespace MiniEngine
std::string str;
};
class RWOP
{
public:
RWOP(FILE* fp,bool autoclose);
RWOP(const std::string& filename,const std::string& openmode);
RWOP(const void* mem,int size);
RWOP(void* mem,int size);
RWOP()=default;
~RWOP()=default;
private:
std::shared_ptr<SDL_RWops> op;
};
enum class BlendMode
{
None = SDL_BLENDMODE_NONE,
@ -84,6 +97,7 @@ namespace MiniEngine
{
public:
~Surface() = default;
int savePNG(const std::string& filename);
protected:
Surface() = default;
private:
@ -124,10 +138,10 @@ namespace MiniEngine
enum class RendererType
{
Software = SDL_RENDERER_SOFTWARE,
Accelerated = SDL_RENDERER_ACCELERATED,
PresentSync = SDL_RENDERER_PRESENTVSYNC,
TargetTexture = SDL_RENDERER_TARGETTEXTURE
Software,
Accelerated,
PresentSync,
TargetTexture
};
enum class FlipMode { None, Horizontal, Vertical };
@ -135,6 +149,7 @@ namespace MiniEngine
class Renderer
{
public:
Renderer() = default;
int setColor(RGBA pack);
RGBA getColor();
int setBlendMode(BlendMode mode);
@ -163,7 +178,6 @@ namespace MiniEngine
Texture loadTexture(std::string FileName) throw(ErrorViewer);
Texture createTexture(int Width, int Height) throw(ErrorViewer);
Renderer() = default;
bool isReady();
private:
std::shared_ptr<SDL_Renderer> rnd;
@ -178,7 +192,20 @@ namespace MiniEngine
Window(std::string Title, int Width, int Height, std::initializer_list<RendererType> RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture }) throw(ErrorViewer);
Renderer getRenderer() const;
void setRenderer(std::initializer_list<RendererType> RendererFlags);
void setRenderer(RendererType Type)
{
_internal_rndflagcalc=0;
_setRenderer(Type);
}
template<typename... Args>
void setRenderer(RendererType Type,Args&&... args)
{
_internal_rndflagcalc=0;
_setRenderer(Type,std::forward<RendererType>(args...));
}
void setRenderer(std::initializer_list<RendererType>);
Rect getSize();
void setSize(Rect sizeRect);
@ -207,8 +234,23 @@ namespace MiniEngine
_DECL_DEPRECATED Surface getSurface();
protected:
template<typename... Args>
void _setRenderer(RendererType Type,Args&&... args)
{
_internal_rndflagcalc|=_render_caster(Type);
_setRenderer(args...);
}
void _setRenderer(RendererType Type)
{
_internal_rndflagcalc|=_render_caster(Type);
_setRenderer_Real(_internal_rndflagcalc);
}
private:
void _setRenderer_Real(Uint32 flags);
Uint32 _internal_rndflagcalc;
Uint32 _render_caster(RendererType);
std::shared_ptr<SDL_Window> wnd;
Renderer winrnd;
};
@ -216,10 +258,27 @@ namespace MiniEngine
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<typename... Args>
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<Style> getFontStyles();
Texture renderText(Renderer rnd, std::string Text, RGBA fg);
Texture renderTextWrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength);
Texture renderTextShaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg);
@ -229,7 +288,23 @@ namespace MiniEngine
Texture renderUTF8Wrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength);
Texture renderUTF8Shaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg);
Texture renderUTF8Solid(Renderer rnd, std::string Text, RGBA fg);
protected:
template<typename... Args>
void _setFontStyle(Style style,Args&&... args)
{
_internal_fontcalc|=_style_caster(style);
_setFontStyle(args...);
}
void _setFontStyle(Style style)
{
_internal_fontcalc|=_style_caster(style);
_real_setFontStyle(_internal_fontcalc);
}
private:
void _real_setFontStyle(int);
int _style_caster(Style);
int _internal_fontcalc;
std::shared_ptr<TTF_Font> font;
};