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
ui_text.hpp
Go to the documentation of this file.
1
11
12#ifndef ZOAPPUITEXT_H
13#define ZOAPPUITEXT_H
14
15#include "toymaker/sim_system.hpp"
16#include "toymaker/text_render.hpp"
17
23class UIText: public ToyMaker::SimObjectAspect<UIText> {
24public:
29 UIText(): SimObjectAspect<UIText>{0} {}
30
36 inline static std::string getSimObjectAspectTypeName() { return "UIText"; }
37
44 static std::shared_ptr<BaseSimObjectAspect> create(const nlohmann::json& jsonAspectProperties);
45
51 std::shared_ptr<BaseSimObjectAspect> clone() const override;
52
57 void onActivated() override;
58
64 inline std::string getText() const { return mText; }
65
71 void updateText(const std::string& newText);
72
78 void updateColor(glm::u8vec4 newColour);
79
85 void updateScale(float scale);
86
92 void updateFont(const std::string& textResourceName);
93
99 void updateAnchor(glm::vec2 anchor);
100
101private:
106 void recomputeTexture();
107
112 glm::u8vec4 mColor {0x00, 0x00, 0x00, 0xFF};
113
118 std::shared_ptr<ToyMaker::TextFont> mFont {};
119
124 std::string mText {};
125
130 float mScale { 1e-2 };
131
136 uint32_t mMaxWidthPixels { 0 };
137
142 glm::vec2 mAnchor {0.f, 0.f};
143};
144
145#endif
An object containing closely related methods and data, and exposing object lifecycle and application ...
Definition sim_system.hpp:956
std::shared_ptr< ToyMaker::TextFont > mFont
The font used to render the text texture used by this object.
Definition ui_text.hpp:118
glm::u8vec4 mColor
The color associated with the text rendered by this object.
Definition ui_text.hpp:112
std::string getText() const
Gets the actual text associated with this UIText object.
Definition ui_text.hpp:64
std::shared_ptr< BaseSimObjectAspect > clone() const override
Constructs a new UIText instance using this one as its blueprint.
Definition ui_text.cpp:59
void updateText(const std::string &newText)
Updates the text rendered by this object.
Definition ui_text.cpp:80
void updateFont(const std::string &textResourceName)
Updates the font using which this object's text texture is rendered.
Definition ui_text.cpp:86
void onActivated() override
Renders the initial text associated with this object once it becomes a part of the active scene.
Definition ui_text.cpp:70
float mScale
The scale, relative to the texture's dimensions, with which the object is made.
Definition ui_text.hpp:130
static std::shared_ptr< BaseSimObjectAspect > create(const nlohmann::json &jsonAspectProperties)
Creates a new UIText aspect based on its JSON description.
Definition ui_text.cpp:9
void updateScale(float scale)
Updates the scale of this object.
Definition ui_text.cpp:74
uint32_t mMaxWidthPixels
The width, in pixels, a single line of text is rendered on before it is wrapped around to the next li...
Definition ui_text.hpp:136
glm::vec2 mAnchor
The point considered the origin of this object, where (0,0) represents the top left hand corner,...
Definition ui_text.hpp:142
static std::string getSimObjectAspectTypeName()
Gets the aspect type string for this class.
Definition ui_text.hpp:36
void updateColor(glm::u8vec4 newColour)
Updates the color of the text rendered by this object.
Definition ui_text.cpp:101
std::string mText
The text displayed by this object on its associated StaticModel surface.
Definition ui_text.hpp:124
void recomputeTexture()
Recomputes the text texture and vertex offsets associated with this object based on its configuration...
Definition ui_text.cpp:107
UIText()
Constructs a new UIText aspect.
Definition ui_text.hpp:29
void updateAnchor(glm::vec2 anchor)
Updates the point considered this object's origin, where (0,0) represents the top left corner of the ...
Definition ui_text.cpp:95