Fundamental framework for an SDL application

This commit is contained in:
2011-06-22 16:12:22 -04:00
commit 27c6f1e0b6
7 changed files with 359 additions and 0 deletions

51
drawutils.cpp Normal file
View File

@ -0,0 +1,51 @@
#include "drawutils.h"
SDL_Surface* DrawUtils::load(string file)
{
SDL_Surface* raw = NULL;
SDL_Surface* cooked = NULL;
raw = SDL_LoadBMP(file.c_str());
if (raw == NULL) return NULL;
cooked = SDL_DisplayFormat(raw);
SDL_FreeSurface(raw); // don't consume raw surfaces
return cooked;
}
bool DrawUtils::draw(SDL_Surface* dest, SDL_Surface* drawable, int x, int y)
{
if (dest == NULL || drawable == NULL) return false;
SDL_Rect dest_r;
dest_r.x = x;
dest_r.y = y;
SDL_BlitSurface(drawable, NULL, dest, &dest_r);
return true;
}
bool DrawUtils::draw(SDL_Surface* dest, SDL_Surface* drawable, int x, int y,
int x2, int y2, int w, int h)
{
SDL_Rect dest_r;
dest_r.x = x;
dest_r.y = y;
SDL_Rect src_r;
src_r.x = x2;
src_r.y = y2;
src_r.w = w;
src_r.h = h;
SDL_BlitSurface(drawable, &src_r, dest, &dest_r);
return true;
}