#include <surface.h>
Public Member Functions | |
Surface () | |
Surface (SDL_Surface *sdl_surface) | |
Surface (const Point2i &size, Uint32 flags, bool useAlpha=true) | |
Surface (const std::string &filename) | |
Surface (const Surface &src) | |
~Surface () | |
Surface & | operator= (const Surface &src) |
void | Free () |
void | AutoFree () |
void | SetAutoFree (bool newAutoFree) |
void | SetSurface (SDL_Surface *newSurface, bool freePrevious=true) |
void | NewSurface (const Point2i &size, Uint32 flags, bool useAlpha=true) |
SDL_Surface * | GetSurface () |
int | SetAlpha (Uint32 flags, Uint8 alpha) |
int | Lock () |
void | Unlock () |
int | Blit (const Surface &src) |
int | Blit (const Surface &src, const Point2i &dst) |
int | Blit (const Surface &src, const Rectanglei &srcRect, const Point2i &dstPoint) |
int | SetColorKey (Uint32 flag, Uint32 key) |
int | SetColorKey (Uint32 flag, Uint8 r, Uint8 g, Uint8 b, Uint8 a) |
void | GetRGBA (Uint32 color, Uint8 &r, Uint8 &g, Uint8 &b, Uint8 &a) const |
Uint32 | MapRGBA (Uint8 r, Uint8 g, Uint8 b, Uint8 a) const |
Color | GetColor (Uint32 color) const |
Uint32 | MapColor (Color color) const |
void | SetClipRect (const Rectanglei &rect) |
void | Flip () |
int | BoxColor (const Rectanglei &rect, const Color &color) |
int | RectangleColor (const Rectanglei &rect, const Color &color, const uint &border_size=1) |
int | VlineColor (const uint &x1, const uint &y1, const uint &y2, const Color &color) |
int | LineColor (const uint &x1, const uint &x2, const uint &y1, const uint &y2, const Color &color) |
int | AALineColor (const uint &x1, const uint &x2, const uint &y1, const uint &y2, const Color &color) |
int | CircleColor (const uint &x, const uint &y, const uint &rad, const Color &color) |
int | Fill (Uint32 color) const |
int | Fill (const Color &color) const |
int | FillRect (const Rectanglei &dstRect, Uint32 color) const |
int | FillRect (const Rectanglei &dstRect, const Color &color) const |
int | ImgLoad (std::string filename) |
Surface | RotoZoom (double angle, double zoomx, double zoomy, int smooth) |
Surface | DisplayFormatAlpha () |
Surface | DisplayFormat () |
Uint32 | GetPixel (int x, int y) |
void | PutPixel (int x, int y, Uint32 pixel) |
bool | IsNull () const |
Point2i | GetSize () const |
int | GetWidth () const |
Return the width of a surface. | |
int | GetHeight () const |
Return the height of a surface. | |
Uint32 | GetFlags () const |
Uint16 | GetPitch () const |
Return the length of a surface scanline in bytes. | |
Uint8 | GetBytesPerPixel () const |
Return the number of bytes used to represent each pixel in a surface. Usually one to four. | |
unsigned char * | GetPixels () const |
Return a pointer on the pixels data. | |
Private Member Functions | |
int | Blit (const Surface &src, SDL_Rect *srcRect, SDL_Rect *dstRect) |
SDL_Rect | GetSDLRect (const Rectanglei &r) const |
SDL_Rect | GetSDLRect (const Point2i &r) const |
Private Attributes | |
SDL_Surface * | surface |
bool | autoFree |
Definition at line 32 of file surface.h.
Surface::Surface | ( | ) | [explicit] |
Default constructor.
Build a null surface with autoFree at true.
Definition at line 38 of file surface.cpp.
Surface::Surface | ( | SDL_Surface * | sdl_surface | ) | [explicit] |
Constructor building a surface object using an existing SDL_Surface pointer.
sdl_surface | The existing sdl_surface. |
Definition at line 48 of file surface.cpp.
Surface::Surface | ( | const Point2i & | size, | |
Uint32 | flags, | |||
bool | useAlpha = true | |||
) | [explicit] |
Constructor building a surface object using the NewSurface function.
size | ||
flags | ||
useAlpha |
Definition at line 61 of file surface.cpp.
00061 { 00062 surface = NULL; 00063 autoFree = true; 00064 NewSurface(size, flags, useAlpha); 00065 }
Here is the call graph for this function:
Surface::Surface | ( | const std::string & | filename | ) | [explicit] |
Constructor building a surface by reading the image from a file.
filename_str | A string containing the path to the graphic file. |
Definition at line 72 of file surface.cpp.
00072 { 00073 surface = NULL; 00074 autoFree = true; 00075 if( !ImgLoad(filename) ) 00076 Error( Format("Unable to open image file : %s", filename.c_str() ) ); 00077 }
Here is the call graph for this function:
Surface::Surface | ( | const Surface & | src | ) |
Copy constructor: build a surface from an other surface.
The two surfaces share the same graphic data.
Definition at line 84 of file surface.cpp.
00084 { 00085 surface = src.surface; 00086 autoFree = true; 00087 if( !IsNull() ) 00088 surface->refcount++; 00089 }
Here is the call graph for this function:
Surface::~Surface | ( | ) |
Destructor of the surface.
Will free the memory used by the surface if autoFree is set to true and if the counter of reference reach 0
Definition at line 96 of file surface.cpp.
00096 { 00097 AutoFree(); 00098 }
Here is the call graph for this function:
void Surface::AutoFree | ( | ) |
Definition at line 121 of file surface.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:
int Surface::Blit | ( | const Surface & | src, | |
const Rectanglei & | srcRect, | |||
const Point2i & | dstPoint | |||
) |
Blit a part (srcRect) of surface (src) at a certaint position (dst) of the current surface/
src | ||
srcRect | ||
dstPoint |
Definition at line 252 of file surface.cpp.
00252 { 00253 SDL_Rect sdlSrcRect = GetSDLRect( srcRect ); 00254 SDL_Rect sdlDstRect = GetSDLRect( dstPoint ); 00255 00256 return Blit(src, &sdlSrcRect, &sdlDstRect); 00257 }
Here is the call graph for this function:
Blit a surface (src) on the current surface at a certain position (dst)
The source surface. A point defining the destination coordinate on the current surface.
Definition at line 239 of file surface.cpp.
00239 { 00240 SDL_Rect dstRect = GetSDLRect( dst );; 00241 00242 return Blit(src, NULL, &dstRect); 00243 }
Here is the call graph for this function:
int Surface::Blit | ( | const Surface & | src | ) |
Blit the whole surface src on the current surface.
src | The source surface. |
Definition at line 229 of file surface.cpp.
Here is the call graph for this function:
int Surface::Blit | ( | const Surface & | src, | |
SDL_Rect * | srcRect, | |||
SDL_Rect * | dstRect | |||
) | [private] |
int Surface::BoxColor | ( | const Rectanglei & | rect, | |
const Color & | color | |||
) |
Definition at line 336 of file surface.cpp.
00336 { 00337 if( rect.IsSizeZero() ) 00338 return 0; 00339 00340 Point2i ptBR = rect.GetBottomRightPoint(); 00341 00342 return boxRGBA( surface, rect.GetPositionX(), rect.GetPositionY(), ptBR.GetX(), ptBR.GetY(), color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha() ); 00343 }
Here is the call graph for this function:
Here is the caller graph for this function:
Surface Surface::DisplayFormat | ( | ) |
Definition at line 476 of file surface.cpp.
00476 { 00477 Surface newSurf; 00478 00479 newSurf.SetSurface( SDL_DisplayFormat( surface ) ); 00480 00481 if( newSurf.IsNull() ) 00482 Error( "Unable to convert the surface to a surface compatible with the display format." ); 00483 00484 return newSurf; 00485 }
Here is the call graph for this function:
Here is the caller graph for this function:
Surface Surface::DisplayFormatAlpha | ( | ) |
Definition at line 462 of file surface.cpp.
00462 { 00463 Surface newSurf; 00464 00465 newSurf.SetSurface( SDL_DisplayFormatAlpha( surface ) ); 00466 00467 if( newSurf.IsNull() ) 00468 Error( "Unable to convert the surface to a surface compatible with the display format with alpha." ); 00469 00470 return newSurf; 00471 }
Here is the call graph for this function:
Here is the caller graph for this function:
int Surface::Fill | ( | const Color & | color | ) | const |
int Surface::Fill | ( | Uint32 | color | ) | const |
color |
Definition at line 398 of file surface.cpp.
Here is the caller graph for this function:
int Surface::FillRect | ( | const Rectanglei & | dstRect, | |
const Color & | color | |||
) | const |
dstRect | ||
color |
Definition at line 422 of file surface.cpp.
Here is the call graph for this function:
int Surface::FillRect | ( | const Rectanglei & | dstRect, | |
Uint32 | color | |||
) | const |
dstRect | ||
color |
Definition at line 411 of file surface.cpp.
00411 { 00412 SDL_Rect sdlDstRect = GetSDLRect( dstRect ); 00413 00414 return SDL_FillRect( surface, &sdlDstRect, color); 00415 }
Here is the call graph for this function:
Here is the caller graph for this function:
void Surface::Flip | ( | ) |
Definition at line 332 of file surface.cpp.
00332 { 00333 SDL_Flip( surface ); 00334 }
Here is the caller graph for this function:
void Surface::Free | ( | ) |
Free the memory occupied by the surface.
The memory is really freed if the reference counter reach 0.
Definition at line 114 of file surface.cpp.
00114 { 00115 if( !IsNull() ){ 00116 SDL_FreeSurface( surface ); 00117 surface = NULL; 00118 } 00119 }
Here is the call graph for this function:
Here is the caller graph for this function:
Uint8 Surface::GetBytesPerPixel | ( | ) | const [inline] |
Color Surface::GetColor | ( | Uint32 | color | ) | const |
Uint32 Surface::GetFlags | ( | ) | const [inline] |
int Surface::GetHeight | ( | ) | const [inline] |
Uint16 Surface::GetPitch | ( | ) | const [inline] |
Uint32 Surface::GetPixel | ( | int | x, | |
int | y | |||
) |
GetPixel.
From the SDL wiki.
x | ||
y |
Definition at line 495 of file surface.cpp.
00495 { 00496 int bpp = surface->format->BytesPerPixel; 00497 /* Here p is the address to the pixel we want to retrieve */ 00498 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; 00499 00500 switch(bpp) { 00501 case 1: 00502 return *p; 00503 00504 case 2: 00505 return *(Uint16 *)p; 00506 00507 case 3: 00508 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) 00509 return p[0] << 16 | p[1] << 8 | p[2]; 00510 else 00511 return p[0] | p[1] << 8 | p[2] << 16; 00512 00513 case 4: 00514 return *(Uint32 *)p; 00515 00516 default: 00517 Error("Unknow bpp!"); 00518 return 0; // To make gcc happy 00519 } 00520 }
unsigned char* Surface::GetPixels | ( | ) | const [inline] |
void Surface::GetRGBA | ( | Uint32 | color, | |
Uint8 & | r, | |||
Uint8 & | g, | |||
Uint8 & | b, | |||
Uint8 & | a | |||
) | const |
color | ||
r | ||
g | ||
b | ||
a |
Definition at line 288 of file surface.cpp.
Here is the caller graph for this function:
SDL_Rect Surface::GetSDLRect | ( | const Point2i & | r | ) | const [private] |
Definition at line 572 of file surface.cpp.
00573 { 00574 SDL_Rect sdlRect; 00575 00576 sdlRect.x = pt.GetX(); 00577 sdlRect.y = pt.GetY(); 00578 sdlRect.w = 0; 00579 sdlRect.h = 0; 00580 00581 return sdlRect; 00582 }
Here is the call graph for this function:
SDL_Rect Surface::GetSDLRect | ( | const Rectanglei & | r | ) | const [private] |
Definition at line 560 of file surface.cpp.
00561 { 00562 SDL_Rect sdlRect; 00563 00564 sdlRect.x = r.GetPositionX(); 00565 sdlRect.y = r.GetPositionY(); 00566 sdlRect.w = r.GetSizeX(); 00567 sdlRect.h = r.GetSizeY(); 00568 00569 return sdlRect; 00570 }
Here is the call graph for this function:
Here is the caller graph for this function:
Point2i Surface::GetSize | ( | ) | const [inline] |
SDL_Surface * Surface::GetSurface | ( | ) |
Return the pointer of the SDL_Surface.
Should be used carefully.
Definition at line 141 of file surface.cpp.
00141 { 00142 return surface; 00143 }
Here is the caller graph for this function:
int Surface::GetWidth | ( | ) | const [inline] |
int Surface::ImgLoad | ( | std::string | filename | ) |
filename |
Definition at line 431 of file surface.cpp.
00431 { 00432 AutoFree(); 00433 surface = IMG_Load( filename.c_str() ); 00434 00435 return !IsNull(); 00436 }
Here is the call graph for this function:
Here is the caller graph for this function:
bool Surface::IsNull | ( | ) | const [inline] |
int Surface::Lock | ( | ) |
Lock the surface to permit direct access.
Definition at line 208 of file surface.cpp.
00208 { 00209 return SDL_LockSurface( surface ); 00210 }
Here is the caller graph for this function:
Uint32 Surface::MapColor | ( | Color | color | ) | const |
Uint32 Surface::MapRGBA | ( | Uint8 | r, | |
Uint8 | g, | |||
Uint8 | b, | |||
Uint8 | a | |||
) | const |
r | ||
g | ||
b | ||
a |
Definition at line 299 of file surface.cpp.
Here is the caller graph for this function:
void Surface::NewSurface | ( | const Point2i & | size, | |
Uint32 | flags, | |||
bool | useAlpha = true | |||
) |
Create a new surface.
size | ||
flags | ||
useAlpha |
Definition at line 165 of file surface.cpp.
00165 { 00166 Uint32 alphaMask; 00167 Uint32 redMask; 00168 Uint32 greenMask; 00169 Uint32 blueMask; 00170 00171 if( autoFree ) 00172 Free(); 00173 00174 #if SDL_BYTEORDER == SDL_LIL_ENDIAN 00175 redMask = 0xff000000; 00176 greenMask = 0x00ff0000; 00177 blueMask = 0x0000ff00; 00178 alphaMask = 0x000000ff; 00179 #else 00180 redMask = 0x000000ff; 00181 greenMask = 0x0000ff00; 00182 blueMask = 0x00ff0000; 00183 alphaMask = 0xff000000; 00184 #endif 00185 00186 if( !useAlpha ) 00187 alphaMask = 0; 00188 00189 surface = SDL_CreateRGBSurface(flags, size.x, size.y, 32, 00190 redMask, greenMask, blueMask, alphaMask ); 00191 00192 if( surface == NULL ) 00193 Error( std::string("Can't create SDL RGBA surface: ") + SDL_GetError() ); 00194 }
Here is the call graph for this function:
Here is the caller graph for this function:
void Surface::PutPixel | ( | int | x, | |
int | y, | |||
Uint32 | pixel | |||
) |
x | ||
y | ||
pixel |
Definition at line 528 of file surface.cpp.
00528 { 00529 int bpp = surface->format->BytesPerPixel; 00530 /* Here p is the address to the pixel we want to set */ 00531 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; 00532 00533 switch(bpp) { 00534 case 1: 00535 *p = pixel; 00536 break; 00537 00538 case 2: 00539 *(Uint16 *)p = pixel; 00540 break; 00541 00542 case 3: 00543 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { 00544 p[0] = (pixel >> 16) & 0xff; 00545 p[1] = (pixel >> 8) & 0xff; 00546 p[2] = pixel & 0xff; 00547 } else { 00548 p[0] = pixel & 0xff; 00549 p[1] = (pixel >> 8) & 0xff; 00550 p[2] = (pixel >> 16) & 0xff; 00551 } 00552 break; 00553 00554 case 4: 00555 *(Uint32 *)p = pixel; 00556 break; 00557 } 00558 }
Here is the caller graph for this function:
int Surface::RectangleColor | ( | const Rectanglei & | rect, | |
const Color & | color, | |||
const uint & | border_size = 1 | |||
) |
Definition at line 345 of file surface.cpp.
00346 { 00347 if( rect.IsSizeZero() ) 00348 return 0; 00349 00350 Point2i ptBR = rect.GetBottomRightPoint(); 00351 00352 if (border_size == 1) 00353 return rectangleRGBA( surface, rect.GetPositionX(), rect.GetPositionY(), ptBR.GetX(), ptBR.GetY(), color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha() ); 00354 00355 // top border 00356 boxRGBA (surface, 00357 rect.GetPositionX(), rect.GetPositionY(), ptBR.GetX(), rect.GetPositionY()+border_size, 00358 color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha() ); 00359 00360 // bottom border 00361 boxRGBA (surface, 00362 rect.GetPositionX(), ptBR.GetY() - border_size, ptBR.GetX(), ptBR.GetY(), 00363 color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha() ); 00364 00365 // left border 00366 boxRGBA (surface, 00367 rect.GetPositionX(), rect.GetPositionY() + border_size, rect.GetPositionX()+border_size, ptBR.GetY()-border_size, 00368 color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha() ); 00369 00370 // right border 00371 boxRGBA (surface, 00372 ptBR.GetX() - border_size, rect.GetPositionY() + border_size, ptBR.GetX(), ptBR.GetY()-border_size, 00373 color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha() ); 00374 00375 return 1; 00376 }
Here is the call graph for this function:
Here is the caller graph for this function:
Surface Surface::RotoZoom | ( | double | angle, | |
double | zoomx, | |||
double | zoomy, | |||
int | smooth | |||
) |
Definition at line 448 of file surface.cpp.
00448 { 00449 Surface newSurf; 00450 00451 newSurf.SetSurface( rotozoomSurfaceXY(surface, angle * ratio_deg_to_rad , zoomx, zoomy, smooth) ); 00452 00453 if( newSurf.IsNull() ) 00454 Error( "Unable to make a rotozoom on the surface !" ); 00455 00456 return newSurf; 00457 }
Here is the call graph for this function:
Here is the caller graph for this function:
int Surface::SetAlpha | ( | Uint32 | flags, | |
Uint8 | alpha | |||
) |
Set the alpha value of a surface.
Definition at line 200 of file surface.cpp.
00200 { 00201 return SDL_SetAlpha( surface, flags, alpha ); 00202 }
Here is the caller graph for this function:
void Surface::SetAutoFree | ( | bool | newAutoFree | ) |
Set the auto free status of a surface.
In general it should always be true for non-system surface.
newAutoFree | the new autoFree status. |
Definition at line 132 of file surface.cpp.
00132 { 00133 autoFree = newAutoFree; 00134 }
Here is the caller graph for this function:
void Surface::SetClipRect | ( | const Rectanglei & | rect | ) |
rect |
Definition at line 327 of file surface.cpp.
00327 { 00328 SDL_Rect sdlRect = GetSDLRect( rect ); 00329 SDL_SetClipRect( surface, &sdlRect ); 00330 }
Here is the call graph for this function:
int Surface::SetColorKey | ( | Uint32 | flag, | |
Uint8 | r, | |||
Uint8 | g, | |||
Uint8 | b, | |||
Uint8 | a | |||
) |
flag | ||
r | ||
g | ||
b | ||
a |
Definition at line 277 of file surface.cpp.
00277 { 00278 return SetColorKey( flag, MapRGBA(r, g, b, a) ); 00279 }
Here is the call graph for this function:
int Surface::SetColorKey | ( | Uint32 | flag, | |
Uint32 | key | |||
) |
flag | ||
key |
Definition at line 264 of file surface.cpp.
00264 { 00265 return SDL_SetColorKey( surface, flag, key ); 00266 }
Here is the caller graph for this function:
void Surface::SetSurface | ( | SDL_Surface * | newSurface, | |
bool | freePrevious = true | |||
) |
Change the surface pointer.
newSurface | The new surface to use. | |
freePrevius | Indicate if the old surface should be freed. |
Definition at line 151 of file surface.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:
void Surface::Unlock | ( | ) |
Unlock the surface.
Definition at line 216 of file surface.cpp.
00216 { 00217 SDL_UnlockSurface( surface ); 00218 }
Here is the caller graph for this function:
bool Surface::autoFree [private] |
SDL_Surface* Surface::surface [private] |