Renamed MainLoop to ScreenManager
[supertux.git] / src / video / texture.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_VIDEO_TEXTURE_HPP
18 #define HEADER_SUPERTUX_VIDEO_TEXTURE_HPP
19
20 #include <config.h>
21
22 #include <assert.h>
23 #include <string>
24
25 #include "supertux/globals.hpp"
26 #include "video/texture_manager.hpp"
27
28 /// bitset for drawing effects
29 enum DrawingEffect {
30   /** Don't apply anything */
31   NO_EFFECT,
32   /** Draw the Surface upside down */
33   VERTICAL_FLIP,
34   /** Draw the Surface from left to down */
35   HORIZONTAL_FLIP,
36   NUM_EFFECTS
37 };
38
39 /**
40  * This class is a wrapper around a texture handle. It stores the texture width
41  * and height and provides convenience functions for uploading SDL_Surfaces
42  * into the texture
43  */
44 class Texture
45 {
46 protected:
47   int refcount;
48   std::string filename;
49
50 public:
51   Texture() : refcount(0), filename() {}
52   virtual ~Texture() {}
53
54   virtual unsigned int get_texture_width() const = 0;
55   virtual unsigned int get_texture_height() const = 0;
56   virtual unsigned int get_image_width() const = 0;
57   virtual unsigned int get_image_height() const = 0;
58
59   std::string get_filename() const
60   {
61     return filename;
62   }
63
64   void set_filename(std::string filename)
65   {
66     this->filename = filename;
67   }
68
69   void ref()
70   {
71     refcount++;
72   }
73
74   void unref()
75   {
76     assert(refcount > 0);
77     refcount--;
78     if(refcount == 0)
79       release();
80   }
81
82 private:
83   void release()
84   {
85     texture_manager->release(this);
86   }
87
88 private:
89   Texture(const Texture&);
90   Texture& operator=(const Texture&);
91 };
92
93 #endif
94
95 /* EOF */