X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FFrame.cpp;h=dbfd814067c95668860d6e34107684a06636e748;hb=cc3d698b8c1ad09d7a3f9e3f28bc84e0ac1735ea;hp=01264e8321921e4f2c55d0e14611c1547a9070fe;hpb=4bc70f5311dcbcca4e6b9e852bbcb19602f50eeb;p=l2e.git diff --git a/src/graphics/Frame.cpp b/src/graphics/Frame.cpp index 01264e8..dbfd814 100644 --- a/src/graphics/Frame.cpp +++ b/src/graphics/Frame.cpp @@ -1,16 +1,12 @@ -/* - * Frame.cpp - * - * Created on: Aug 7, 2012 - * Author: holy - */ - #include "Frame.h" +#include "Texture.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" using geometry::Vector; using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace graphics { @@ -38,55 +34,26 @@ void Frame::Draw(SDL_Surface *dest, const Vector &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(RepeatWidth(), BorderHeight()), Vector(offset.X() + BorderWidth(), offset.Y())) + .Render(dest, Vector(position.X() + BorderWidth(), position.Y()), Vector(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(BorderWidth(), RepeatHeight()), Vector(offset.X(), offset.Y() + BorderHeight())) + .Render(dest, Vector(position.X(), position.Y() + BorderHeight()), Vector(position.X() + BorderWidth(), position.Y() + height - BorderHeight())); + + // center fill + Texture(surface, RepeatSize(), Vector(offset.X() + BorderWidth(), offset.Y() + BorderHeight())) + .Render(dest, position + BorderSize(), position + Vector(width, height) - BorderSize()); + + // right border + Texture(surface, Vector(BorderWidth(), RepeatHeight()), Vector(offset.X() + BorderWidth() + RepeatWidth(), offset.Y() + BorderHeight())) + .Render(dest, Vector(position.X() + width - BorderWidth(), position.Y() + BorderHeight()), Vector(position.X() + width, position.Y() + height - BorderHeight())); // bottom-left corner srcRect.x = offset.X(); @@ -94,27 +61,17 @@ void Frame::Draw(SDL_Surface *dest, const Vector &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(RepeatWidth(), BorderHeight()), Vector(offset.X() + BorderWidth(), offset.Y() + BorderHeight() + RepeatHeight())) + .Render(dest, Vector(position.X() + BorderWidth(), position.Y() + height - BorderHeight()), Vector(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); } @@ -122,20 +79,17 @@ void Frame::Draw(SDL_Surface *dest, const Vector &position, int width, int void Frame::CreateTypeDescription() { Frame f; - int imageId(TypeDescription::GetTypeId("Image")); - int vectorId(TypeDescription::GetTypeId("Vector")); - - TypeDescription &td(TypeDescription::CreateOrGet("Frame")); + 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), imageId).SetReferenced().SetDescription("the underlying graphic from which the frame parts are cut")); - td.AddField("border", FieldDescription(((char *)&f.borderSize) - ((char *)&f), vectorId).SetDescription("size of the border part, dimensions of top-left corner")); - td.AddField("repeat", FieldDescription(((char *)&f.repeatSize) - ((char *)&f), vectorId).SetDescription("size of the repeat part, dimensions of a single tile of the background texture")); - td.AddField("offset", FieldDescription(((char *)&f.offset) - ((char *)&f), vectorId).SetDescription("offset into the image where to start cutting, coordinates of the top-left corner on the image")); + 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) {