Fix for coverity #29401
[supertux.git] / src / object / 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 "supertux/game_object.hpp"
21 #include "util/reader_fwd.hpp"
22 #include "video/drawing_context.hpp"
23
24 class DisplayManager;
25
26 class Background : public GameObject
27 {
28 public:
29   Background();
30   Background(const Reader& reader);
31   virtual ~Background();
32
33   void set_image(const std::string& name, float bkgd_speed);
34
35   std::string get_image() const
36   { return imagefile; }
37   float get_speed() const
38   { return speed; }
39
40   virtual void update(float elapsed_time);
41
42   virtual void draw(DrawingContext& context);
43   void draw_image(DrawingContext& context, const Vector& pos);
44
45 private:
46   enum Alignment {
47     NO_ALIGNMENT,
48     LEFT_ALIGNMENT,
49     RIGHT_ALIGNMENT,
50     TOP_ALIGNMENT,
51     BOTTOM_ALIGNMENT
52   };
53
54   /** Backgrounds with NO_ALIGNMENT are repeated over the whole
55       screen, backgrounds with left, right, top, bottom alignment are
56       only repeated in one direction and attached to the level edge */
57   Alignment alignment;
58
59   int layer;
60   std::string imagefile_top;
61   std::string imagefile;
62   std::string imagefile_bottom;
63   Vector pos; /**< coordinates of upper-left corner of image */
64   float speed; /**< scroll-speed in horizontal direction */
65   float speed_y; /**< scroll-speed in vertical direction */
66   Vector scroll_speed;
67   Vector scroll_offset;
68   SurfacePtr image_top; /**< image to draw above pos */
69   SurfacePtr image; /**< image to draw, anchored at pos */
70   SurfacePtr image_bottom; /**< image to draw below pos+screenheight */
71 };
72
73 #endif /*SUPERTUX_BACKGROUND_H*/
74
75 /* EOF */