treewars/drawutils.cpp

52 lines
930 B
C++
Raw Normal View History

#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;
}