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();
46 const Vector<int> total = to - from;
47 const Vector<int> over = total % size;
48 const Vector<int> target = from + (total - over);
50 for (destRect.y = from.Y(); destRect.y < target.Y(); destRect.y += size.Y()) {
51 for (destRect.x = from.X(); destRect.x < target.X(); destRect.x += size.X()) {
52 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
56 destRect.x = target.X();
59 for (destRect.y = from.Y(); destRect.y < target.Y(); destRect.y += size.Y()) {
60 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
64 destRect.y = target.Y();
67 for (destRect.x = from.X(); destRect.x < target.X(); destRect.x += size.X()) {
68 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
73 destRect.x = target.X();
74 destRect.y = target.Y();
75 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
81 void Texture::CreateTypeDescription() {
84 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Texture"));
85 td.SetConstructor(&Construct);
86 td.SetSize(sizeof(Texture));
88 td.AddField("image", FieldDescription(((char *)&t.surface) - ((char *)&t), Interpreter::IMAGE_ID).SetReferenced().SetDescription("image containing the texture"));
89 td.AddField("size", FieldDescription(((char *)&t.size) - ((char *)&t), Interpreter::VECTOR_ID).SetDescription("offset into the image in pixels"));
90 td.AddField("offset", FieldDescription(((char *)&t.offset) - ((char *)&t), Interpreter::VECTOR_ID).SetDescription("size of the texture in pixels"));
93 void Texture::Construct(void *data) {