X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FFrame.cpp;h=46fa1b59db7c799255c282f90e9fe92c654a509d;hb=57a75f13e98f4b5d311c2d3b9d9ff637120c5ee2;hp=a152ee76c8efa152825dc514938e100df97c3736;hpb=d20fa78a0dcbc95a69bb6077d2081d42b74a2d1a;p=l2e.git diff --git a/src/graphics/Frame.cpp b/src/graphics/Frame.cpp index a152ee7..46fa1b5 100644 --- a/src/graphics/Frame.cpp +++ b/src/graphics/Frame.cpp @@ -7,12 +7,27 @@ #include "Frame.h" +#include "../loader/Interpreter.h" +#include "../loader/TypeDescription.h" + using geometry::Vector; +using loader::FieldDescription; +using loader::Interpreter; +using loader::TypeDescription; namespace graphics { // TODO: maybe create a cache for frames? 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 = offset.X(); @@ -105,4 +120,25 @@ void Frame::Draw(SDL_Surface *dest, const Vector &position, int width, int SDL_BlitSurface(surface, &srcRect, dest, &destRect); } + +void Frame::CreateTypeDescription() { + Frame f; + + TypeDescription &td(TypeDescription::Create(TYPE_ID, "Frame")); + td.SetDescription( + "A frame is basically a border + a background texture.\n" + "It splits an image into 3*3 parts where the edges are kept as is and the sides and the middle part are repeated as needed."); + td.SetConstructor(&Construct); + td.SetSize(sizeof(Frame)); + + td.AddField("image", FieldDescription(((char *)&f.surface) - ((char *)&f), Interpreter::IMAGE_ID).SetReferenced().SetDescription("the underlying graphic from which the frame parts are cut")); + td.AddField("border", FieldDescription(((char *)&f.borderSize) - ((char *)&f), Interpreter::VECTOR_ID).SetDescription("size of the border part, dimensions of top-left corner")); + td.AddField("repeat", FieldDescription(((char *)&f.repeatSize) - ((char *)&f), Interpreter::VECTOR_ID).SetDescription("size of the repeat part, dimensions of a single tile of the background texture")); + td.AddField("offset", FieldDescription(((char *)&f.offset) - ((char *)&f), Interpreter::VECTOR_ID).SetDescription("offset into the image where to start cutting, coordinates of the top-left corner on the image")); +} + +void Frame::Construct(void *data) { + new (data) Frame; +} + }