fix cr/lfs and remove trailing whitespaces...
[supertux.git] / src / video / image_texture.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  02111-1307, USA.
19
20 #ifndef __SURFACE_TEXTURE_HPP__
21 #define __SURFACE_TEXTURE_HPP__
22
23 #include <string>
24 #include <assert.h>
25 #include "texture.hpp"
26
27 class ImageTexture : public Texture
28 {
29 private:
30   std::string filename;
31   float image_width;
32   float image_height;
33   int refcount;
34
35 public:
36   float get_image_width() const
37   {
38     return image_width;
39   }
40
41   float get_image_height() const
42   {
43     return image_height;
44   }
45
46   float get_uv_right() const
47   {
48     return image_width / static_cast<float> (get_width());
49   }
50
51   float get_uv_bottom() const
52   {
53     return image_height / static_cast<float> (get_height());
54   }
55
56   void ref()
57   {
58     refcount++;
59   }
60
61   void unref()
62   {
63     assert(refcount > 0);
64     refcount--;
65     if(refcount == 0)
66       release();
67   }
68
69 private:
70   friend class TextureManager;
71
72   ImageTexture(SDL_Surface* surface);
73   virtual ~ImageTexture();
74
75   void release();
76 };
77
78 #endif