drawSurface.cpp

00001 /*
00002   サーフェスの描画クラス
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "drawSurface.h"
00008 
00009 
00010 DrawSurface::DrawSurface(void) : surface(NULL) {
00011 }
00012 
00013 
00014 DrawSurface::DrawSurface(const char* bmpFile, bool transparent) {
00015   load(bmpFile, transparent);
00016 }
00017 
00018 
00019 DrawSurface::DrawSurface(SDL_Surface* sdlSurface, bool transparent) {
00020   load(sdlSurface, transparent);
00021 }
00022 
00023 
00024 DrawSurface::~DrawSurface(void) {
00025   if (surface) {
00026     SDL_FreeSurface(surface);
00027   }
00028 }
00029 
00030 
00031 bool DrawSurface::draw(const VXV::Rect& size, const VXV::Grid& pos,
00032                        unsigned long ticks) {
00033   if (!surface) {
00034     return false;
00035   } else {
00036 
00037     SDL_Video::blitSurface(surface, size, pos);
00038     return true;
00039   }
00040 }
00041 
00042 
00043 void DrawSurface::setSize(void) {
00044   if (surface) {
00045     w = surface->w;
00046     h = surface->h;
00047   } else {
00048     w = 0;
00049     h = 0;
00050   }
00051 }
00052 
00053 
00054 SDL_Surface* DrawSurface::surfaceTransparent(SDL_Surface* sdlSurface) {
00055   if (surface->format->palette) {
00056     SDL_SetColorKey(surface, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
00057                     *(Uint8 *)surface->pixels);
00058   }
00059   SDL_Surface *temp = SDL_DisplayFormat(surface);
00060   SDL_FreeSurface(surface);
00061 
00062   return temp;
00063 }
00064 
00065 
00066 void DrawSurface::load(const char* bmpFile, bool transparent) {
00067   surface = SDL_LoadBMP(bmpFile);
00068   if (!surface) {
00069     throw SDL_Exception();
00070   }
00071   if (transparent) {
00072     surface = surfaceTransparent(surface);
00073   }
00074   setSize();
00075 }
00076 
00077 
00078 void DrawSurface::load(SDL_Surface* sdlSurface, bool transparent) {
00079   surface = sdlSurface;
00080   if (transparent) {
00081     surface = surfaceTransparent(sdlSurface);
00082   }
00083   setSize();
00084 }
00085 

Generated on Mon Apr 13 22:52:02 2009 by  doxygen 1.5.7.1