Ember
A C++ 20 'game engine' built with SDL3 with wide platform support.
label.h
Go to the documentation of this file.
1 #pragma once
2 #include "node.h"
3 
4 
5 /* * @brief 2D Label Node
6  *
7  * @details A 2D label node that can be added to the scene graph.
8  * - Supports custom fonts, font sizes, and colors.
9  * - Can apply UberShader effects like outline and shadow.
10  *
11  * @version 1.1.0
12  */
13 class Label final : public Node2D {
14 
15 public:
16  explicit Label(const std::string& font_alias, const std::string& text, const int ft_size = 0, const Color& color = Color::WHITE)
17  : _font_alias(font_alias), _text(text), _color(color.normalize_color()), _font_size(ft_size) {
18  }
19 
20  Label(const std::string& font_path, const std::string& font_alias, const std::string& text, int ft_size = 16,
21  const Color& color = Color::WHITE);
22 
23  void ready() override;
24 
25  void process(double delta_time) override;
26 
27  void draw(Renderer* renderer) override;
28 
29  std::string get_text() const;
30 
31  void set_text(const char* fmt, ...);
32 
33  void set_font_size(float size);
34 
35  void set_text_color(const Color& color);
36 
37  void set_outline(bool enabled, float thickness = 1.f, const Color& color = Color::BLACK);
38 
39  void set_shadow(bool enabled, glm::vec2 offset = glm::vec2(-1.f), const Color& color = Color::BLACK);
40 
41  void input(const InputManager* input) override;
42  void draw_inspector() override;
43  void draw_hierarchy() override;
44  ~Label() override;
45 
46 private:
47  std::string _font_alias = "default";
48  std::string _text = "";
49  glm::vec4 _color = Color::WHITE.normalize_color();
50  UberShader _effect = UberShader::none();
51  int _font_size = 0;
52  float _kerning = 0.0f; // spacing between characters
53  std::string _path = "";
54  bool bb_code_enabled = false;
55 };
Definition: input_manager.h:117
Definition: label.h:13
void ready() override
Definition: label.cpp:15
void input(const InputManager *input) override
Definition: label.cpp:80
void set_outline(bool enabled, float thickness=1.f, const Color &color=Color::BLACK)
Definition: label.cpp:68
void set_font_size(float size)
Definition: label.cpp:60
void set_text_color(const Color &color)
Definition: label.cpp:64
~Label() override
Definition: label.cpp:169
void set_shadow(bool enabled, glm::vec2 offset=glm::vec2(-1.f), const Color &color=Color::BLACK)
Definition: label.cpp:74
void set_text(const char *fmt,...)
Definition: label.cpp:39
void draw_inspector() override
Definition: label.cpp:84
std::string get_text() const
Definition: label.cpp:35
void process(double delta_time) override
Definition: label.cpp:19
Label(const std::string &font_alias, const std::string &text, const int ft_size=0, const Color &color=Color::WHITE)
Definition: label.h:16
void draw(Renderer *renderer) override
Definition: label.cpp:23
void draw_hierarchy() override
Definition: label.cpp:165
2D Node base class for scene graph.
Definition: node.h:25
Base class for all renderers.
Definition: ember_core.h:109
Color struct.
Definition: engine_structs.h:85
static const Color WHITE
Definition: engine_structs.h:100
static const Color BLACK
Definition: engine_structs.h:101
glm::vec4 normalize_color() const
Definition: engine_structs.cpp:47
UberShader shader effects for rendering texts and sprites.
Definition: shader.h:8
static UberShader none()
Definition: shader.h:16