supertux
text_object.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_OBJECT_TEXT_OBJECT_HPP
18 #define HEADER_SUPERTUX_OBJECT_TEXT_OBJECT_HPP
19 
20 #include "supertux/game_object.hpp"
21 
22 #include "math/anchor_point.hpp"
23 #include "video/color.hpp"
24 #include "video/drawing_context.hpp"
25 #include "video/font_ptr.hpp"
26 
27 class DrawingContext;
28 class ReaderMapping;
29 
38 class TextObject final : public GameObject
39 {
40  static Color default_color;
41 
42 public:
43  static void register_class(ssq::VM& vm);
44 
45 public:
46  TextObject(const std::string& name = "");
47  ~TextObject() override;
48 
49  static std::string class_name() { return "textobject"; }
50  virtual std::string get_class_name() const override { return class_name(); }
51  virtual std::string get_exposed_class_name() const override { return "TextObject"; }
52  static std::string display_name() { return _("Text"); }
53  virtual std::string get_display_name() const override { return display_name(); }
54  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(TextObject)); }
55 
56  virtual const std::string get_icon_path() const override { return "images/engine/editor/textarray.png"; }
57 
58  virtual void draw(DrawingContext& context) override;
59  virtual void update(float dt_sec) override;
60  virtual bool is_saveable() const override { return false; }
61 
67  void set_text(const std::string& text);
73  void set_font(const std::string& fontname);
79  void fade_in(float fadetime);
85  void fade_out(float fadetime);
91  void grow_in(float fadetime);
97  void grow_out(float fadetime);
104  void set_visible(bool visible);
111  void set_centered(bool centered);
118  void set_pos(float x, float y);
123  float get_x() const;
128  float get_y() const;
129 #ifdef DOXYGEN_SCRIPTING
130 
135  float get_pos_x() const;
141  float get_pos_y() const;
142 #endif
143 
148  void set_anchor_point(int anchor);
153  int get_anchor_point() const;
160  void set_anchor_offset(float x, float y);
166  float get_wrap_width() const;
173  void set_wrap_width(float width);
182  void set_front_fill_color(float red, float green, float blue, float alpha);
191  void set_back_fill_color(float red, float green, float blue, float alpha);
200  void set_text_color(float red, float green, float blue, float alpha);
207  void set_roundness(float roundness);
208 
209  void set_anchor_point(AnchorPoint anchor) { m_anchor = anchor; }
210  void set_anchor_offset(const Vector& offset) { m_anchor_offset = offset; }
211 
212  void set_pos(const Vector& pos) { m_pos = pos; }
213  const Vector& get_pos() const { return m_pos; }
214 
215 private:
216  void wrap_text();
217 
218 private:
219  FontPtr m_font;
220  std::string m_text;
221  std::string m_wrapped_text;
222  float m_fade_progress;
223  float m_fadetime;
228  bool m_visible;
233  bool m_centered;
234  AnchorPoint m_anchor;
235  Vector m_anchor_offset;
236  Vector m_pos;
241  float m_wrap_width;
242  Color m_front_fill_color;
243  Color m_back_fill_color;
244  Color m_text_color;
249  float m_roundness;
250  bool m_growing_in;
251  bool m_growing_out;
252  bool m_fading_in;
253  bool m_fading_out;
254  bool m_grower;
255  bool m_fader;
256 
257 private:
258  TextObject(const TextObject&) = delete;
259  TextObject& operator=(const TextObject&) = delete;
260 };
261 
262 #endif
263 
264 /* EOF */
void set_visible(bool visible)
Definition: text_object.cpp:138
void set_front_fill_color(float red, float green, float blue, float alpha)
Sets the front fill color of the text.
Definition: text_object.cpp:205
void set_roundness(float roundness)
Definition: text_object.cpp:223
virtual bool is_saveable() const override
Indicates if the object will be saved.
Definition: text_object.hpp:60
void set_font(const std::string &fontname)
Sets the font of the text to be displayed.
Definition: text_object.cpp:62
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: text_object.hpp:54
void fade_out(float fadetime)
Fades out the specified text for the next ""fadetime"" seconds.
Definition: text_object.cpp:130
void set_wrap_width(float width)
Definition: text_object.cpp:199
void set_pos(float x, float y)
Sets the offset of the text, relative to the anchor point.
Definition: text_object.cpp:157
void grow_in(float fadetime)
Grows in the specified text for the next ""fadetime"" seconds.
Definition: text_object.cpp:102
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: text_object.cpp:269
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: text_object.hpp:53
A text object intended for scripts that want to tell a story.
Definition: text_object.hpp:38
void set_centered(bool centered)
Definition: text_object.cpp:151
void set_text_color(float red, float green, float blue, float alpha)
Sets the text color.
Definition: text_object.cpp:217
void set_anchor_point(int anchor)
Sets the anchor point of the text.
Definition: text_object.cpp:175
float get_x() const
Returns the X offset of the text, relative to the anchor point.
Definition: text_object.cpp:163
void grow_out(float fadetime)
Grows out the specified text for the next ""fadetime"" seconds.
Definition: text_object.cpp:112
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
int get_anchor_point() const
Returns the current anchor point of the text (one of the ""ANCHOR_*"" constants; see ${SRG_REF_Anchor...
Definition: text_object.cpp:181
void set_text(const std::string &text)
Sets the text string to be displayed.
Definition: text_object.cpp:95
float get_wrap_width() const
Definition: text_object.cpp:193
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
Definition: color.hpp:26
void fade_in(float fadetime)
Fades in the specified text for the next ""fadetime"" seconds.
Definition: text_object.cpp:120
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
float get_y() const
Returns the Y offset of the text, relative to the anchor point.
Definition: text_object.cpp:169
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: text_object.cpp:229
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
void set_anchor_offset(float x, float y)
Sets the anchor offset of the text.
Definition: text_object.cpp:187
void set_back_fill_color(float red, float green, float blue, float alpha)
Sets the back fill color of the text.
Definition: text_object.cpp:211