4 * Created on: Aug 5, 2012
10 #include "../loader/TypeDescription.h"
12 using geometry::Vector;
13 using loader::FieldDescription;
14 using loader::TypeDescription;
18 void Sprite::Draw(SDL_Surface *dest, const Vector<int> &position, int col, int row) const {
19 SDL_Rect srcRect, destRect;
20 srcRect.x = offset.X() + col * Width();
21 srcRect.y = offset.Y() + row * Height();
24 destRect.x = position.X();
25 destRect.y = position.Y();
27 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
30 destRect.h = Height();
32 while (destRect.w > 1 && destRect.h > 1) {
33 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, red ? 0xFF : 0, 0, 0));
44 void Sprite::CreateTypeDescription() {
47 int imageId(TypeDescription::GetTypeId("Image"));
48 int vectorId(TypeDescription::GetTypeId("Vector"));
50 TypeDescription &td(TypeDescription::CreateOrGet("Sprite"));
51 td.SetSize(sizeof(Sprite));
53 td.AddField("image", FieldDescription(((char *)&s.surface) - ((char *)&s), imageId, true));
54 td.AddField("size", FieldDescription(((char *)&s.size) - ((char *)&s), vectorId, false));
55 td.AddField("offset", FieldDescription(((char *)&s.offset) - ((char *)&s), vectorId, false));