From 592a4bbae44f7d7baea260e51a0092f77170f3de Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Wed, 5 Apr 2017 09:23:13 +0800 Subject: [PATCH 1/5] Add Font Style Support --- MiniEngine.cpp | 25 +++++++++++++++++++++++++ MiniEngine.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 0dc49e1..1938803 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -579,6 +579,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; diff --git a/MiniEngine.h b/MiniEngine.h index c1864f7..678ae22 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -216,10 +216,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 + 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