Candle affects lightmap
[supertux.git] / src / video / surface.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20 #ifndef __SURFACE_HPP__
21 #define __SURFACE_HPP__
22
23 #include <string>
24 #include "math/vector.hpp"
25
26 class Color;
27 class Blend;
28 class ImageTexture;
29
30 /// bitset for drawing effects
31 enum DrawingEffect {
32   /** Don't apply anything */
33   NO_EFFECT       = 0x0000,
34   /** Draw the Surface upside down */
35   VERTICAL_FLIP     = 0x0001,
36   /** Draw the Surface from left to down */
37   HORIZONTAL_FLIP   = 0x0002,
38 };
39
40 /**
41  * A rectangular image.
42  * The class basically holds a reference to a texture with additional UV
43  * coordinates that specify a rectangular area on this texture
44  */
45 class Surface
46 {
47 private:
48   friend class DrawingContext;
49   friend class Font;
50   ImageTexture* texture;
51
52   float uv_left;
53   float uv_top;
54   float uv_right;
55   float uv_bottom;
56
57   void draw(float x, float y, float alpha, float angle, const Color& color, const Blend& blend, DrawingEffect effect) const;
58   void draw(float x, float y, float alpha, DrawingEffect effect) const;
59   void draw_part(float src_x, float src_y, float dst_x, float dst_y,
60                  float width, float height,
61                  float alpha, DrawingEffect effect) const;
62
63   float width;
64   float height;
65 public:
66   Surface(const std::string& file);
67   Surface(const std::string& file, int x, int y, int w, int h);
68   Surface(const Surface& other);
69   ~Surface();
70
71   /** flip the surface horizontally */
72   void hflip();
73
74   const Surface& operator= (const Surface& other);
75
76   float get_width() const
77   {
78     return width;
79   }
80
81   float get_height() const
82   {
83     return height;
84   }
85
86   /**
87    * returns a vector containing width and height
88    */
89   Vector get_size() const
90   { return Vector(get_width(), get_height()); }
91
92 };
93
94 #endif