00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "SurfaceTool.h"
00010
00011 #include "SDLException.h"
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 SDL_Surface *
00022 SurfaceTool::createEmpty(SDL_Surface *surface, int width, int height)
00023 {
00024 if (!width) {
00025 width = surface->w;
00026 }
00027 if (!height) {
00028 height = surface->h;
00029 }
00030
00031 SDL_Surface *result = SDL_CreateRGBSurface(surface->flags, width, height,
00032 surface->format->BitsPerPixel,
00033 surface->format->Rmask,
00034 surface->format->Gmask,
00035 surface->format->Bmask,
00036 surface->format->Amask);
00037 if (NULL == result) {
00038 throw SDLException(ExInfo("ConvertSurface"));
00039 }
00040 return result;
00041 }
00042
00043
00044
00045
00046
00047
00048 SDL_Surface *
00049 SurfaceTool::createClone(SDL_Surface *surface)
00050 {
00051 SDL_Surface *clone = SDL_ConvertSurface(surface,
00052 surface->format, surface->flags);
00053 if (NULL == clone) {
00054 throw SDLException(ExInfo("ConvertSurface"));
00055 }
00056 return clone;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 void
00068 SurfaceTool::alphaFill(SDL_Surface *surface, SDL_Rect *dstrect,
00069 const SDL_Color &color)
00070 {
00071 int w = surface->w;
00072 int h = surface->h;
00073 if (dstrect) {
00074 w = dstrect->w;
00075 h = dstrect->h;
00076 }
00077 SDL_Surface *canvas = createEmpty(surface, w, h);
00078 Uint32 pixel = SDL_MapRGB(canvas->format, color.r, color.g, color.b);
00079 SDL_FillRect(canvas, NULL, pixel);
00080 SDL_SetAlpha(canvas, SDL_SRCALPHA|SDL_RLEACCEL, color.unused);
00081
00082 SDL_BlitSurface(canvas, NULL, surface, dstrect);
00083 SDL_FreeSurface(canvas);
00084 }
00085