]> git.localhorst.tv Git - l2e.git/blobdiff - src/graphics/Texture.cpp
consistent naming of graphics drawing functions
[l2e.git] / src / graphics / Texture.cpp
index f53c82fd7030f6219332e5368ae1d435b4a4481e..9c49db4060ba32aa4d9728e69a164bf5676d850c 100644 (file)
@@ -4,7 +4,7 @@
 #include "../loader/TypeDescription.h"
 #include "../sdl/utility.h"
 
-using geometry::Vector;
+using math::Vector;
 using loader::FieldDescription;
 using loader::Interpreter;
 using loader::TypeDescription;
@@ -26,7 +26,7 @@ Texture::~Texture() {
 }
 
 
-void Texture::Render(SDL_Surface *dest, const Vector<int> &from, const Vector<int> &to) const {
+void Texture::Draw(SDL_Surface *dest, const Vector<int> &from, const Vector<int> &to) const {
        SDL_Rect destRect;
        destRect.x = from.X();
        destRect.y = from.Y();
@@ -40,21 +40,38 @@ void Texture::Render(SDL_Surface *dest, const Vector<int> &from, const Vector<in
        SDL_Rect srcRect;
        srcRect.x = offset.X();
        srcRect.y = offset.Y();
+       srcRect.h = size.Y();
+       srcRect.w = size.X();
 
-       for (destRect.y = from.Y(); destRect.y < to.Y(); destRect.y += size.Y()) {
+       const Vector<int> total = to - from;
+       const Vector<int> over = total % size;
+       const Vector<int> target = from + (total - over);
+
+       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);
                }
        }