- converted text_type into a class
[supertux.git] / src / texture.h
1 //
2 // C Interface: texture
3 //
4 // Description: 
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #ifndef SUPERTUX_TEXTURE_H
14 #define SUPERTUX_TEXTURE_H
15
16 #include <SDL.h>
17 #include <string>
18 #ifndef NOOPENGL
19 #include <SDL_opengl.h>
20 #endif
21
22 #include "screen.h"
23
24 class SurfaceImpl;
25
26 /** Container class that holds a surface, necessary so that we can
27     switch Surface implementations (OpenGL, SDL) on the fly */
28 class Surface
29 {
30 public:
31   SurfaceImpl* impl;
32   int w; 
33   int h;
34 public:
35   Surface(SDL_Surface* surf, int use_alpha);  
36   Surface(const std::string& file, int use_alpha);  
37   Surface(const std::string& file, int x, int y, int w, int h, int use_alpha);
38   ~Surface();
39
40   void draw(float x, float y, Uint8 alpha = 255, bool update = false);
41   void draw_bg(Uint8 alpha = 255, bool update = false);
42   void draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha = 255, bool update = false);
43 };
44
45 /** Surface implementation, all implementation have to inherit from
46     this class */
47 class SurfaceImpl
48 {
49 public:
50   SDL_Surface* sdl_surface;
51   int w;
52   int h;
53
54 public:
55   virtual void draw(float x, float y, Uint8 alpha, bool update) = 0;
56   virtual void draw_bg(Uint8 alpha, bool update) = 0;
57   virtual void draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update) = 0;
58 };
59
60 class SurfaceSDL : public SurfaceImpl
61 {
62 public:
63   
64 public:
65   SurfaceSDL(SDL_Surface* surf, int use_alpha);
66   SurfaceSDL(const std::string& file, int use_alpha);  
67   SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
68   virtual ~SurfaceSDL();
69
70   void draw(float x, float y, Uint8 alpha, bool update);
71   void draw_bg(Uint8 alpha, bool update);
72   void draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update);
73 };
74
75 class SurfaceOpenGL : public SurfaceImpl
76 {
77 public:
78   unsigned gl_texture;
79
80 public:
81   SurfaceOpenGL(SDL_Surface* surf, int use_alpha);
82   SurfaceOpenGL(const std::string& file, int use_alpha);  
83   SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
84   virtual ~SurfaceOpenGL();
85
86   void draw(float x, float y, Uint8 alpha, bool update);
87   void draw_bg(Uint8 alpha, bool update);
88   void draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update);
89
90 private:
91   void create_gl(SDL_Surface * surf, GLuint * tex);
92 };
93
94 #endif /*SUPERTUX_TEXTURE_H*/
95
96 /* Local Variables: */
97 /* mode: c++ */
98 /* End: */