Initial integration, lots of broken stuff
[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 <config.h>
24
25 #include <string>
26 #include <SDL.h>
27 #include "math/vector.hpp"
28 #include "file_system.hpp"
29 #include <unison/video/Texture.hpp>
30
31 /// bitset for drawing effects
32 enum DrawingEffect {
33   /** Don't apply anything */
34   NO_EFFECT,
35   /** Draw the Surface upside down */
36   VERTICAL_FLIP,
37   /** Draw the Surface from left to down */
38   HORIZONTAL_FLIP,
39   NUM_EFFECTS
40 };
41
42 /**
43  * A rectangular image.
44  * The class basically holds a reference to a texture with additional UV
45  * coordinates that specify a rectangular area on this texture
46  */
47 class Surface
48 {
49 private:
50   Unison::Video::TextureSection texture;
51   bool flipx;
52
53 public:
54   Surface(const std::string& file) :
55     texture(FileSystem::normalize(file)),
56     flipx(false)
57   {
58   }
59
60   Surface(const std::string& file, int x, int y, int w, int h) :
61     texture(FileSystem::normalize(file), Unison::Video::Rect(x, y, w, h)),
62     flipx(false)
63   {
64   }
65
66   Surface(const Surface& other) :
67     texture(other.texture),
68     flipx(false)
69   {
70   }
71
72   ~Surface()
73   {
74   }
75
76   /** flip the surface horizontally */
77   void hflip()
78   {
79     flipx = !flipx;
80   }
81
82   bool get_flipx() const
83   {
84     return flipx;
85   }
86
87   const Surface& operator= (const Surface& other)
88   {
89     texture = other.texture;
90     return *this;
91   }
92
93   Unison::Video::TextureSection get_texture() const
94   {
95     return texture;
96   }
97
98   int get_x() const
99   {
100     return texture.clip_rect.pos.x;
101   }
102
103   int get_y() const
104   {
105     return texture.clip_rect.pos.y;
106   }
107
108   int get_width() const
109   {
110     return texture.clip_rect.size.x ? texture.clip_rect.size.x : texture.image.get_size().x;
111   }
112
113   int get_height() const
114   {
115     return texture.clip_rect.size.y ? texture.clip_rect.size.y : texture.image.get_size().y;
116   }
117
118   Vector get_position() const
119   { return Vector(get_x(), get_y()); }
120
121   /**
122    * returns a vector containing width and height
123    */
124   Vector get_size() const
125   { return Vector(get_width(), get_height()); }
126 };
127
128 #endif