From: Ricardo Cruz Date: Tue, 19 Oct 2004 17:45:38 +0000 (+0000) Subject: Added filter to horizontal flip Surfaces. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f1e420934b6afd3c65183db7d87018cbfbde1221;p=supertux.git Added filter to horizontal flip Surfaces. SVN-Revision: 2034 --- diff --git a/lib/video/surface.cpp b/lib/video/surface.cpp index 718fbeba9..1c69e3f9f 100644 --- a/lib/video/surface.cpp +++ b/lib/video/surface.cpp @@ -197,9 +197,9 @@ Surface::reload() } } -void Surface::apply_mask(Color color) +void Surface::apply_filter(int filter, Color color) { -impl->apply_mask(color); +impl->apply_filter(filter, color); } Surface::~Surface() @@ -255,7 +255,25 @@ Surface::resize(int w_, int h_) void apply_filter_to_surface(SDL_Surface* surface, int filter, Color color) { -if(filter == MASK_FILTER) +if(filter == HORIZONTAL_FLIP_FILTER) + { + SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true); + SDL_BlitSurface(surface, NULL, sur_copy, NULL); + SDL_SetAlpha(sur_copy,0,0); + + SDL_Rect src, dst; + src.y = dst.y = 0; + src.w = dst.w = 1; + src.h = dst.h = sur_copy->h; + for(int x = 0; x < sur_copy->w; x++) + { + src.x = x; dst.x = sur_copy->w - x; + SDL_BlitSurface(sur_copy, &src, surface, &dst); + } + + SDL_FreeSurface(sur_copy); + } +else if(filter == MASK_FILTER) { SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true); @@ -841,9 +859,9 @@ SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uin } void -SurfaceOpenGL::apply_mask(Color color) +SurfaceOpenGL::apply_filter(int filter, Color color) { - ::apply_filter_to_surface(sdl_surface, MASK_FILTER, color); + ::apply_filter_to_surface(sdl_surface, filter, color); create_gl(sdl_surface,&gl_texture); w = sdl_surface->w; @@ -1053,9 +1071,9 @@ SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 } void -SurfaceSDL::apply_mask(Color color) +SurfaceSDL::apply_filter(int filter, Color color) { - ::apply_filter_to_surface(sdl_surface, MASK_FILTER, color); + ::apply_filter_to_surface(sdl_surface, filter, color); w = sdl_surface->w; h = sdl_surface->h; diff --git a/lib/video/surface.h b/lib/video/surface.h index 23d0c2e3f..ef311d8a5 100644 --- a/lib/video/surface.h +++ b/lib/video/surface.h @@ -59,7 +59,9 @@ namespace SuperTux /// types of filters enum { - MASK_FILTER + HORIZONTAL_FLIP_FILTER, + MASK_FILTER, + NONE_FILTER }; /** This class holds all the data necessary to construct a surface */ @@ -118,7 +120,7 @@ namespace SuperTux void resize(int widht, int height); - void apply_mask(Color color); + void apply_filter(int filter, Color color = Color(0,0,0)); }; /** Surface implementation, all implementation have to inherit from @@ -146,7 +148,7 @@ namespace SuperTux SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function - virtual void apply_mask(Color color) = 0; + virtual void apply_filter(int filter, Color color = Color(0,0,0)) = 0; }; class SurfaceSDL : public SurfaceImpl @@ -162,7 +164,7 @@ namespace SuperTux 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_mask(Color color); + void apply_filter(int filter, Color color); }; #ifndef NOOPENGL @@ -183,7 +185,7 @@ namespace SuperTux 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_mask(Color color); + void apply_filter(int filter, Color color); private: void create_gl(SDL_Surface * surf, GLuint * tex);