textscroller.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifndef HEADER_SUPERTUX_OBJECT_TEXTSCROLLER_HPP
  18. #define HEADER_SUPERTUX_OBJECT_TEXTSCROLLER_HPP
  19. #include <memory>
  20. #include <vector>
  21. #include "supertux/info_box_line.hpp"
  22. #include "supertux/game_object.hpp"
  23. #include "control/controller.hpp"
  24. class DrawingContext;
  25. class InfoBoxLine;
  26. class ReaderCollection;
  27. class ReaderMapping;
  28. class ReaderObject;
  29. class TextScroller : public GameObject
  30. {
  31. public:
  32. TextScroller(const ReaderMapping& mapping);
  33. TextScroller(const ReaderObject& root);
  34. virtual void draw(DrawingContext& context) override;
  35. virtual void update(float dt_sec) override;
  36. virtual ObjectSettings get_settings() override;
  37. static std::string class_name() { return "textscroller"; }
  38. virtual std::string get_class_name() const override { return class_name(); }
  39. static std::string display_name() { return _("Text Scroller"); }
  40. virtual std::string get_display_name() const override { return display_name(); }
  41. virtual const std::string get_icon_path() const override { return "images/engine/editor/textscroller.png"; }
  42. void set_default_speed(float default_speed);
  43. void scroll(float offset);
  44. bool is_finished() const { return m_finished; }
  45. protected:
  46. const Controller* controller;
  47. private:
  48. void parse_file(const std::string& filename);
  49. void parse_root(const ReaderObject& root);
  50. void parse_content(const ReaderCollection& collection);
  51. private:
  52. std::string m_filename;
  53. std::string m_finish_script;
  54. std::vector<std::unique_ptr<InfoBoxLine> > m_lines;
  55. float m_scroll;
  56. float m_default_speed;
  57. float m_x_offset;
  58. bool m_controllable;
  59. bool m_finished;
  60. bool m_fading;
  61. enum XAnchor {
  62. SCROLLER_ANCHOR_LEFT,
  63. SCROLLER_ANCHOR_CENTER,
  64. SCROLLER_ANCHOR_RIGHT
  65. };
  66. enum TextAlign {
  67. SCROLLER_ALIGN_LEFT,
  68. SCROLLER_ALIGN_CENTER,
  69. SCROLLER_ALIGN_RIGHT
  70. };
  71. XAnchor m_x_anchor;
  72. TextAlign m_text_align;
  73. private:
  74. TextScroller(const TextScroller&) = delete;
  75. TextScroller& operator=(const TextScroller&) = delete;
  76. };
  77. #endif
  78. /* EOF */