Changed up and down to previous and next. And added up and down icons.
[supertux.git] / src / texture.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.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
21 #ifndef SUPERTUX_TEXTURE_H
22 #define SUPERTUX_TEXTURE_H
23
24 #include <SDL.h>
25 #include <string>
26 #ifndef NOOPENGL
27 #include <SDL_opengl.h>
28 #endif
29
30 #include <list>
31 #include "screen.h"
32
33 SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha);
34
35 class SurfaceImpl;
36 class SurfaceSDL;
37 class SurfaceOpenGL;
38
39 /** This class holds all the data necessary to construct a surface */
40 class SurfaceData 
41 {
42 public:
43   enum ConstructorType { LOAD, LOAD_PART, SURFACE };
44   ConstructorType type;
45   SDL_Surface* surface;
46   std::string file;
47   int use_alpha;
48   int x;
49   int y;
50   int w;
51   int h;
52
53   SurfaceData(SDL_Surface* surf, int use_alpha_);
54   SurfaceData(const std::string& file_, int use_alpha_);
55   SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_);
56   ~SurfaceData();
57
58   SurfaceSDL* create_SurfaceSDL();
59   SurfaceOpenGL* create_SurfaceOpenGL();
60   SurfaceImpl* create();
61 };
62
63 /** Container class that holds a surface, necessary so that we can
64     switch Surface implementations (OpenGL, SDL) on the fly */
65 class Surface
66 {
67 public:
68   SurfaceData data;
69   SurfaceImpl* impl;
70   int w; 
71   int h;
72   
73   typedef std::list<Surface*> Surfaces;
74   static Surfaces surfaces;
75 public:
76   static void reload_all();
77   static void debug_check();
78
79   Surface(SDL_Surface* surf, int use_alpha);  
80   Surface(const std::string& file, int use_alpha);  
81   Surface(const std::string& file, int x, int y, int w, int h, int use_alpha);
82   ~Surface();
83   
84   /** Captures the screen and returns it as Surface*, the user is expected to call the destructor. */
85   static Surface* CaptureScreen();
86   
87   /** Reload the surface, which is necesarry in case of a mode swich */
88   void reload();
89
90   void draw(float x, float y, Uint8 alpha = 255, bool update = false);
91   void draw_bg(Uint8 alpha = 255, bool update = false);
92   void draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha = 255, bool update = false);
93   void draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update = false);
94   void resize(int w_, int h_);
95 };
96
97 /** Surface implementation, all implementation have to inherit from
98     this class */
99 class SurfaceImpl
100 {
101 protected:
102   SDL_Surface* sdl_surface;
103
104 public:
105   int w;
106   int h;
107
108 public:
109   SurfaceImpl();
110   virtual ~SurfaceImpl();
111   
112   /** Return 0 on success, -2 if surface needs to be reloaded */
113   virtual int draw(float x, float y, Uint8 alpha, bool update) = 0;
114   virtual int draw_bg(Uint8 alpha, bool update) = 0;
115   virtual int draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update) = 0;
116   virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0;
117   int resize(int w_, int h_);
118
119   SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function
120 };
121
122 class SurfaceSDL : public SurfaceImpl
123 {
124 public:
125   SurfaceSDL(SDL_Surface* surf, int use_alpha);
126   SurfaceSDL(const std::string& file, int use_alpha);  
127   SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
128   virtual ~SurfaceSDL();
129
130   int draw(float x, float y, Uint8 alpha, bool update);
131   int draw_bg(Uint8 alpha, bool update);
132   int draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update);
133   int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
134 };
135
136 #ifndef NOOPENGL
137 class SurfaceOpenGL : public SurfaceImpl
138 {
139 public:
140   unsigned gl_texture;
141
142 public:
143   SurfaceOpenGL(SDL_Surface* surf, int use_alpha);
144   SurfaceOpenGL(const std::string& file, int use_alpha);  
145   SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
146   virtual ~SurfaceOpenGL();
147
148   int draw(float x, float y, Uint8 alpha, bool update);
149   int draw_bg(Uint8 alpha, bool update);
150   int draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update);
151   int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
152
153 private:
154   void create_gl(SDL_Surface * surf, GLuint * tex);
155 };
156 #endif 
157
158 #endif /*SUPERTUX_TEXTURE_H*/
159
160 /* Local Variables: */
161 /* mode: c++ */
162 /* End: */