X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fvideo%2Fsurface.cpp;h=3c98b30747c3526a8fb52798f8cafbb06a7dfe11;hb=133d94d5b145f325c38c8c15c9ea561bfffb092d;hp=d9ab082539f200b77433ad248d03286aab0be64e;hpb=995d8328815cad1e6572b832832bb61a8aeaeb8e;p=supertux.git diff --git a/lib/video/surface.cpp b/lib/video/surface.cpp index d9ab08253..3c98b3074 100644 --- a/lib/video/surface.cpp +++ b/lib/video/surface.cpp @@ -27,17 +27,18 @@ #include "SDL.h" #include "SDL_image.h" -#include "../video/surface.h" -#include "../video/screen.h" -#include "../app/globals.h" -#include "../app/setup.h" +#include "video/surface.h" +#include "video/screen.h" +#include "app/globals.h" +#include "app/setup.h" using namespace SuperTux; Surface::Surfaces Surface::surfaces; SurfaceData::SurfaceData(SDL_Surface* temp, bool use_alpha_) - : type(SURFACE), surface(0), use_alpha(use_alpha_) + : type(SURFACE), surface(0), use_alpha(use_alpha_), + x(0), y(0), w(0), h(0) { // Copy the given surface and make sure that it is not stored in // video memory @@ -58,12 +59,14 @@ SurfaceData::SurfaceData(const std::string& file_, bool use_alpha_) : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_) {} -SurfaceData::SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_) +SurfaceData::SurfaceData(const std::string& file_, int x_, int y_, + int w_, int h_, bool use_alpha_) : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_), x(x_), y(y_), w(w_), h(h_) {} -SurfaceData::SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_) +SurfaceData::SurfaceData(Color top_gradient_, Color bottom_gradient_, + int w_, int h_) : type(GRADIENT), surface(0), use_alpha(false), w(w_), h(h_) { top_gradient = top_gradient_; @@ -163,8 +166,8 @@ Surface::Surface(const std::string& file, bool use_alpha) surfaces.push_back(this); } -Surface::Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha) - : data(file, x, y, w, h, use_alpha), w(0), h(0) +Surface::Surface(const std::string& file, int x, int y, int w_, int h_, bool use_alpha) + : data(file, x, y, w_, h_, use_alpha), w(0), h(0) { impl = data.create(); if (impl) @@ -205,12 +208,12 @@ Surface::reload() void Surface::apply_filter(int filter, Color color) { -impl->apply_filter(filter, color); + impl->apply_filter(filter, color); -SurfaceData::Filter apply_filter; -apply_filter.type = filter; -apply_filter.color = color; -data.applied_filters.push_back(apply_filter); + SurfaceData::Filter apply_filter; + apply_filter.type = filter; + apply_filter.color = color; + data.applied_filters.push_back(apply_filter); } Surface::~Surface() @@ -252,58 +255,41 @@ Surface::debug_check() } void -Surface::resize(int w_, int h_) -{ - if (impl) - { - w = w_; - h = h_; - if (impl->resize(w_,h_) == -2) - reload(); - } -} - -void apply_filter_to_surface(SDL_Surface* surface, int filter, Color color) { -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++) + 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-1 - x; - SDL_BlitSurface(sur_copy, &src, surface, &dst); + src.x = x; dst.x = sur_copy->w-1 - 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); + SDL_FreeSurface(sur_copy); + } else if(filter == MASK_FILTER) { + SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true); - Uint8 r,g,b,a; + Uint8 r,g,b,a; - SDL_LockSurface(sur_copy); - for(int x = 0; x < sur_copy->w; x++) - for(int y = 0; y < sur_copy->h; y++) - { - SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a); - if(a != 0) - { - putpixel(sur_copy, x,y, color.map_rgba(sur_copy)); + SDL_LockSurface(sur_copy); + for(int x = 0; x < sur_copy->w; x++) + for(int y = 0; y < sur_copy->h; y++) { + SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a); + if(a != 0) { + putpixel(sur_copy, x,y, color.map_rgba(sur_copy)); } } - SDL_UnlockSurface(sur_copy); + SDL_UnlockSurface(sur_copy); - SDL_BlitSurface(sur_copy, NULL, surface, NULL); - SDL_FreeSurface(sur_copy); + SDL_BlitSurface(sur_copy, NULL, surface, NULL); + SDL_FreeSurface(sur_copy); } } @@ -327,19 +313,12 @@ sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, src.w = w; src.h = h; - conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel, + conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, temp->format->BitsPerPixel, temp->format->Rmask, temp->format->Gmask, temp->format->Bmask, temp->format->Amask); - /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN - 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); - #else - - 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - #endif*/ - SDL_SetAlpha(temp,0,0); SDL_BlitSurface(temp, &src, conv, NULL); @@ -431,22 +410,18 @@ SuperTux::sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha) SDL_Surface* sdl_surface_from_gradient(Color top, Color bottom, int w, int h) { - SDL_Surface* sdl_surface; - - sdl_surface = SDL_CreateRGBSurface(screen->flags, w, h, + SDL_Surface* sdl_surface + = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, 0); - if(sdl_surface == NULL) + if(sdl_surface == 0) Termination::abort("Cannot create surface for the gradient", "SURFACE"); - if(top == bottom) - { + if(top == bottom) { SDL_FillRect(sdl_surface, NULL, SDL_MapRGB(sdl_surface->format, top.red, top.green, top.blue)); - } - else - { + } else { float redstep = (float(bottom.red)-float(top.red)) / float(h); float greenstep = (float(bottom.green)-float(top.green)) / float(h); float bluestep = (float(bottom.blue) - float(top.blue)) / float(h); @@ -455,15 +430,14 @@ sdl_surface_from_gradient(Color top, Color bottom, int w, int h) rect.x = 0; rect.w = w; rect.h = 1; - for(float y = 0; y < h; y++) - { + for(float y = 0; y < h; y++) { rect.y = (int)y; SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format, - int(float(top.red) + redstep * y), - int(float(top.green) + greenstep * y), - int(float(top.blue) + bluestep * y))); - } + int(float(top.red) + redstep * y), + int(float(top.green) + greenstep * y), + int(float(top.blue) + bluestep * y))); } + } return sdl_surface; } @@ -483,20 +457,6 @@ SDL_Surface* SurfaceImpl::get_sdl_surface() const return sdl_surface; } -int SurfaceImpl::resize(int w_, int h_) -{ - w = w_; - h = h_; - SDL_Rect dest; - dest.x = 0; - dest.y = 0; - dest.w = w; - dest.h = h; - int ret = SDL_SoftStretch(sdl_surface, NULL, - sdl_surface, &dest); - return ret; -} - #ifndef NOOPENGL SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, bool use_alpha) { @@ -516,23 +476,23 @@ SurfaceOpenGL::SurfaceOpenGL(const std::string& file, bool use_alpha) h = sdl_surface->h; } -SurfaceOpenGL::SurfaceOpenGL(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_) +SurfaceOpenGL::SurfaceOpenGL(const std::string& file_, int x_, int y_, + int w_, int h_, bool use_alpha_) { sdl_surface = sdl_surface_part_from_file(file_,x_,y_,w_,h_,use_alpha_); create_gl(sdl_surface, &gl_texture); - w = sdl_surface->w; - h = sdl_surface->h; + h = sdl_surface->h; } -SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h) +SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient, + int _w, int _h) { - sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h); + sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient,_w,_h); create_gl(sdl_surface, &gl_texture); - w = sdl_surface->w; - h = sdl_surface->h; + h = sdl_surface->h; } SurfaceOpenGL::~SurfaceOpenGL() @@ -892,18 +852,20 @@ SurfaceSDL::SurfaceSDL(const std::string& file, bool use_alpha) h = sdl_surface->h; } -SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int w, int h, bool use_alpha) +SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int _w, int _h, + bool use_alpha) { - sdl_surface = sdl_surface_part_from_file(file, x, y, w, h, use_alpha); + sdl_surface = sdl_surface_part_from_file(file, x, y, _w, _h, use_alpha); w = sdl_surface->w; - h = sdl_surface->h; + h = sdl_surface->h; } -SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h) +SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient, + int _w, int _h) { - sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h); + sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient,_w,_h); w = sdl_surface->w; - h = sdl_surface->h; + h = sdl_surface->h; } int @@ -1090,4 +1052,3 @@ SurfaceSDL::apply_filter(int filter, Color color) SurfaceSDL::~SurfaceSDL() {} -/* EOF */