3 #include "../loader/Interpreter.h"
4 #include "../loader/TypeDescription.h"
5 #include "../sdl/utility.h"
8 using loader::FieldDescription;
9 using loader::Interpreter;
10 using loader::TypeDescription;
16 const Vector<int> &size,
17 const Vector<int> &offset)
29 void Texture::Render(SDL_Surface *dest, const Vector<int> &from, const Vector<int> &to) const {
31 destRect.x = from.X();
32 destRect.y = from.Y();
33 if (!surface || size == Vector<int>()) {
34 destRect.w = to.X() - from.X();
35 destRect.h = to.Y() - from.Y();
36 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
41 srcRect.x = offset.X();
42 srcRect.y = offset.Y();
44 for (destRect.y = from.Y(); destRect.y < to.Y(); destRect.y += size.Y()) {
46 destRect.h = size.Y();
47 if (destRect.y + destRect.h > to.Y()) {
48 srcRect.h = to.Y() - destRect.y;
49 destRect.h = to.Y() - destRect.y;
51 for (destRect.x = from.X(); destRect.x < to.X(); destRect.x += size.X()) {
53 destRect.w = size.X();
54 if (destRect.x + destRect.w > to.X()) {
55 srcRect.w = to.X() - destRect.x;
56 destRect.w = to.X() - destRect.x;
58 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
64 void Texture::CreateTypeDescription() {
67 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Texture"));
68 td.SetConstructor(&Construct);
69 td.SetSize(sizeof(Texture));
71 td.AddField("image", FieldDescription(((char *)&t.surface) - ((char *)&t), Interpreter::IMAGE_ID).SetReferenced().SetDescription("image containing the texture"));
72 td.AddField("size", FieldDescription(((char *)&t.size) - ((char *)&t), Interpreter::VECTOR_ID).SetDescription("offset into the image in pixels"));
73 td.AddField("offset", FieldDescription(((char *)&t.offset) - ((char *)&t), Interpreter::VECTOR_ID).SetDescription("size of the texture in pixels"));
76 void Texture::Construct(void *data) {