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 |
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 | |
27 | /** A text object intended for scripts that want to tell a story */ |
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 */ |
78 | |