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 "math/anchor_point.hpp"
21 #include "scripting/text.hpp"
22 #include "squirrel/exposed_object.hpp"
23 #include "supertux/game_object.hpp"
24 #include "video/color.hpp"
25 #include "video/font_ptr.hpp"
26 
28 class TextObject final : public GameObject,
29  public ExposedObject<TextObject, scripting::Text>
30 {
31  static Color default_color;
32 
33 public:
34  TextObject(const std::string& name = std::string());
35  virtual ~TextObject();
36 
37  virtual void draw(DrawingContext& context) override;
38  virtual void update(float dt_sec) override;
39  virtual bool is_singleton() const override { return true; }
40  virtual bool is_saveable() const override { return false; }
41 
42  void set_text(const std::string& text);
43  void set_font(const std::string& name);
44  void fade_in(float fadetime);
45  void fade_out(float fadetime);
46  void set_visible(bool visible);
47  void set_centered(bool centered);
48  bool is_visible();
49 
50  void set_anchor_point(AnchorPoint anchor) { m_anchor = anchor; }
51  AnchorPoint get_anchor_point() const { return m_anchor; }
52 
53  void set_pos(const Vector& pos) { m_pos = pos; }
54  const Vector& get_pos() const { return m_pos; }
55 
56 private:
57  void wrap_text();
58 
59 private:
60  FontPtr m_font;
61  std::string m_text;
62  std::string m_wrapped_text;
63  float m_fading;
64  float m_fadetime;
65  bool m_visible;
66  bool m_centered;
67  AnchorPoint m_anchor;
68  Vector m_pos;
69 
70 private:
71  TextObject(const TextObject&) = delete;
72  TextObject& operator=(const TextObject&) = delete;
73 };
74 
75 #endif
76 
77 /* EOF */
virtual bool is_saveable() const override
Indicates if the object will be saved.
Definition: text_object.hpp:40
Simple two dimensional vector.
Definition: vector.hpp:24
This class binds a certain GameObject class to a scripting class.
Definition: exposed_object.hpp:45
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:155
A text object intended for scripts that want to tell a story.
Definition: text_object.hpp:28
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
Definition: color.hpp:25
virtual bool is_singleton() const override
If true only a single object of this type is allowed in a given GameObjectManager.
Definition: text_object.hpp:39
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: text_object.cpp:125
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42