gradient.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "scripting/gradient.hpp"
  19. #include "squirrel/exposed_object.hpp"
  20. #include "supertux/game_object.hpp"
  21. #include "video/drawing_context.hpp"
  22. class ReaderMapping;
  23. class Gradient final :
  24. public GameObject,
  25. public ExposedObject<Gradient, scripting::Gradient>
  26. {
  27. public:
  28. Gradient();
  29. Gradient(const ReaderMapping& reader);
  30. ~Gradient() override;
  31. virtual void update(float dt_sec) override;
  32. virtual void draw(DrawingContext& context) override;
  33. virtual bool is_saveable() const override;
  34. static std::string class_name() { return "gradient"; }
  35. virtual std::string get_class_name() const override { return class_name(); }
  36. static std::string display_name() { return _("Gradient"); }
  37. virtual std::string get_display_name() const override { return display_name(); }
  38. virtual const std::string get_icon_path() const override {
  39. return "images/engine/editor/gradient.png";
  40. }
  41. virtual ObjectSettings get_settings() override;
  42. virtual void on_flip(float height) override;
  43. void set_gradient(const Color& top, const Color& bottom);
  44. void fade_gradient(const Color& top, const Color& bottom, float time);
  45. Color get_gradient_top() const { return m_gradient_top; }
  46. Color get_gradient_bottom() const { return m_gradient_bottom; }
  47. GradientDirection get_direction() const { return m_gradient_direction; }
  48. std::string get_direction_string() const;
  49. void set_direction(const GradientDirection& direction);
  50. void set_direction(const std::string& direction);
  51. void set_layer(int layer) { m_layer = layer; }
  52. int get_layer() const { return m_layer; }
  53. private:
  54. int m_layer;
  55. Color m_gradient_top;
  56. Color m_gradient_bottom;
  57. GradientDirection m_gradient_direction;
  58. Blend m_blend;
  59. DrawingTarget m_target;
  60. private:
  61. Gradient(const Gradient&) = delete;
  62. Gradient& operator=(const Gradient&) = delete;
  63. Color m_start_gradient_top;
  64. Color m_start_gradient_bottom;
  65. Color m_fade_gradient_top;
  66. Color m_fade_gradient_bottom;
  67. float m_fade_total_time;
  68. float m_fade_time = 0;
  69. };
  70. #endif
  71. /* EOF */