supertux
textscroller.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // 2018 Ingo Ruhnke <grumbel@gmail.com>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_OBJECT_TEXTSCROLLER_HPP
19 #define HEADER_SUPERTUX_OBJECT_TEXTSCROLLER_HPP
20 
21 #include <memory>
22 #include <vector>
23 
24 #include "supertux/info_box_line.hpp"
25 #include "supertux/game_object.hpp"
26 #include "control/controller.hpp"
27 
28 class DrawingContext;
29 class InfoBoxLine;
30 class ReaderCollection;
31 class ReaderMapping;
32 class ReaderObject;
33 
34 class TextScroller : public GameObject
35 {
36 public:
37  TextScroller(const ReaderMapping& mapping);
38  TextScroller(const ReaderObject& root);
39 
40  virtual void draw(DrawingContext& context) override;
41  virtual void update(float dt_sec) override;
42  virtual ObjectSettings get_settings() override;
43  static std::string class_name() { return "textscroller"; }
44  virtual std::string get_class_name() const override { return class_name(); }
45  static std::string display_name() { return _("Text Scroller"); }
46  virtual std::string get_display_name() const override { return display_name(); }
47  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(TextScroller)); }
48  virtual const std::string get_icon_path() const override { return "images/engine/editor/textscroller.png"; }
49 
50  void set_default_speed(float default_speed);
51  void scroll(float offset);
52  bool is_finished() const { return m_finished; }
53 
54 protected:
55  const Controller* controller;
56 
57 private:
58  void parse_file(const std::string& filename);
59  void parse_root(const ReaderObject& root);
60  void parse_content(const ReaderCollection& collection);
61 
62 private:
63  std::string m_filename;
64  std::string m_finish_script;
65  std::vector<std::unique_ptr<InfoBoxLine> > m_lines;
66  float m_scroll;
67  float m_default_speed;
68  float m_x_offset;
69  bool m_controllable;
70  bool m_finished;
71  bool m_fading;
72 
73  enum XAnchor {
74  SCROLLER_ANCHOR_LEFT,
75  SCROLLER_ANCHOR_CENTER,
76  SCROLLER_ANCHOR_RIGHT
77  };
78  enum TextAlign {
79  SCROLLER_ALIGN_LEFT,
80  SCROLLER_ALIGN_CENTER,
81  SCROLLER_ALIGN_RIGHT
82  };
83 
84  XAnchor m_x_anchor;
85  TextAlign m_text_align;
86 
87 private:
88  TextScroller(const TextScroller&) = delete;
89  TextScroller& operator=(const TextScroller&) = delete;
90 };
91 
92 #endif
93 
94 /* EOF */
Definition: controller.hpp:57
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: textscroller.cpp:281
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: textscroller.hpp:46
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: textscroller.hpp:47
Definition: reader_object.hpp:30
Definition: textscroller.hpp:34
Definition: object_settings.hpp:39
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: textscroller.cpp:244
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
Helper class for InfoBox: Represents a line of text.
Definition: info_box_line.hpp:34
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
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
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
Definition: reader_collection.hpp:30