supertux
background.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_BACKGROUND_HPP
18 #define HEADER_SUPERTUX_OBJECT_BACKGROUND_HPP
19 
20 #include "math/vector.hpp"
21 #include "sprite/sprite_ptr.hpp"
22 #include "supertux/game_object.hpp"
23 #include "supertux/timer.hpp"
24 #include "video/blend.hpp"
25 #include "video/drawing_context.hpp"
26 #include "video/flip.hpp"
27 
28 class ReaderMapping;
29 
35 class Background final : public GameObject
36 {
37 public:
38  static void register_class(ssq::VM& vm);
39 
40 public:
41  Background();
42  Background(const ReaderMapping& reader);
43  ~Background() override;
44 
45  virtual void update(float dt_sec) override;
46  virtual void draw(DrawingContext& context) override;
47 
48  static std::string class_name() { return "background"; }
49  virtual std::string get_class_name() const override { return class_name(); }
50  virtual std::string get_exposed_class_name() const override { return "Background"; }
51  static std::string display_name() { return _("Background"); }
52  virtual std::string get_display_name() const override { return display_name(); }
53  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(Background)); }
54 
55  virtual const std::string get_icon_path() const override {
56  return "images/engine/editor/background.png";
57  }
58 
59  virtual ObjectSettings get_settings() override;
60  virtual void after_editor_set() override;
61 
62  virtual void on_flip(float height) override;
63 
64  void draw_image(DrawingContext& context, const Vector& pos);
65 
66  const std::string& get_image() const { return m_imagefile; }
67  float get_speed() const { return m_parallax_speed.x; }
68  int get_layer() const { return m_layer; }
69 
70  Color get_color() const { return m_color; }
71  void fade_color(Color color, float time);
72 
78  void set_image(const std::string& image);
86  void set_images(const std::string& top_image, const std::string& middle_image,
87  const std::string& bottom_image);
93  void set_speed(float speed);
94 
99  float get_color_red() const;
104  float get_color_green() const;
109  float get_color_blue() const;
114  float get_color_alpha() const;
123  void set_color(float red, float green, float blue, float alpha);
133  void fade_color(float red, float green, float blue, float alpha, float time);
138  void set_top_image_action(const std::string& action);
143  void set_image_action(const std::string& action);
148  void set_bottom_image_action(const std::string& action);
153  void set_all_image_actions(const std::string& action);
154 
155 private:
156  enum Alignment {
157  NO_ALIGNMENT,
158  LEFT_ALIGNMENT,
159  RIGHT_ALIGNMENT,
160  TOP_ALIGNMENT,
161  BOTTOM_ALIGNMENT
162  };
163 
164 private:
168  Alignment m_alignment;
169 
173  bool m_fill;
174 
175  int m_layer;
176  std::string m_imagefile_top;
177  std::string m_imagefile;
178  std::string m_imagefile_bottom;
179  Vector m_pos;
180  Vector m_parallax_speed;
181  Vector m_scroll_speed;
182  Vector m_scroll_offset;
183  SpritePtr m_image_top;
184  SpritePtr m_image;
185  SpritePtr m_image_bottom;
187  Blend m_blend;
188  Color m_color;
189  DrawingTarget m_target;
190 
191  Timer m_timer_color;
192  Color m_src_color, m_dst_color;
193 
194  Flip m_flip;
195 
196 private:
197  Background(const Background&) = delete;
198  Background& operator=(const Background&) = delete;
199 };
200 
201 #endif
202 
203 /* EOF */
void set_image_action(const std::string &action)
Sets the sprite action for the main (middle) image.
Definition: background.cpp:558
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: background.cpp:520
void set_bottom_image_action(const std::string &action)
Sets the sprite action for the bottom image.
Definition: background.cpp:564
float get_color_red() const
Returns the red color value.
Definition: background.cpp:392
void set_image(const std::string &image)
Sets the background&#39;s image.
Definition: background.cpp:363
void set_images(const std::string &top_image, const std::string &middle_image, const std::string &bottom_image)
Sets the top, middle and bottom background images.
Definition: background.cpp:370
void set_all_image_actions(const std::string &action)
Sets the sprite action for all images (top, middle and bottom).
Definition: background.cpp:571
float get_color_blue() const
Returns the blue color value.
Definition: background.cpp:404
A ""Background"" that was given a name can be manipulated by scripts.
Definition: background.hpp:35
Definition: object_settings.hpp:39
float get_color_green() const
Returns the green color value.
Definition: background.cpp:398
void set_speed(float speed)
Sets the background speed.
Definition: background.cpp:385
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: background.cpp:322
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: background.cpp:579
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: background.hpp:53
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
float get_color_alpha() const
Returns the alpha color value.
Definition: background.cpp:410
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
void set_top_image_action(const std::string &action)
Sets the sprite action for the top image.
Definition: background.cpp:551
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 set_color(float red, float green, float blue, float alpha)
Sets the background color.
Definition: background.cpp:340
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
Definition: reader_mapping.hpp:32
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: background.hpp:52
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42