Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
text_field.h
Go to the documentation of this file.
1 #ifndef TEXT_FIELD_H
2 #define TEXT_FIELD_H
3 
5 //= SCRIPTABLE
6 //= SCRIPTABLE BASES TextArea
7 
8 namespace Graphics {
9  namespace UI {
13  class TextField : public TextArea {
14  private:
15  bool cursor_over;
16  std::shared_ptr<WrappableText> default_text;
17  std::shared_ptr<WrappableText> typed_text;
18  std::string caret;
19  float blink_speed;
20  bool in_focus;
21  std::string current_typed;
22  glm::vec4 typed_color;
23 
24  void reset();
25  protected:
26  const glm::vec4 mouse_over_dim = glm::vec4(0.1, 0.1, 0.1, 0.0);
27  public:
28  //= BEGIN SCRIPTABLE
29 
38  TextField(std::shared_ptr<WrappableText> default_text, std::shared_ptr<WrappableText> typed_text, VertexData vertex_data, std::shared_ptr<Skin> skin, const unsigned int layer);
56  static std::shared_ptr<TextField> create(std::shared_ptr<Skin> skin, std::shared_ptr<WrappableText> default_text, std::shared_ptr<WrappableText> typed_text, glm::vec4 background_color, float padding, float screen_width, float screen_height, float x_pos, float y_pos, float width, float height, const unsigned int layer);
57 
58  virtual void onLeftClick() override;
59  virtual void onRightClick() override;
60  virtual void onLeftClickRelease() override;
61  virtual void onRightClickRelease() override;
62  virtual void onCursorEnter() override;
63  virtual void onCursorLeave() override;
64  virtual void onKeyDown(const int key) override;
65  virtual void onKeyUp(const int key) override;
66  virtual void onKeyRepeat(const int key) override;
67  virtual void onScroll(const glm::dvec2 position_change) override;
68  virtual void onCharacterTyped(const unsigned char character);
74  virtual std::string to_string() const noexcept override;
75  virtual std::string className() const noexcept override;
76  //= END SCRIPTABLE
77 
78  virtual void onDestroy() override;
79  virtual void onStart() override;
80  virtual bool onUpdate(const double delta) override;
81 
82  void handleQueuedEvent(std::shared_ptr<Events::Event> event) override;
83  void onNotifyNow(std::shared_ptr<Events::Event> event) override;
84 
85  virtual void log(el::base::type::ostream_t& os) const;
86  };
87  }
88 }
89 
90 #endif
const glm::vec4 mouse_over_dim
Definition: text_field.h:26
virtual void onKeyRepeat(const int key) override
Called when a key is repeated while element is in focus.
Definition: text_field.cpp:134
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_field.cpp:72
virtual void onCharacterTyped(const unsigned char character)
Definition: text_field.cpp:145
virtual void onKeyUp(const int key) override
Called when a key is released while element is in focus.
Definition: text_field.cpp:131
virtual void onCursorEnter() override
Called when the mosue cursor goes over the element.
Definition: text_field.cpp:98
virtual void onLeftClick() override
Called when element is left clicked.
Definition: text_field.cpp:76
virtual void onDestroy() override
Called when the engine is shutting down.
Definition: text_field.cpp:47
Class for vertex data.
Definition: vertex_data.h:17
virtual void onRightClickRelease() override
Called when element has right click released over it.
Definition: text_field.cpp:94
virtual void log(el::base::type::ostream_t &os) const
Definition: text_field.cpp:163
virtual void onScroll(const glm::dvec2 position_change) override
Called when the mouse wheel is scrolled while element is in focus.
Definition: text_field.cpp:142
virtual void onKeyDown(const int key) override
Called when a key is pressed while element is in focus.
Definition: text_field.cpp:106
virtual void onRightClick() override
Called when element is right clicked.
Definition: text_field.cpp:87
virtual void onCursorLeave() override
Called when the mouse cursor goes off the element.
Definition: text_field.cpp:102
TextField(std::shared_ptr< WrappableText > default_text, std::shared_ptr< WrappableText > typed_text, VertexData vertex_data, std::shared_ptr< Skin > skin, const unsigned int layer)
TextField constructor.
Definition: text_field.cpp:14
static std::shared_ptr< TextField > create(std::shared_ptr< Skin > skin, std::shared_ptr< WrappableText > default_text, std::shared_ptr< WrappableText > typed_text, glm::vec4 background_color, float padding, float screen_width, float screen_height, float x_pos, float y_pos, float width, float height, const unsigned int layer)
TextField factory function.
Definition: text_field.cpp:19
Class for text area.
Definition: text_area.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_field.cpp:64
Class for text field.
Definition: text_field.h:13
virtual void onStart() override
Called when the engine starts and when a new scene is loaded.
Definition: text_field.cpp:51
virtual void onLeftClickRelease() override
Called when element has left click released over it.
Definition: text_field.cpp:90
virtual std::string className() const noexceptoverride
Returns a string representing the class name.
Definition: text_field.cpp:153
virtual bool onUpdate(const double delta) override
Called every engine loop.
Definition: text_field.cpp:60
virtual std::string to_string() const noexceptoverride
Returns a string representation of the object.
Definition: text_field.cpp:157