Initial commit. Not even a game yet :P
[cToan.git] / src / SDLWrap_Surface.cpp
blob93b9f5c7f4c6b4958494b1a9abb4d7eac8bf9a95
1 #include "SDLWrap_Surface.hpp"
2 #include <iostream>
3 namespace SDLWrap {
5 Surface::Surface(const std::string BMPFilePath)
6 try {
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");
23 Surface::~Surface()
25 SDL_FreeSurface(this->me);
28 bool
29 Surface::Blit(const Surface &Destination)
31 return ( RealBlit(Destination, NULL, NULL) == 0 );
34 bool
35 Surface::Blit(const Surface &Destination, int DestXOffset, int DestYOffset)
37 SDL_Rect OffsetRect;
38 OffsetRect.x = DestXOffset;
39 OffsetRect.y = DestYOffset;
40 return ( RealBlit(Destination, NULL, &OffsetRect) == 0 );
43 bool
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&#3368336
52 continue;
55 return 0;