X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvideo%2Fsurface.hpp;h=0945253edff8810bed4124303e1bd8314aa5b226;hb=6b50afc6cdd8d3555901b02ce12f15b5bac32aa8;hp=d2cae0c157a229e2bcaa92fe1043246f8a6df57a;hpb=5b7f9214cb929399f1a855ef5807018a9447d510;p=supertux.git diff --git a/src/video/surface.hpp b/src/video/surface.hpp index d2cae0c15..0945253ed 100644 --- a/src/video/surface.hpp +++ b/src/video/surface.hpp @@ -1,7 +1,7 @@ -// $Id: surface.h 2175 2004-11-24 19:02:49Z sik0fewl $ +// $Id$ // // SuperTux -// Copyright (C) 2004 Tobias Glaesser +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -17,170 +17,70 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. -#ifndef SUPERTUX_TEXTURE_H -#define SUPERTUX_TEXTURE_H +#ifndef __SURFACE_HPP__ +#define __SURFACE_HPP__ #include -#include -#include -#include +class Color; +class Blend; +class ImageTexture; -#include "math/vector.hpp" -#include "video/screen.hpp" - -void apply_filter_to_surface(SDL_Surface *surface, int filter, int value); -SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha); -SDL_Surface* sdl_surface_from_nothing(); - -class SurfaceImpl; -class SurfaceSDL; -class SurfaceOpenGL; -class DrawingContext; - /// bitset for drawing effects -enum { +enum DrawingEffect { /** Don't apply anything */ - NONE_EFFECT = 0x0000, + NO_EFFECT = 0x0000, /** Draw the Surface upside down */ VERTICAL_FLIP = 0x0001, /** Draw the Surface from left to down */ HORIZONTAL_FLIP = 0x0002, - /** Draw the Surface with alpha equal to 128 */ - SEMI_TRANSPARENT = 0x0004 -}; - -/// types of filters -enum { - HORIZONTAL_FLIP_FILTER, - MASK_FILTER, - NONE_FILTER -}; - -/** This class holds all the data necessary to construct a surface */ -class SurfaceData -{ -public: - enum ConstructorType { LOAD, LOAD_PART, SURFACE, GRADIENT }; - ConstructorType type; - SDL_Surface* surface; - std::string file; - - struct Filter { int type; Color color; }; - std::vector applied_filters; - - bool use_alpha; - int x; - int y; - int w; - int h; - Color top_gradient; - Color bottom_gradient; - - SurfaceData(SDL_Surface* surf, bool use_alpha_); - SurfaceData(const std::string& file_, bool use_alpha_); - SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_); - SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_); - ~SurfaceData(); - - SurfaceSDL* create_SurfaceSDL(); - SurfaceOpenGL* create_SurfaceOpenGL(); - SurfaceImpl* create(); }; - -/** Container class that holds a surface, necessary so that we can - * switch Surface implementations (OpenGL, SDL) on the fly +/** + * A rectangular image. + * The class basically holds a reference to a texture with additional UV + * coordinates that specify a rectangular area on this texture */ class Surface { +private: + friend class DrawingContext; + friend class Font; + ImageTexture* texture; + + float uv_left; + float uv_top; + float uv_right; + float uv_bottom; + + void draw(float x, float y, float alpha, float angle, const Color& color, const Blend& blend, DrawingEffect effect) const; + void draw(float x, float y, float alpha, DrawingEffect effect) const; + void draw_part(float src_x, float src_y, float dst_x, float dst_y, + float width, float height, + float alpha, DrawingEffect effect) const; + + float width; + float height; public: - SurfaceImpl* impl; - SurfaceData data; - int w; - int h; - - typedef std::list Surfaces; - static Surfaces surfaces; -public: - static void reload_all(); - static void debug_check(); - - Surface(SDL_Surface* surf, bool use_alpha); - Surface(const std::string& file, bool use_alpha); - Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha); - Surface(Color top_gradient, Color bottom_gradient, int w_, int h_); + Surface(const std::string& file); + Surface(const std::string& file, int x, int y, int w, int h); + Surface(const Surface& other); ~Surface(); - - /** Reload the surface, which is necesarry in case of a mode swich */ - void reload(); - - void apply_filter(int filter, Color color = Color(0,0,0)); -}; -/** Surface implementation, all implementation have to inherit from - this class */ -class SurfaceImpl -{ -protected: - SDL_Surface* sdl_surface; - -public: - int w; - int h; - -public: - SurfaceImpl(); - virtual ~SurfaceImpl(); - - /** Return 0 on success, -2 if surface needs to be reloaded */ - virtual int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; - virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; - virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; + /** flip the surface horizontally */ + void hflip(); - - SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function - - virtual void apply_filter(int filter, Color color = Color(0,0,0)) = 0; -}; + const Surface& operator= (const Surface& other); -class SurfaceSDL : public SurfaceImpl -{ -public: - SurfaceSDL(SDL_Surface* surf, bool use_alpha); - SurfaceSDL(const std::string& file, bool use_alpha); - SurfaceSDL(const std::string& file, int x, int y, int w_, int h_, bool use_alpha); - SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h); - virtual ~SurfaceSDL(); - - int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT); - int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT); - int draw_stretched(float x, float y, int w, int h, Uint8 alpha, Uint32 effect = NONE_EFFECT); - - void apply_filter(int filter, Color color); -}; + float get_width() const + { + return width; + } -class SurfaceOpenGL : public SurfaceImpl -{ -public: - GLuint gl_texture; - -public: - SurfaceOpenGL(SDL_Surface* surf, bool use_alpha); - SurfaceOpenGL(const std::string& file, bool use_alpha); - SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, bool use_alpha); - SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h); - - virtual ~SurfaceOpenGL(); - - int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT); - int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT); - int draw_stretched(float x, float y, int w, int h, Uint8 alpha, Uint32 effect = NONE_EFFECT); - - void apply_filter(int filter, Color color); - -private: - void create_gl(SDL_Surface * surf, GLuint * tex); + float get_height() const + { + return height; + } }; #endif