Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wrappable_text.h
Go to the documentation of this file.
1 #ifndef WRAPPABLE_TEXT_H
2 #define WRAPPABLE_TEXT_H
3 
4 #include <map>
5 #include "graphics/ui/text.h"
6 //= SCRIPTABLE
7 //= SCRIPTABLE BASES Text
8 
9 namespace Graphics {
10  namespace UI {
14  class WrappableText : public Text {
15  public:
16  //= SCRIPTABLE ENUM
20  enum HorizontalAlignment : unsigned int {LEFT, HCENTER, RIGHT};
21  //= SCRIPTABLE ENUM
25  enum VerticalAlignment : unsigned int { TOP, VCENTER, BOTTOM};
26  private:
27  float width;
28  float height;
29  VerticalAlignment vertical_alignment;
30  HorizontalAlignment horizontal_alignment;
31  Transform horizontal_alignment_transform;
32  Transform vertical_alignment_transform;
33  std::multimap<unsigned char, Transform> character_transforms;
34  float line_spacing;
35  protected:
36  std::vector<std::pair<float, std::vector<Character>>> splitTextIntoLines();
37  public:
38  //= BEGIN SCRIPTABLE
39 
43  WrappableText();
50  void setSize(float width, float height);
56  void setLineSpacing(float spacing);
62  void setHorizontalAlignment(const HorizontalAlignment& alignment);
68  void setVerticalAlignment(const VerticalAlignment& alignment);
69 
75  virtual void setText(const std::string& text) override;
81  virtual std::string to_string() const noexcept override;
82  virtual std::string className() const noexcept override;
83  //= END SCRIPTABLE
84 
85  virtual void onDestroy() override;
86  virtual void onStart() override;
87  virtual bool onUpdate(const double delta) override;
88  void handleQueuedEvent(std::shared_ptr<Events::Event> event) override;
89  void onNotifyNow(std::shared_ptr<Events::Event> event) override;
90 
91  virtual void log(el::base::type::ostream_t& os) const;
92  };
93  }
94 }
95 #endif
Class for text.
Definition: text.h:18
HorizontalAlignment
Horizontal Alignment Enum.
Definition: wrappable_text.h:20
std::vector< std::pair< float, std::vector< Character > > > splitTextIntoLines()
Definition: wrappable_text.cpp:28
virtual void onDestroy() override
Called when the engine is shutting down.
Definition: wrappable_text.cpp:142
void setLineSpacing(float spacing)
Sets the line spacing.
Definition: wrappable_text.cpp:24
void setVerticalAlignment(const VerticalAlignment &alignment)
Sets the vertical alignment.
Definition: wrappable_text.cpp:15
virtual std::string className() const noexceptoverride
Returns a string representing the class name.
Definition: wrappable_text.cpp:180
void handleQueuedEvent(std::shared_ptr< Events::Event > event) override
HandleQueuedEvent allows derived classes to define behaviour for when queuedEvents are received...
Definition: wrappable_text.cpp:172
Class for transform.
Definition: transform.h:13
virtual void setText(const std::string &text) override
Sets the text string.
Definition: wrappable_text.cpp:54
Definition: wrappable_text.h:25
virtual bool onUpdate(const double delta) override
Called every engine loop.
Definition: wrappable_text.cpp:149
Definition: wrappable_text.h:25
Definition: wrappable_text.h:25
Definition: wrappable_text.h:20
virtual std::string to_string() const noexceptoverride
Returns a string representation of the object.
Definition: wrappable_text.cpp:184
std::string text
Definition: text.h:21
void setSize(float width, float height)
Sets the size.
Definition: wrappable_text.cpp:19
VerticalAlignment
Vertical Alignment Enum.
Definition: wrappable_text.h:25
WrappableText()
Wrappable Text constructor.
Definition: wrappable_text.cpp:7
virtual void log(el::base::type::ostream_t &os) const
Definition: wrappable_text.cpp:190
Definition: wrappable_text.h:20
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: wrappable_text.cpp:176
virtual void onStart() override
Called when the engine starts and when a new scene is loaded.
Definition: wrappable_text.cpp:146
Definition: wrappable_text.h:20
Class for wrappable text.
Definition: wrappable_text.h:14
void setHorizontalAlignment(const HorizontalAlignment &alignment)
Sets the horizontal alignment.
Definition: wrappable_text.cpp:11