NWengine 0.9
Loading...
Searching...
No Matches
Text.h
1#pragma once
2#include "Font.h"
3#include "GameObject.h"
4#include "Shader.h"
5#include <list>
6
10class Text : public GameComponent {
11public:
16 static std::string GetType() { return "Text"; }
17
21 Text() = default;
22
26 ~Text();
27
32 Text(GameObject* go);
33
38
42 void Update() override;
43
48 void* GetGameObject() override;
49
54 void SetGameObject(void* go) override;
55
59 void UpdateGlyphs();
60
66 void SetFont(const std::string& path, Shader* shader);
67
72 void SetShader(Shader* shader);
73
79 fVec2 GetSize();
80
84 std::list<Character> characters;
85
89 Shader* _shader = nullptr;
90
94 Font* font = nullptr;
95
99 std::string text = "";
100
104 bool isBatched = true;
105
109 int layerOrder = 0;
110
114 Vector4<float> colors = Vector4<float>(1.0f, 1.0f, 1.0f, 1.0f); // Each color is 10 bits
115
119 fVec2 position = fVec2(0.0f, 0.0f);
120
124 fVec2 scale = fVec2(1.0f, 1.0f);
125
132 int Serialize(std::fstream* data, int offset) override;
133
140 int Deserialize(std::fstream* data, int offset) override;
141};
Defines the GameObject class and its related components.
Class representing a font asset.
Definition Font.h:34
Base class for game components.
Definition GameObject.h:29
Class representing a game object.
Definition GameObject.h:68
Class representing a shader asset.
Definition Shader.h:22
The Text class represents a text component that can be attached to a GameObject.
Definition Text.h:10
int layerOrder
layerOrder indicates the layer order of each glyph, changing this requires calling UpdateGlyph()
Definition Text.h:109
~Text()
Text destructor.
Definition Text.cpp:149
fVec2 scale
scale is the scale of the text.
Definition Text.h:124
Text()=default
Text constructor.
void UpdateGlyphs()
UpdateGlyphs updates the glyphs of the Text component.
Definition Text.cpp:49
GameObject * attachedObj
attachedObj is a pointer to the GameObject that the Text component is attached to.
Definition Text.h:37
Vector4< float > colors
colors is the color of the text.
Definition Text.h:114
static std::string GetType()
GetType returns the type of the Text component.
Definition Text.h:16
void SetFont(const std::string &path, Shader *shader)
SetFont sets the font of the Text component.
Definition Text.cpp:87
int Serialize(std::fstream *data, int offset) override
Serialize serializes the Text component data.
Definition Text.cpp:99
int Deserialize(std::fstream *data, int offset) override
Deserialize deserializes the Text component data.
Definition Text.cpp:119
Shader * _shader
_shader is a pointer to the shader used for rendering the text.
Definition Text.h:89
void * GetGameObject() override
GetGameObject returns the GameObject that the Text component is attached to.
Definition Text.cpp:80
bool isBatched
isBatched indicates whether the text is batched for rendering.
Definition Text.h:104
void Update() override
Update is called every frame to update the Text component.
Definition Text.cpp:12
std::string text
text is the string of text to be rendered.
Definition Text.h:99
Font * font
font is a pointer to the font used for rendering the text.
Definition Text.h:94
fVec2 GetSize()
Gets total size in pixels sets the shader of the text.
Definition Text.cpp:39
void SetGameObject(void *go) override
SetGameObject sets the GameObject that the Text component is attached to.
Definition Text.cpp:83
void SetShader(Shader *shader)
SetShader sets the shader of the Text component.
Definition Text.cpp:35
std::list< Character > characters
characters is a list of characters that make up the text.
Definition Text.h:84
fVec2 position
position is the position of the text.
Definition Text.h:119
Definition Maths.h:275