]> git.localhorst.tv Git - l2e.git/blobdiff - src/graphics/Frame.cpp
changed Frame implementation
[l2e.git] / src / graphics / Frame.cpp
index 46fa1b59db7c799255c282f90e9fe92c654a509d..86b9cd25d5d7b5d06c0213aea81ef303db945b96 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "Frame.h"
 
+#include "Texture.h"
 #include "../loader/Interpreter.h"
 #include "../loader/TypeDescription.h"
 
@@ -40,55 +41,26 @@ void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
        // top border
-       srcRect.x += BorderWidth();
-       srcRect.w = RepeatWidth();
-       destRect.x += BorderWidth();
-       int fullRepeatWidth(width - (2 * BorderWidth()));
-       int repeatCursor(0);
-       while (repeatCursor < fullRepeatWidth) {
-               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-               destRect.x += RepeatWidth();
-               repeatCursor += RepeatWidth();
-       }
+       Texture(surface, Vector<int>(RepeatWidth(), BorderHeight()), Vector<int>(offset.X() + BorderWidth(), offset.Y()))
+       .Render(dest, Vector<int>(position.X() + BorderWidth(), position.Y()), Vector<int>(position.X() + width - BorderWidth(), position.Y() + BorderHeight()));
 
        // top-right corner
-       srcRect.x += RepeatWidth();
+       srcRect.x = offset.X() + RepeatWidth() + BorderWidth();
        srcRect.w = BorderWidth();
+       destRect.x = position.X() + width - BorderWidth();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
-       // middle
-       destRect.y += BorderHeight();
-       int fullRepeatHeight(height - (2 * BorderHeight()));
-       int hRepeatCursor(0);
-       while (hRepeatCursor < fullRepeatHeight) {
-
-               // left border
-               srcRect.x = offset.X();
-               srcRect.y = offset.Y() + BorderHeight();
-               srcRect.w = BorderWidth();
-               srcRect.h = RepeatHeight();
-               destRect.x = position.X();
-               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-
-               // fill
-               repeatCursor = 0;
-               srcRect.x += BorderWidth();
-               srcRect.w = RepeatWidth();
-               destRect.x += BorderWidth();
-               while (repeatCursor < fullRepeatWidth) {
-                       SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-                       destRect.x += RepeatWidth();
-                       repeatCursor += RepeatWidth();
-               }
-
-               // right border
-               srcRect.x += RepeatWidth();
-               srcRect.w = BorderWidth();
-               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-
-               destRect.y += RepeatHeight();
-               hRepeatCursor += RepeatHeight();
-       }
+       // left border
+       Texture(surface, Vector<int>(BorderWidth(), RepeatHeight()), Vector<int>(offset.X(), offset.Y() + BorderHeight()))
+       .Render(dest, Vector<int>(position.X(), position.Y() + BorderHeight()), Vector<int>(position.X() + BorderWidth(), position.Y() + height - BorderHeight()));
+
+       // center fill
+       Texture(surface, RepeatSize(), Vector<int>(offset.X() + BorderWidth(), offset.Y() + BorderHeight()))
+       .Render(dest, position + BorderSize(), position + Vector<int>(width, height) - BorderSize());
+
+       // right border
+       Texture(surface, Vector<int>(BorderWidth(), RepeatHeight()), Vector<int>(offset.X() + BorderWidth() + RepeatWidth(), offset.Y() + BorderHeight()))
+       .Render(dest, Vector<int>(position.X() + width - BorderWidth(), position.Y() + BorderHeight()), Vector<int>(position.X() + width, position.Y() + height - BorderHeight()));
 
        // bottom-left corner
        srcRect.x = offset.X();
@@ -96,27 +68,17 @@ void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int
        srcRect.w = BorderWidth();
        srcRect.h = BorderHeight();
        destRect.x = position.X();
+       destRect.y = position.Y() + height - BorderHeight();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
        // bottom border
-       srcRect.x += BorderWidth();
-       srcRect.w = RepeatWidth();
-       destRect.x += BorderWidth();
-       repeatCursor = 0;
-       while (repeatCursor < fullRepeatWidth) {
-               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-               destRect.x += RepeatWidth();
-               repeatCursor += RepeatWidth();
-       }
-       if (fullRepeatWidth < fullRepeatWidth) {
-               srcRect.w = fullRepeatWidth - fullRepeatWidth;
-               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-               destRect.x += fullRepeatWidth - fullRepeatWidth;
-       }
+       Texture(surface, Vector<int>(RepeatWidth(), BorderHeight()), Vector<int>(offset.X() + BorderWidth(), offset.Y() + BorderHeight() + RepeatHeight()))
+       .Render(dest, Vector<int>(position.X() + BorderWidth(), position.Y() + height - BorderHeight()), Vector<int>(position.X() + width - BorderWidth(), position.Y() + height));
 
        // bottom-right corner
-       srcRect.x += RepeatWidth();
+       srcRect.x = offset.X() + BorderWidth() + RepeatWidth();
        srcRect.w = BorderWidth();
+       destRect.x = position.X() + width - BorderWidth();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 }