Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
text_render.hpp
Go to the documentation of this file.
1
11
18
19#ifndef FOOLSENGINE_TEXTRENDER_H
20#define FOOLSENGINE_TEXTRENDER_H
21
22#include <SDL2/SDL_ttf.h>
23
25#include "texture.hpp"
26
27namespace ToyMaker{
28 class TextFont;
29
35 class TextFont: public Resource<TextFont> {
36 public:
37 virtual ~TextFont();
38
45 explicit TextFont(const std::string& fontPath, uint16_t pointSize);
46
52 inline static std::string getResourceTypeName() { return "TextFont"; }
53
59 inline std::string getFontPath() const { return mFontPath; }
60
66 inline uint16_t getPointSize() const { return mPointSize; }
67
76 std::shared_ptr<Texture> renderText(
77 const std::string& text,
78 glm::u8vec3 textColor,
79 glm::u8vec3 backgroundColor
80 ) const;
81
90 std::shared_ptr<Texture> renderTextArea(
91 const std::string& text,
92 glm::u8vec4 textColor,
93 uint32_t wrapLength=0
94 ) const;
95
105 std::shared_ptr<Texture> renderText(
106 const std::string& text,
107 glm::u8vec4 textColor
108 ) const;
109
110
111 private:
119 static TTF_Font* LoadFont(const std::string& fontPath, uint16_t pointSize);
120
127 static std::shared_ptr<Texture> MakeTexture(SDL_Surface* surface);
128
133 TTF_Font* mFont;
134
139 std::string mFontPath;
140
145 uint16_t mPointSize;
146 };
147
171 class TextFontFromFile: public ResourceConstructor<TextFont, TextFontFromFile> {
172 public:
173 explicit TextFontFromFile(): ResourceConstructor<TextFont, TextFontFromFile>{0} {}
174 inline static std::string getResourceConstructorName() { return "fromFile"; }
175 private:
176 std::shared_ptr<IResource> createResource(const nlohmann::json& methodParameters) override;
177 };
178}
179
180#endif
ResourceConstructor(int explicitlyInitializeMe)
Definition resource_database.hpp:491
Resource(int explicitlyInitializeMe)
Definition resource_database.hpp:389
std::shared_ptr< IResource > createResource(const nlohmann::json &methodParameters) override
Creates a resource object using the parameters specified in methodParameters.
Definition text_render.cpp:27
A wrapper class over SDL_ttf, providing methods to generate text textures from text using a font as a...
Definition text_render.hpp:35
static std::string getResourceTypeName()
Gets the resource type string for this class.
Definition text_render.hpp:52
TTF_Font * mFont
A pointer to the underlying SDL_ttf font resource.
Definition text_render.hpp:133
uint16_t mPointSize
The point size with which the font was loaded.
Definition text_render.hpp:145
static TTF_Font * LoadFont(const std::string &fontPath, uint16_t pointSize)
The function responsible for actually loading the font from the path specified.
Definition text_render.cpp:20
std::string mFontPath
The path from which this font was loaded.
Definition text_render.hpp:139
std::shared_ptr< Texture > renderText(const std::string &text, glm::u8vec3 textColor, glm::u8vec3 backgroundColor) const
Uses this font to render some text against a solid background.
Definition text_render.cpp:33
std::string getFontPath() const
Gets the path of the TTF font file from which this resource was loaded.
Definition text_render.hpp:59
std::shared_ptr< Texture > renderTextArea(const std::string &text, glm::u8vec4 textColor, uint32_t wrapLength=0) const
Renders a texture for some text with a transparent background, which may run multiple lines,...
Definition text_render.cpp:72
TextFont(const std::string &fontPath, uint16_t pointSize)
Constructs a new Text Font object.
Definition text_render.cpp:7
static std::shared_ptr< Texture > MakeTexture(SDL_Surface *surface)
Utility function for converting an SDL surface into a Texture resource.
Definition text_render.cpp:93
uint16_t getPointSize() const
Gets the point size with which the font was loaded.
Definition text_render.hpp:66
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
Headers relating to resources and their management for a given project.
Header containing definitions of classes and functions related to loading and using Texture resources...