Nox Engine
 
Loading...
Searching...
No Matches
Text.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "ECS.h"
9#include "TextureManager.h"
10#include <SDL2/SDL_ttf.h>
11
16struct Text : public Component {
17public:
26 Text(std::string inStr, int x, int y, float scale, SDL_Color color);
34 Text(std::string inStr, int x, int y, float scale);
41 Text(std::string inStr, int x, int y);
42
43 ~Text() override;
44
48 void update() override;
52 void draw() override;
53
58 void changeText(std::string text);
64
65protected:
66 std::string data;
67 float scale;
68 SDL_Texture* textTex;
69 SDL_Colour textColour;
70 SDL_Rect destRect;
71
76 void setTex(const char* text);
77};
Defines the core classes for the Entity-Component-System (ECS) architecture.
ComponentID getComponentTypeID() noexcept
Gets the unique ID for a given component type.
Definition ECS.h:39
A static utility class for loading and drawing textures.
The base class for all components in the ECS.
Definition ECS.h:53
A component that renders a string of text on the screen.
Definition Text.h:16
void setTex(const char *text)
Creates a new texture from a string of text.
Definition Text.cpp:62
void draw() override
Draws the text texture to the screen.
Definition Text.cpp:41
void changeText(std::string text)
Changes the text content and regenerates the texture.
Definition Text.cpp:48
void centreText(SDL_Rect &parentRect)
Adjusts the text's position to be centered within a parent rectangle.
Definition Text.cpp:52
void update() override
Updates the destination rectangle for rendering.
Definition Text.cpp:36