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 "scripting/background.hpp"
22 #include "squirrel/exposed_object.hpp"
23 #include "supertux/game_object.hpp"
24 #include "video/blend.hpp"
25 #include "video/drawing_context.hpp"
26 #include "video/surface_ptr.hpp"
27 
28 class ReaderMapping;
29 
30 class Background final : public GameObject,
31  public ExposedObject<Background, scripting::Background>
32 {
33 public:
34  Background();
35  Background(const ReaderMapping& reader);
36  virtual ~Background();
37 
38  virtual void update(float dt_sec) override;
39  virtual void draw(DrawingContext& context) override;
40 
41  virtual std::string get_class() const override { return "background"; }
42  virtual std::string get_display_name() const override { return _("Background"); }
43 
44  virtual const std::string get_icon_path() const override {
45  return "images/engine/editor/background.png";
46  }
47 
48  virtual ObjectSettings get_settings() override;
49  virtual void after_editor_set() override;
50 
51  void set_image(const std::string& name);
52  void set_images(const std::string& name_top, const std::string& name_middle, const std::string& name_bottom);
53  void set_speed(float bgd_speed);
54 
55  void draw_image(DrawingContext& context, const Vector& pos);
56 
57  std::string get_image() const { return m_imagefile; }
58  float get_speed() const { return m_parallax_speed.x; }
59  int get_layer() const { return m_layer; }
60 
61 private:
62  enum Alignment {
63  NO_ALIGNMENT,
64  LEFT_ALIGNMENT,
65  RIGHT_ALIGNMENT,
66  TOP_ALIGNMENT,
67  BOTTOM_ALIGNMENT
68  };
69 
70 private:
74  Alignment m_alignment;
75 
79  bool m_fill;
80 
81  int m_layer;
82  std::string m_imagefile_top;
83  std::string m_imagefile;
84  std::string m_imagefile_bottom;
85  Vector m_pos;
86  Vector m_parallax_speed;
87  Vector m_scroll_speed;
88  Vector m_scroll_offset;
89  SurfacePtr m_image_top;
90  SurfacePtr m_image;
91  SurfacePtr m_image_bottom;
93  bool m_has_pos_x;
94  bool m_has_pos_y;
95 
96  Blend m_blend;
97  DrawingTarget m_target;
98 
99 private:
100  Background(const Background&) = delete;
101  Background& operator=(const Background&) = delete;
102 };
103 
104 #endif
105 
106 /* EOF */
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: background.cpp:329
Simple two dimensional vector.
Definition: vector.hpp:24
This class binds a certain GameObject class to a scripting class.
Definition: exposed_object.hpp:45
Definition: background.hpp:30
Definition: object_settings.hpp:35
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:198
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
Definition: reader_mapping.hpp:31
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42