supertux
gradient.hpp
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 
17 #ifndef HEADER_SUPERTUX_OBJECT_GRADIENT_HPP
18 #define HEADER_SUPERTUX_OBJECT_GRADIENT_HPP
19 
20 #include "supertux/game_object.hpp"
21 #include "video/drawing_context.hpp"
22 
23 class ReaderMapping;
24 
31 class Gradient final : public GameObject
32 {
33 public:
34  static void register_class(ssq::VM& vm);
35 
36 public:
37  Gradient();
38  Gradient(const ReaderMapping& reader);
39  ~Gradient() override;
40 
41  virtual void update(float dt_sec) override;
42  virtual void draw(DrawingContext& context) override;
43 
44  virtual bool is_saveable() const override;
45 
46  static std::string class_name() { return "gradient"; }
47  virtual std::string get_class_name() const override { return class_name(); }
48  virtual std::string get_exposed_class_name() const override { return "Gradient"; }
49  static std::string display_name() { return _("Gradient"); }
50  virtual std::string get_display_name() const override { return display_name(); }
51  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(Gradient)); }
52 
53  virtual const std::string get_icon_path() const override {
54  return "images/engine/editor/gradient.png";
55  }
56 
57  virtual ObjectSettings get_settings() override;
58 
59  virtual void on_flip(float height) override;
60 
61  void set_gradient(const Color& top, const Color& bottom);
62  void fade_gradient(const Color& top, const Color& bottom, float time);
63  Color get_gradient_top() const { return m_gradient_top; }
64  Color get_gradient_bottom() const { return m_gradient_bottom; }
65 
66  GradientDirection get_direction() const { return m_gradient_direction; }
67  std::string get_direction_string() const;
68  void set_direction(const GradientDirection& direction);
69 
70  void set_layer(int layer) { m_layer = layer; }
71  int get_layer() const { return m_layer; }
72 
78  void set_direction(const std::string& direction);
79 #ifdef DOXYGEN_SCRIPTING
80 
85  std::string get_direction() const;
86 #endif
87 
94  void set_color1(float red, float green, float blue);
102  void set_color2(float red, float green, float blue);
113  void set_colors(float red1, float green1, float blue1, float red2, float green2, float blue2);
122  void fade_color1(float red, float green, float blue, float time);
131  void fade_color2(float red, float green, float blue, float time);
143  void fade_colors(float red1, float green1, float blue1, float red2, float green2, float blue2, float time);
148  void swap_colors();
149 
150 private:
151  int m_layer;
152  Color m_gradient_top;
153  Color m_gradient_bottom;
154  GradientDirection m_gradient_direction;
155  Blend m_blend;
156  DrawingTarget m_target;
157 
158  Color m_start_gradient_top;
159  Color m_start_gradient_bottom;
160  Color m_fade_gradient_top;
161  Color m_fade_gradient_bottom;
162  float m_fade_total_time;
163  float m_fade_time;
164 
165 private:
166  Gradient(const Gradient&) = delete;
167  Gradient& operator=(const Gradient&) = delete;
168 };
169 
170 #endif
171 
172 /* EOF */
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: gradient.cpp:322
void fade_colors(float red1, float green1, float blue1, float red2, float green2, float blue2, float time)
Fade both gradient colors to specified new colors in ""time"" seconds.
Definition: gradient.cpp:276
void set_color2(float red, float green, float blue)
Set bottom gradient color.
Definition: gradient.cpp:252
A ""Gradient"" that was given a name can be controlled by scripts.
Definition: gradient.hpp:31
Definition: object_settings.hpp:39
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: gradient.hpp:51
void fade_color1(float red, float green, float blue, float time)
Fade the top gradient color to a specified new color in ""time"" seconds.
Definition: gradient.cpp:264
virtual bool is_saveable() const override
Indicates if the object will be saved.
Definition: gradient.cpp:315
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
void swap_colors()
Swap top and bottom gradient colors.
Definition: gradient.cpp:282
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: gradient.cpp:288
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
Definition: color.hpp:26
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
void fade_color2(float red, float green, float blue, float time)
Fade the bottom gradient color to a specified new color in ""time"" seconds.
Definition: gradient.cpp:270
Definition: reader_mapping.hpp:32
void set_color1(float red, float green, float blue)
Set top gradient color.
Definition: gradient.cpp:246
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
void set_colors(float red1, float green1, float blue1, float red2, float green2, float blue2)
Set both gradient colors.
Definition: gradient.cpp:258
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: gradient.cpp:133
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: gradient.hpp:50