X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FFrame.cpp;h=34767f53f0cd170185723e2a0806f4cd87ab14bf;hb=76ebf3fdefce0655ecd2404e735e8fd96347d934;hp=c682fa0f97ca7de495b04914b2c84c03d8c34fc9;hpb=1162be37102b24df11f469495c0184f3f9a26ba0;p=l2e.git diff --git a/src/graphics/Frame.cpp b/src/graphics/Frame.cpp index c682fa0..34767f5 100644 --- a/src/graphics/Frame.cpp +++ b/src/graphics/Frame.cpp @@ -7,91 +7,104 @@ #include "Frame.h" -using geometry::Point; +#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 Point &position, int width, int height) const { +void Frame::Draw(SDL_Surface *dest, const Vector &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 Point &position, int width, int h } // 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)); +} + }