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"));
52 "An image + a size and offset.\n"
53 "The resulting section or a section offset by a multiple of its size can be drawn.");
54 td.SetConstructor(&Construct);
55 td.SetSize(sizeof(Sprite));
57 td.AddField("image", FieldDescription(((char *)&s.surface) - ((char *)&s), imageId).SetReferenced().SetDescription("the image to cut this sprite from"));
58 td.AddField("size", FieldDescription(((char *)&s.size) - ((char *)&s), vectorId).SetDescription("dimensions of the sprite"));
59 td.AddField("offset", FieldDescription(((char *)&s.offset) - ((char *)&s), vectorId).SetDescription("offset into the image, top-left corner of the sprite's (0,0) clip"));
62 void Sprite::Construct(void *data) {