gradient.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_GRADIENT_HPP
  17. #define HEADER_SUPERTUX_OBJECT_GRADIENT_HPP
  18. #include "editor/layer_object.hpp"
  19. #include "video/drawing_context.hpp"
  20. class ReaderMapping;
  21. /**
  22. * @scripting
  23. * @summary A ""Gradient"" that was given a name can be controlled by scripts.
  24. * @instances A ""Gradient"" is instantiated by placing a definition inside a level.
  25. It can then be accessed by its name from a script or via ""sector.name"" from the console.
  26. */
  27. class Gradient final : public LayerObject
  28. {
  29. public:
  30. static void register_class(ssq::VM& vm);
  31. public:
  32. Gradient();
  33. Gradient(const ReaderMapping& reader);
  34. ~Gradient() override;
  35. virtual void update(float dt_sec) override;
  36. virtual void draw(DrawingContext& context) override;
  37. virtual bool is_saveable() const override;
  38. static std::string class_name() { return "gradient"; }
  39. virtual std::string get_class_name() const override { return class_name(); }
  40. virtual std::string get_exposed_class_name() const override { return "Gradient"; }
  41. static std::string display_name() { return _("Gradient"); }
  42. virtual std::string get_display_name() const override { return display_name(); }
  43. virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(Gradient)); }
  44. virtual const std::string get_icon_path() const override {
  45. return "images/engine/editor/gradient.png";
  46. }
  47. virtual ObjectSettings get_settings() override;
  48. virtual void on_flip(float height) override;
  49. void set_gradient(const Color& top, const Color& bottom);
  50. void fade_gradient(const Color& top, const Color& bottom, float time);
  51. inline Color get_gradient_top() const { return m_gradient_top; }
  52. inline Color get_gradient_bottom() const { return m_gradient_bottom; }
  53. inline GradientDirection get_direction() const { return m_gradient_direction; }
  54. std::string get_direction_string() const;
  55. inline void set_direction(const GradientDirection& direction) { m_gradient_direction = direction; }
  56. inline void set_layer(int layer) { m_layer = layer; }
  57. int get_layer() const override { return m_layer; }
  58. /**
  59. * @scripting
  60. * @description Sets the direction of the gradient.
  61. * @param string $direction Can be "horizontal", "vertical", "horizontal_sector" or "vertical_sector".
  62. */
  63. void set_direction(const std::string& direction);
  64. #ifdef DOXYGEN_SCRIPTING
  65. /**
  66. * @scripting
  67. * @description Returns the direction of the gradient.
  68. Possible values are "horizontal", "vertical", "horizontal_sector" or "vertical_sector".
  69. */
  70. std::string get_direction() const;
  71. #endif
  72. /**
  73. * @scripting
  74. * @description Set top gradient color.
  75. * @param float $red
  76. * @param float $green
  77. * @param float $blue
  78. * @param float $alpha
  79. */
  80. void set_color1(float red, float green, float blue, float alpha = 1.f);
  81. /**
  82. * @scripting
  83. * @description Set bottom gradient color.
  84. * @param float $red
  85. * @param float $green
  86. * @param float $blue
  87. * @param float $alpha
  88. */
  89. void set_color2(float red, float green, float blue, float alpha = 1.f);
  90. /**
  91. * @scripting
  92. * @description Set both gradient colors.
  93. * @param float $red1
  94. * @param float $green1
  95. * @param float $blue1
  96. * @param float $red2
  97. * @param float $green2
  98. * @param float $blue2
  99. * @param float $alpha1
  100. * @param float $alpha2
  101. */
  102. void set_colors(float red1, float green1, float blue1, float red2, float green2, float blue2, float alpha1 = 1.f, float alpha2 = 1.f);
  103. /**
  104. * @scripting
  105. * @description Fade the top gradient color to a specified new color in ""time"" seconds.
  106. * @param float $red
  107. * @param float $green
  108. * @param float $blue
  109. * @param float $time
  110. * @param float $alpha
  111. */
  112. void fade_color1(float red, float green, float blue, float time, float alpha = 1.f);
  113. /**
  114. * @scripting
  115. * @description Fade the bottom gradient color to a specified new color in ""time"" seconds.
  116. * @param float $red
  117. * @param float $green
  118. * @param float $blue
  119. * @param float $time
  120. * @param float $alpha
  121. */
  122. void fade_color2(float red, float green, float blue, float time, float alpha = 1.f);
  123. /**
  124. * @scripting
  125. * @description Fade both gradient colors to specified new colors in ""time"" seconds.
  126. * @param float $red1
  127. * @param float $green1
  128. * @param float $blue1
  129. * @param float $red2
  130. * @param float $green2
  131. * @param float $blue2
  132. * @param float $time
  133. * @param float $alpha1
  134. * @param float $alpha2
  135. */
  136. void fade_colors(float red1, float green1, float blue1, float red2, float green2, float blue2, float time, float alpha1 = 1.f, float alpha2 = 1.f);
  137. /**
  138. * @scripting
  139. * @description Swap top and bottom gradient colors.
  140. */
  141. void swap_colors();
  142. private:
  143. int m_layer;
  144. Color m_gradient_top;
  145. Color m_gradient_bottom;
  146. GradientDirection m_gradient_direction;
  147. Blend m_blend;
  148. DrawingTarget m_target;
  149. Color m_start_gradient_top;
  150. Color m_start_gradient_bottom;
  151. Color m_fade_gradient_top;
  152. Color m_fade_gradient_bottom;
  153. float m_fade_total_time;
  154. float m_fade_time;
  155. public:
  156. static const Color DEFAULT_GRADIENT_TOP;
  157. static const Color DEFAULT_GRADIENT_BOTTOM;
  158. private:
  159. Gradient(const Gradient&) = delete;
  160. Gradient& operator=(const Gradient&) = delete;
  161. };
  162. #endif
  163. /* EOF */