4 * Created on: Aug 5, 2012
10 #include "../loader/Interpreter.h"
11 #include "../loader/TypeDescription.h"
13 using geometry::Vector;
14 using loader::FieldDescription;
15 using loader::Interpreter;
16 using loader::TypeDescription;
20 void Sprite::Draw(SDL_Surface *dest, const Vector<int> &position, int col, int row) const {
21 SDL_Rect srcRect, destRect;
22 srcRect.x = offset.X() + col * Width();
23 srcRect.y = offset.Y() + row * Height();
26 destRect.x = position.X();
27 destRect.y = position.Y();
29 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
32 destRect.h = Height();
34 while (destRect.w > 1 && destRect.h > 1) {
35 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, red ? 0xFF : 0, 0, 0));
46 void Sprite::CreateTypeDescription() {
49 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Sprite"));
51 "An image + a size and offset.\n"
52 "The resulting section or a section offset by a multiple of its size can be drawn.");
53 td.SetConstructor(&Construct);
54 td.SetSize(sizeof(Sprite));
56 td.AddField("image", FieldDescription(((char *)&s.surface) - ((char *)&s), Interpreter::IMAGE_ID).SetReferenced().SetDescription("the image to cut this sprite from"));
57 td.AddField("size", FieldDescription(((char *)&s.size) - ((char *)&s), Interpreter::VECTOR_ID).SetDescription("dimensions of the sprite"));
58 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"));
61 void Sprite::Construct(void *data) {