From 2c75d95ddf849996bfc18267a9eecb4d0f4e1916 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 16 Mar 2022 15:30:37 -0400 Subject: signs can be read now! --- src/renderer.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/renderer.h') diff --git a/src/renderer.h b/src/renderer.h index de1e125..ce2e7e1 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -3,10 +3,13 @@ #include #include +#include #include #include #include #include +#include +#include #include "consts.h" class Game; @@ -27,6 +30,14 @@ public: } }; +class ttf_error : public std::logic_error { +public: + + ttf_error() : std::logic_error(TTF_GetError()) + { + } +}; + class sdl_wrapper { public: @@ -67,6 +78,26 @@ public: } }; +class ttf_wrapper { +public: + + ttf_wrapper() + { + if (TTF_Init() != 0) + { + ttf_error ex; + TTF_Quit(); + + throw ex; + } + } + + ~ttf_wrapper() + { + TTF_Quit(); + } +}; + class window_deleter { public: @@ -111,6 +142,16 @@ public: using texture_ptr = std::unique_ptr; +class font_deleter { +public: + + void operator()(TTF_Font* ptr) { + TTF_CloseFont(ptr); + } +}; + +using font_ptr = std::unique_ptr; + class Renderer { public: @@ -122,14 +163,18 @@ public: void renderTitle(int num, double fade); + TTF_Font* getFont() { return font_.get(); } + private: void loadTextureFromFile(std::string_view path, texture_ptr& texture); sdl_wrapper sdl_; img_wrapper img_; + ttf_wrapper ttf_; window_ptr win_; renderer_ptr ren_; + font_ptr font_; texture_ptr playerFade_; texture_ptr lampFade_; @@ -142,6 +187,18 @@ private: std::array titles_; std::array titleWidths_; std::array titleHeights_; + + // Text rendering + struct MessageCache { + texture_ptr renderedTex; + std::vector charIndexToWidth; + std::string line; + std::string overflow; + }; + + void renderMessageLine(MessageCache& line, const std::string& text, const Game& game); + + MessageCache messageLines_[2]; }; #endif /* end of include guard: RENDERER_H_6A58EC30 */ -- cgit 1.4.1