X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fvideo%2Fsurface.cpp;h=73dc131b4bf0b73b78bf7f28237746b5a21ca6e4;hb=1028ce017d6809007e39a8f7c034a0d62bfe3052;hp=1adff4f948aa5a08aabf2fa201187b2d5ad7457f;hpb=f10f7bbeb7f782c09c290e2474df2dcedd9a2820;p=supertux.git diff --git a/lib/video/surface.cpp b/lib/video/surface.cpp index 1adff4f94..73dc131b4 100644 --- a/lib/video/surface.cpp +++ b/lib/video/surface.cpp @@ -26,6 +26,7 @@ #include "SDL_image.h" #include "../video/surface.h" +#include "../video/screen.h" #include "../app/globals.h" #include "../app/setup.h" @@ -196,6 +197,11 @@ Surface::reload() } } +void Surface::apply_mask(Color color) +{ +impl->apply_mask(color); +} + Surface::~Surface() { #ifdef DEBUG @@ -246,6 +252,32 @@ Surface::resize(int w_, int h_) } } +void +apply_filter_to_surface(SDL_Surface* surface, int filter, Color color) +{ +if(filter == MASK_FILTER) + { + Uint8 r,g,b,a; + SDL_Rect rect; + rect.w = rect.h = 1; + SDL_LockSurface(surface); + for(int x = 0; x < surface->w; x++) + for(int y = 0; y < surface->h; y++) + { +// SDL_LockSurface(surface); + SDL_GetRGBA(getpixel(surface,x,y), surface->format, &r,&g,&b,&a); +// SDL_UnlockSurface(surface); + if(a != 0) + { + putpixel(surface, x,y, color.map_rgba(surface)); +// rect.x = x; rect.y = y; +// SDL_FillRect(surface, &rect, color.map_rgba(surface)); + } + } + SDL_UnlockSurface(surface); + } +} + SDL_Surface* sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, bool use_alpha) { @@ -804,6 +836,16 @@ SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uin return 0; } +void +SurfaceOpenGL::apply_mask(Color color) +{ + ::apply_filter_to_surface(sdl_surface, MASK_FILTER, color); + create_gl(sdl_surface,&gl_texture); + + w = sdl_surface->w; + h = sdl_surface->h; +} + #endif SurfaceSDL::SurfaceSDL(SDL_Surface* surf, bool use_alpha) @@ -1006,6 +1048,15 @@ SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 return ret; } +void +SurfaceSDL::apply_mask(Color color) +{ + ::apply_filter_to_surface(sdl_surface, MASK_FILTER, color); + + w = sdl_surface->w; + h = sdl_surface->h; +} + SurfaceSDL::~SurfaceSDL() {}