#ifndef SUPERTUX_TEXTURE_H
#define SUPERTUX_TEXTURE_H
#include <SDL.h>
#include <string>
#ifndef NOOPENGL
#include <SDL_opengl.h>
#endif
#include <list>
#include "screen.h"
SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha);
class SurfaceImpl;
class SurfaceSDL;
class SurfaceOpenGL;
class SurfaceData
{
public:
enum ConstructorType { LOAD, LOAD_PART, SURFACE };
ConstructorType type;
SDL_Surface* surface;
std::string file;
int use_alpha;
int x;
int y;
int w;
int h;
SurfaceData(SDL_Surface* surf, int use_alpha_);
SurfaceData(const std::string& file_, int use_alpha_);
SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_);
~SurfaceData();
SurfaceSDL* create_SurfaceSDL();
SurfaceOpenGL* create_SurfaceOpenGL();
SurfaceImpl* create();
};
class Surface
{
public:
SurfaceData data;
SurfaceImpl* impl;
int w;
int h;
typedef std::list<Surface*> Surfaces;
static Surfaces surfaces;
public:
static void reload_all();
static void debug_check();
Surface(SDL_Surface* surf, int use_alpha);
Surface(const std::string& file, int use_alpha);
Surface(const std::string& file, int x, int y, int w, int h, int use_alpha);
~Surface();
static Surface* CaptureScreen();
void reload();
void draw(float x, float y, Uint8 alpha = 255, bool update = false);
void draw_bg(Uint8 alpha = 255, bool update = false);
void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false);
void draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update = false);
void resize(int w_, int h_);
};
class SurfaceImpl
{
protected:
SDL_Surface* sdl_surface;
public:
int w;
int h;
public:
SurfaceImpl();
virtual ~SurfaceImpl();
virtual int draw(float x, float y, Uint8 alpha, bool update) = 0;
virtual int draw_bg(Uint8 alpha, bool update) = 0;
virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0;
virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0;
int resize(int w_, int h_);
SDL_Surface* get_sdl_surface() const;
};
class SurfaceSDL : public SurfaceImpl
{
public:
SurfaceSDL(SDL_Surface* surf, int use_alpha);
SurfaceSDL(const std::string& file, int use_alpha);
SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
virtual ~SurfaceSDL();
int draw(float x, float y, Uint8 alpha, bool update);
int draw_bg(Uint8 alpha, bool update);
int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
};
#ifndef NOOPENGL
class SurfaceOpenGL : public SurfaceImpl
{
public:
unsigned gl_texture;
public:
SurfaceOpenGL(SDL_Surface* surf, int use_alpha);
SurfaceOpenGL(const std::string& file, int use_alpha);
SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
virtual ~SurfaceOpenGL();
int draw(float x, float y, Uint8 alpha, bool update);
int draw_bg(Uint8 alpha, bool update);
int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
private:
void create_gl(SDL_Surface * surf, GLuint * tex);
};
#endif
#endif