text_object.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #ifndef HEADER_SUPERTUX_OBJECT_TEXT_OBJECT_HPP
  17. #define HEADER_SUPERTUX_OBJECT_TEXT_OBJECT_HPP
  18. #include "squirrel/exposed_object.hpp"
  19. #include "supertux/game_object.hpp"
  20. #include "math/anchor_point.hpp"
  21. #include "scripting/text_object.hpp"
  22. #include "video/color.hpp"
  23. #include "video/drawing_context.hpp"
  24. #include "video/font_ptr.hpp"
  25. class DrawingContext;
  26. class ReaderMapping;
  27. /** A text object intended for scripts that want to tell a story */
  28. class TextObject final : public GameObject,
  29. public ExposedObject<TextObject, scripting::TextObject>
  30. {
  31. static Color default_color;
  32. public:
  33. TextObject(const std::string& name = "");
  34. ~TextObject() override;
  35. static std::string class_name() { return "textobject"; }
  36. virtual std::string get_class_name() const override { return class_name(); }
  37. static std::string display_name() { return _("Text"); }
  38. virtual std::string get_display_name() const override { return display_name(); }
  39. virtual const std::string get_icon_path() const override { return "images/engine/editor/textarray.png"; }
  40. virtual void draw(DrawingContext& context) override;
  41. virtual void update(float dt_sec) override;
  42. virtual bool is_saveable() const override { return false; }
  43. void set_text(const std::string& text);
  44. void set_font(const std::string& name);
  45. void grow_in(float fadetime);
  46. void grow_out(float fadetime);
  47. void fade_in(float fadetime);
  48. void fade_out(float fadetime);
  49. void set_visible(bool visible);
  50. void set_centered(bool centered);
  51. void set_front_fill_color(Color frontfill);
  52. void set_back_fill_color(Color backfill);
  53. void set_text_color(Color textcolor);
  54. void set_roundness(float roundness);
  55. bool is_visible();
  56. void set_anchor_point(AnchorPoint anchor) { m_anchor = anchor; }
  57. AnchorPoint get_anchor_point() const { return m_anchor; }
  58. void set_anchor_offset(const Vector& offset) { m_anchor_offset = offset; }
  59. float get_wrap_width() const { return m_wrap_width; }
  60. void set_wrap_width(float width) { m_wrap_width = width; }
  61. void set_pos(const Vector& pos) { m_pos = pos; }
  62. const Vector& get_pos() const { return m_pos; }
  63. private:
  64. void wrap_text();
  65. private:
  66. FontPtr m_font;
  67. std::string m_text;
  68. std::string m_wrapped_text;
  69. float m_fade_progress;
  70. float m_fadetime;
  71. bool m_visible;
  72. bool m_centered;
  73. AnchorPoint m_anchor;
  74. Vector m_anchor_offset;
  75. Vector m_pos;
  76. float m_wrap_width;
  77. Color m_front_fill_color;
  78. Color m_back_fill_color;
  79. Color m_text_color;
  80. float m_roundness;
  81. bool m_growing_in;
  82. bool m_growing_out;
  83. bool m_fading_in;
  84. bool m_fading_out;
  85. bool m_grower;
  86. bool m_fader;
  87. private:
  88. TextObject(const TextObject&) = delete;
  89. TextObject& operator=(const TextObject&) = delete;
  90. };
  91. #endif
  92. /* EOF */