- Reworked Surface class and drawing stuff:
[supertux.git] / src / video / surface.hpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 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
25 class ImageTexture;
26
27 /// bitset for drawing effects
28 enum DrawingEffect {
29   /** Don't apply anything */
30   NO_EFFECT       = 0x0000,
31   /** Draw the Surface upside down */
32   VERTICAL_FLIP     = 0x0001,
33   /** Draw the Surface from left to down */
34   HORIZONTAL_FLIP   = 0x0002,
35 };
36
37 /**
38  * Container class that holds a surface, necessary so that we can
39  * reload Surface implementations on the fly
40  */
41 class Surface
42 {
43 private:
44   friend class DrawingContext;
45   friend class Font;
46   ImageTexture* texture;
47
48   float uv_left;
49   float uv_top;
50   float uv_right;
51   float uv_bottom;
52
53   void draw(float x, float y, float alpha, DrawingEffect effect) const;
54   void draw_part(float src_x, float src_y, float dst_x, float dst_y,
55                  float width, float height,
56                  float alpha, DrawingEffect effect) const;
57
58   float width;
59   float height;
60 public:
61   Surface(const std::string& file);
62   Surface(const std::string& file, int x, int y, int w, int h);
63   Surface(const Surface& other);
64   ~Surface();
65
66   /** flip the surface horizontally */
67   void hflip();
68   
69   /** Reload the surface, which is necesarry in case of a mode swich */
70   void reload();
71
72   const Surface& operator= (const Surface& other);
73
74   float get_width() const
75   {
76     return width;
77   }
78
79   float get_height() const
80   {
81     return height;
82   }
83 };
84
85 #endif