-SurfaceSDL::SurfaceSDL(SDL_Surface* surf, bool use_alpha)
-{
- sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
- w = sdl_surface->w;
- h = sdl_surface->h;
-}
-
-SurfaceSDL::SurfaceSDL(const std::string& file, bool use_alpha)
-{
- sdl_surface = sdl_surface_from_file(file, use_alpha);
- w = sdl_surface->w;
- h = sdl_surface->h;
-}
-
-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);
- w = sdl_surface->w;
- h = sdl_surface->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);
- w = sdl_surface->w;
- h = sdl_surface->h;
-}
-
-int
-SurfaceSDL::draw(float x, float y, Uint8 alpha, Uint32 effect)
-{
- SDL_Rect dest;
-
- dest.x = (int)x;
- dest.y = (int)y;
- dest.w = w;
- dest.h = h;
-
- if(effect & SEMI_TRANSPARENT)
- alpha = 128;
-
- if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
- {
- // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
- for(float sx = 0; sx < w; sx++)
- for(float sy = 0; sy < h; sy++)
- if(draw_part(sx, sy, x+(w-sx), y+(h-sy), 1, 1, alpha, NONE_EFFECT) == -2)
- return -2;
- return 0;
- }
- else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
- {
- for(float sy = 0; sy < h; sy++)
- if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2)
- return -2;
- return 0;
- }
- else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
- {
- for(float sx = 0; sx < w; sx++)
- if(draw_part(sx, 0, x+(w-sx), y, 1, h, alpha, NONE_EFFECT) == -2)
- return -2;
- return 0;
- }
-
- if(alpha != 255)
- {
- /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
- to temp sur, blit the temp into the screen */
- /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
- already have an alpha mask yet... */
-
- SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
- sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
- sdl_surface->format->Rmask, sdl_surface->format->Gmask,
- sdl_surface->format->Bmask,
- 0);
- int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
- SDL_FillRect(sdl_surface_copy, NULL, colorkey);
- SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
-
-
- SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
- SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
-
- int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
-
- SDL_FreeSurface (sdl_surface_copy);
- return ret;
- }
-
- int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
-
- return ret;
-}
-
-int
-SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
-{
- SDL_Rect src, dest;
-
- src.x = (int)sx;
- src.y = (int)sy;
- src.w = (int)w;
- src.h = (int)h;
-
- dest.x = (int)x;
- dest.y = (int)y;
- dest.w = (int)w;
- dest.h = (int)h;
-
- if(effect & SEMI_TRANSPARENT)
- alpha = 128;
-
- if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
- {
- // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
- for(float sx_ = 0; sx_ < w; sx++)
- for(float sy_ = 0; sy_ < h; sy++)
- if(draw_part(sx_, sy_, sx+(w-sx_), sy+(h-sy_), 1, 1, alpha, NONE_EFFECT) == -2)
- return -2;
- return 0;
- }
- else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
- {
- for(float sy_ = sy; sy_ < h; sy_++)
- if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2)
- return -2;
- return 0;
- }
- else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
- {
- for(float sx_ = 0; sx_ < w; sx_++)
- if(draw_part(sx_, 0, sx+(w-sx_), sy, 1, h, alpha, NONE_EFFECT) == -2)
- return -2;
- return 0;
- }
-
- if(alpha != 255)
- {
- /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
- to temp sur, blit the temp into the screen */
- /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
- already have an alpha mask, yet... */
-
- SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
- (int)w, (int)h, sdl_surface->format->BitsPerPixel,
- sdl_surface->format->Rmask, sdl_surface->format->Gmask,
- sdl_surface->format->Bmask,
- 0);
- int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
- SDL_FillRect(sdl_surface_copy, NULL, colorkey);
- SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
-
-
- SDL_BlitSurface(sdl_surface, &src, sdl_surface_copy, NULL);
- SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
-
- int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
-
- SDL_FreeSurface (sdl_surface_copy);
- return ret;
- }
-
- int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest);
-
- return ret;
-}
-
-int
-SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)