3 #include "../loader/Interpreter.h"
4 #include "../loader/TypeDescription.h"
7 using loader::FieldDescription;
8 using loader::Interpreter;
9 using loader::TypeDescription;
13 void Sprite::Draw(SDL_Surface *dest, const Vector<int> &position, int col, int row) const {
14 SDL_Rect srcRect, destRect;
15 srcRect.x = offset.X() + col * Width();
16 srcRect.y = offset.Y() + row * Height();
19 destRect.x = position.X();
20 destRect.y = position.Y();
22 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
25 destRect.h = Height();
27 while (destRect.w > 1 && destRect.h > 1) {
28 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, red ? 0xFF : 0, 0, 0));
39 void Sprite::CreateTypeDescription() {
42 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Sprite"));
44 "An image + a size and offset.\n"
45 "The resulting section or a section offset by a multiple of its size can be drawn.");
46 td.SetConstructor(&Construct);
47 td.SetSize(sizeof(Sprite));
49 td.AddField("image", FieldDescription(((char *)&s.surface) - ((char *)&s), Interpreter::IMAGE_ID).SetReferenced().SetDescription("the image to cut this sprite from"));
50 td.AddField("size", FieldDescription(((char *)&s.size) - ((char *)&s), Interpreter::VECTOR_ID).SetDescription("dimensions of the sprite"));
51 td.AddField("offset", FieldDescription(((char *)&s.offset) - ((char *)&s), Interpreter::VECTOR_ID).SetDescription("offset into the image, top-left corner of the sprite's (0,0) clip"));
54 void Sprite::Construct(void *data) {