1 #include "SDLWrap_Surface.hpp"
5 Surface::Surface(const std::string BMPFilePath
)
7 SDL_Surface
*tmpSurface
= NULL
;
8 if ( (tmpSurface
= SDL_LoadBMP(BMPFilePath
.c_str())) == NULL
)
9 throw SurfaceCreationError();
11 if ( (this->me
= SDL_DisplayFormat(tmpSurface
)) == NULL
)
12 throw SurfaceCreationError();
14 SDL_FreeSurface(tmpSurface
);
16 this->FilePath
= BMPFilePath
;
18 catch (SurfaceCreationError
)
20 ErrorHandler::OutputError(ErrorHandler::FATAL_CONSTRUCTOR_ERROR
, "Surface::Surface(char*) constructor threw a SurfaceCreationError.\n");
25 SDL_FreeSurface(this->me
);
29 Surface::Blit(const Surface
&Destination
)
31 return ( RealBlit(Destination
, NULL
, NULL
) == 0 );
35 Surface::Blit(const Surface
&Destination
, int DestXOffset
, int DestYOffset
)
38 OffsetRect
.x
= DestXOffset
;
39 OffsetRect
.y
= DestYOffset
;
40 return ( RealBlit(Destination
, NULL
, &OffsetRect
) == 0 );
44 Surface::RealBlit(const Surface
&Destination
, SDL_Rect
*SourceRect
, SDL_Rect
*DestRect
)
46 while ( SDL_BlitSurface(this->me
, SourceRect
, Destination
.me
, DestRect
) == -2 ) {
47 /* Reload the image and reblit. Too lazy to implement now but the SDL docs have something on it and so does a
48 * very good post by rip-off on GameDev.
49 * http://sdl.beuc.net/sdl.wiki/SDL_BlitSurface
50 * http://www.gamedev.net/community/forums/topic.asp?topic_id=518486&whichpage=1�