]> git.localhorst.tv Git - l2e.git/blobdiff - src/graphics/Frame.cpp
added type description of Frame
[l2e.git] / src / graphics / Frame.cpp
index 1c51c454cad056f9a56f9734e0f490426e2860d4..34767f53f0cd170185723e2a0806f4cd87ab14bf 100644 (file)
 
 #include "Frame.h"
 
+#include "../loader/TypeDescription.h"
+
 using geometry::Vector;
+using loader::FieldDescription;
+using loader::TypeDescription;
 
 namespace graphics {
 
 // TODO: maybe create a cache for frames?
 void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int height) const {
+       if (!surface) {
+               SDL_Rect rect;
+               rect.x = position.X();
+               rect.y = position.Y();
+               rect.w = width;
+               rect.h = height;
+               SDL_FillRect(dest, &rect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+               return;
+       }
        // top-left corner
        SDL_Rect srcRect;
-       srcRect.x = xOffset;
-       srcRect.y = yOffset;
-       srcRect.w = borderWidth;
-       srcRect.h = borderHeight;
+       srcRect.x = offset.X();
+       srcRect.y = offset.Y();
+       srcRect.w = BorderWidth();
+       srcRect.h = BorderHeight();
        SDL_Rect destRect;
        destRect.x = position.X();
        destRect.y = position.Y();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
        // top border
-       srcRect.x += borderWidth;
-       srcRect.w = repeatWidth;
-       destRect.x += borderWidth;
-       int fullRepeatWidth(width - (2 * borderWidth));
+       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;
+               destRect.x += RepeatWidth();
+               repeatCursor += RepeatWidth();
        }
 
        // top-right corner
-       srcRect.x += repeatWidth;
-       srcRect.w = borderWidth;
+       srcRect.x += RepeatWidth();
+       srcRect.w = BorderWidth();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
        // middle
-       destRect.y += borderHeight;
-       int fullRepeatHeight(height - (2 * borderHeight));
+       destRect.y += BorderHeight();
+       int fullRepeatHeight(height - (2 * BorderHeight()));
        int hRepeatCursor(0);
        while (hRepeatCursor < fullRepeatHeight) {
 
                // left border
-               srcRect.x = xOffset;
-               srcRect.y = yOffset + borderHeight;
-               srcRect.w = borderWidth;
-               srcRect.h = repeatHeight;
+               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;
+               srcRect.x += BorderWidth();
+               srcRect.w = RepeatWidth();
+               destRect.x += BorderWidth();
                while (repeatCursor < fullRepeatWidth) {
                        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-                       destRect.x += repeatWidth;
-                       repeatCursor += repeatWidth;
+                       destRect.x += RepeatWidth();
+                       repeatCursor += RepeatWidth();
                }
 
                // right border
-               srcRect.x += repeatWidth;
-               srcRect.w = borderWidth;
+               srcRect.x += RepeatWidth();
+               srcRect.w = BorderWidth();
                SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
-               destRect.y += repeatHeight;
-               hRepeatCursor += repeatHeight;
+               destRect.y += RepeatHeight();
+               hRepeatCursor += RepeatHeight();
        }
 
        // bottom-left corner
-       srcRect.x = xOffset;
-       srcRect.y = yOffset + borderHeight + repeatHeight;
-       srcRect.w = borderWidth;
-       srcRect.h = borderHeight;
+       srcRect.x = offset.X();
+       srcRect.y = offset.Y() + BorderHeight() + RepeatHeight();
+       srcRect.w = BorderWidth();
+       srcRect.h = BorderHeight();
        destRect.x = position.X();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
        // bottom border
-       srcRect.x += borderWidth;
-       srcRect.w = repeatWidth;
-       destRect.x += borderWidth;
+       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;
+               destRect.x += RepeatWidth();
+               repeatCursor += RepeatWidth();
        }
        if (fullRepeatWidth < fullRepeatWidth) {
                srcRect.w = fullRepeatWidth - fullRepeatWidth;
@@ -100,9 +113,25 @@ void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int
        }
 
        // bottom-right corner
-       srcRect.x += repeatWidth;
-       srcRect.w = borderWidth;
+       srcRect.x += RepeatWidth();
+       srcRect.w = BorderWidth();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 }
 
+
+void Frame::CreateTypeDescription() {
+       Frame f;
+       TypeDescription &td(TypeDescription::CreateOrGet("Frame"));
+
+       td.SetSize(sizeof(Frame));
+
+       int imageId(TypeDescription::GetTypeId("Image"));
+       int vectorId(TypeDescription::GetTypeId("Vector"));
+
+       td.AddField("surface", FieldDescription(((char *)&f.surface) - ((char *)&f), imageId, true));
+       td.AddField("borderSize", FieldDescription(((char *)&f.borderSize) - ((char *)&f), vectorId, false));
+       td.AddField("repeatSize", FieldDescription(((char *)&f.repeatSize) - ((char *)&f), vectorId, false));
+       td.AddField("offset", FieldDescription(((char *)&f.offset) - ((char *)&f), vectorId, false));
+}
+
 }