X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FTexture.cpp;h=9c49db4060ba32aa4d9728e69a164bf5676d850c;hb=f6548c2aabfb371bd81382d7800e6e2cdb826e06;hp=2bb0e97f2113529421bcd5ee6ac3b1c0f2b3fabc;hpb=350055a7ff27c74882aff8a4d6af2014782f830b;p=l2e.git diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index 2bb0e97..9c49db4 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -1,15 +1,13 @@ -/* - * Texture.cpp - * - * Created on: Oct 21, 2012 - * Author: holy - */ - #include "Texture.h" +#include "../loader/Interpreter.h" +#include "../loader/TypeDescription.h" #include "../sdl/utility.h" -using geometry::Vector; +using math::Vector; +using loader::FieldDescription; +using loader::Interpreter; +using loader::TypeDescription; namespace graphics { @@ -28,7 +26,7 @@ Texture::~Texture() { } -void Texture::Render(SDL_Surface *dest, const Vector &from, const Vector &to) const { +void Texture::Draw(SDL_Surface *dest, const Vector &from, const Vector &to) const { SDL_Rect destRect; destRect.x = from.X(); destRect.y = from.Y(); @@ -42,24 +40,58 @@ void Texture::Render(SDL_Surface *dest, const Vector &from, const Vector total = to - from; + const Vector over = total % size; + const Vector target = from + (total - over); - for (destRect.y = from.Y(); destRect.y < to.Y(); destRect.y += size.Y()) { + for (destRect.y = from.Y(); destRect.y < target.Y(); destRect.y += size.Y()) { + for (destRect.x = from.X(); destRect.x < target.X(); destRect.x += size.X()) { + SDL_BlitSurface(surface, &srcRect, dest, &destRect); + } + } + if (over.X() > 0) { + destRect.x = target.X(); + srcRect.w = over.X(); srcRect.h = size.Y(); - destRect.h = size.Y(); - if (destRect.y + destRect.h > to.Y()) { - srcRect.h = to.Y() - destRect.y; - destRect.h = to.Y() - destRect.y; + for (destRect.y = from.Y(); destRect.y < target.Y(); destRect.y += size.Y()) { + SDL_BlitSurface(surface, &srcRect, dest, &destRect); + } + } + if (over.Y() > 0) { + destRect.y = target.Y(); + srcRect.w = size.X(); + srcRect.h = over.Y(); + for (destRect.x = from.X(); destRect.x < target.X(); destRect.x += size.X()) { + SDL_BlitSurface(surface, &srcRect, dest, &destRect); } - for (destRect.x = from.X(); destRect.x < to.X(); destRect.x += size.X()) { - srcRect.w = size.X(); - destRect.w = size.X(); - if (destRect.x + destRect.w > to.X()) { - srcRect.w = to.X() - destRect.x; - destRect.w = to.X() - destRect.x; - } + if (over.X() > 0) { + srcRect.w = over.X(); + srcRect.h = over.Y(); + destRect.x = target.X(); + destRect.y = target.Y(); SDL_BlitSurface(surface, &srcRect, dest, &destRect); } } } + +void Texture::CreateTypeDescription() { + Texture t; + + TypeDescription &td(TypeDescription::Create(TYPE_ID, "Texture")); + td.SetConstructor(&Construct); + td.SetSize(sizeof(Texture)); + + td.AddField("image", FieldDescription(((char *)&t.surface) - ((char *)&t), Interpreter::IMAGE_ID).SetReferenced().SetDescription("image containing the texture")); + td.AddField("size", FieldDescription(((char *)&t.size) - ((char *)&t), Interpreter::VECTOR_ID).SetDescription("offset into the image in pixels")); + td.AddField("offset", FieldDescription(((char *)&t.offset) - ((char *)&t), Interpreter::VECTOR_ID).SetDescription("size of the texture in pixels")); +} + +void Texture::Construct(void *data) { + new (data) Texture; +} + }