Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
text.h
Go to the documentation of this file.
1 #ifndef TEXT_H
2 #define TEXT_H
3 #include <glm/glm.hpp>
4 #include <memory>
5 #include "component.h"
6 #include "graphics/ui/font.h"
7 #include "graphics/vertex_data.h"
8 #include "graphics/shader.h"
9 #include "transform.h"
10 //= SCRIPTABLE
11 //= SCRIPTABLE BASES Component
12 
13 namespace Graphics {
14  namespace UI {
18  class Text : public Component {
19  protected:
20  std::shared_ptr<Font> font;
21  std::string text;
22  glm::vec4 color;
23  std::shared_ptr<Shader> shader;
24  float kerning;
25 
26  void renderCharacter(const unsigned char character, Transform transform);
27 
28  public:
29  //= BEGIN SCRIPTABLE
30 
34  Text();
40  void setFont(const std::shared_ptr<Font> font);
46  virtual void setText(const std::string& text);
52  std::string getText() const noexcept;
58  void setColor(const glm::vec4& color);
64  glm::vec4 getColor() const noexcept;
70  void setShader(std::shared_ptr<Shader> shader);
76  void setKerning(const float amount) noexcept;
82  float getKerning() const noexcept;
88  std::string to_string() const noexcept;
89  virtual std::string className() const noexcept override;
90  //= END SCRIPTABLE
91 
92  virtual void onDestroy() override;
93  virtual void onStart() override;
94  virtual bool onUpdate(const double delta) override;
95  void handleQueuedEvent(std::shared_ptr<Events::Event> event) override;
96  void onNotifyNow(std::shared_ptr<Events::Event> event) override;
97  virtual unsigned long long getValueForSorting() const noexcept override;
98 
99  virtual void log(el::base::type::ostream_t& os) const;
100  };
101  }
102 }
103 
104 #endif
Class for text.
Definition: text.h:18
void handleQueuedEvent(std::shared_ptr< Events::Event > event) override
HandleQueuedEvent allows derived classes to define behaviour for when queuedEvents are received...
Definition: text.cpp:77
Class for shader.
Definition: shader.h:17
void setFont(const std::shared_ptr< Font > font)
Sets the font.
Definition: text.cpp:13
virtual unsigned long long getValueForSorting() const noexceptoverride
Gets the value for sorting.
Definition: text.cpp:51
void setKerning(const float amount) noexcept
Sets the kerning.
Definition: text.cpp:37
Base Class for all components.
Definition: component.h:20
virtual void setText(const std::string &text)
Sets the text string.
Definition: text.cpp:17
virtual void onStart() override
Called when the engine starts and when a new scene is loaded.
Definition: text.cpp:89
std::string getText() const noexcept
Gets the text string.
Definition: text.cpp:21
std::shared_ptr< Font > font
Definition: text.h:20
float getKerning() const noexcept
Gets the kerning.
Definition: text.cpp:41
void setShader(std::shared_ptr< Shader > shader)
Sets the shader.
Definition: text.cpp:33
virtual void log(el::base::type::ostream_t &os) const
Definition: text.cpp:123
glm::vec4 getColor() const noexcept
Gets the color.
Definition: text.cpp:29
glm::vec4 color
Definition: text.h:22
Class for transform.
Definition: transform.h:13
std::shared_ptr< Transform > transform
Definition: component.h:23
std::shared_ptr< Shader > shader
Definition: text.h:23
std::string text
Definition: text.h:21
Text()
Constructor for Text.
Definition: text.cpp:9
std::string to_string() const noexcept
Returns a string representation of the object.
Definition: text.cpp:45
void renderCharacter(const unsigned char character, Transform transform)
Definition: text.cpp:55
void onNotifyNow(std::shared_ptr< Events::Event > event) override
When receiving an event that is immediate, onNotifyNow is used. It acts as an interrupt to make sure ...
Definition: text.cpp:81
virtual void onDestroy() override
Called when the engine is shutting down.
Definition: text.cpp:85
float kerning
Definition: text.h:24
virtual std::string className() const noexceptoverride
Returns a string representing the class name.
Definition: text.cpp:119
virtual bool onUpdate(const double delta) override
Called every engine loop.
Definition: text.cpp:92
void setColor(const glm::vec4 &color)
Sets the color.
Definition: text.cpp:25