-/*
- * Gauge.cpp
- *
- * Created on: Aug 7, 2012
- * Author: holy
- */
-
#include "Gauge.h"
-using geometry::Vector;
+#include "../loader/Interpreter.h"
+#include "../loader/TypeDescription.h"
+
+using math::Vector;
+using loader::FieldDescription;
+using loader::Interpreter;
+using loader::TypeDescription;
namespace graphics {
int filledWidth = fill * (width - startWidth - endWidth) / 255;
int emptyWidth = (255 - fill) * (width - startWidth - endWidth) / 255;
+ if (!surface) {
+ destRect.x = position.X();
+ destRect.y = position.Y();
+ destRect.w = filledWidth + startWidth;
+ destRect.h = height;
+ SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0x00));
+ destRect.x += destRect.w;
+ destRect.w = emptyWidth + endWidth;
+ SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+ return;
+ }
+
// start
srcRect.w = startWidth;
srcRect.h = height;
destRect.y = position.Y();
// full part
if (fill == 0) {
- srcRect.x = emptyX;
- srcRect.y = emptyY;
+ srcRect.x = emptyOffset.X();
+ srcRect.y = emptyOffset.Y();
SDL_BlitSurface(surface, &srcRect, dest, &destRect);
} else {
- srcRect.x = fullX;
- srcRect.y = fullY;
+ srcRect.x = fullOffset.X();
+ srcRect.y = fullOffset.Y();
SDL_BlitSurface(surface, &srcRect, dest, &destRect);
}
destRect.x = position.X() + startWidth;
// fill
- srcRect.x = fullX + startWidth;
- srcRect.y = fullY;
+ srcRect.x = fullOffset.X() + startWidth;
+ srcRect.y = fullOffset.Y();
srcRect.w = repeatWidth;
while (filledWidth > repeatWidth) {
SDL_BlitSurface(surface, &srcRect, dest, &destRect);
destRect.x += repeatWidth;
filledWidth -= repeatWidth;
}
- srcRect.x = emptyX + startWidth;
- srcRect.y = emptyY;
+ srcRect.x = emptyOffset.X() + startWidth;
+ srcRect.y = emptyOffset.Y();
while (emptyWidth > repeatWidth) {
SDL_BlitSurface(surface, &srcRect, dest, &destRect);
destRect.x += repeatWidth;
// end
srcRect.w = endWidth;
if (fill == 255) {
- srcRect.x = fullX + startWidth + repeatWidth;
- srcRect.y = fullY;
+ srcRect.x = fullOffset.X() + startWidth + repeatWidth;
+ srcRect.y = fullOffset.Y();
SDL_BlitSurface(surface, &srcRect, dest, &destRect);
} else {
- srcRect.x = emptyX + startWidth + repeatWidth;
- srcRect.y = emptyY;
+ srcRect.x = emptyOffset.X() + startWidth + repeatWidth;
+ srcRect.y = emptyOffset.Y();
SDL_BlitSurface(surface, &srcRect, dest, &destRect);
}
}
+
+void Gauge::CreateTypeDescription() {
+ Gauge g;
+
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Gauge"));
+ td.SetDescription(
+ "Gauges display a percentage by filling the left part different than the right.\n"
+ "The fill level is only mapped with repeat.\n"
+ "Start is filled if the level in greater than zero, end is filled if the level is at its maximum.");
+ td.SetConstructor(&Construct);
+ td.SetSize(sizeof(Gauge));
+
+ td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), Interpreter::IMAGE_ID).SetReferenced().SetDescription("the underlying graphic from which the gauge parts are cut"));
+ td.AddField("full", FieldDescription(((char *)&g.fullOffset) - ((char *)&g), Interpreter::VECTOR_ID).SetDescription("top-left corner of the filled gauge"));
+ td.AddField("empty", FieldDescription(((char *)&g.emptyOffset) - ((char *)&g), Interpreter::VECTOR_ID).SetDescription("top-left corner of the empty gauge"));
+ td.AddField("height", FieldDescription(((char *)&g.height) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("height of the gauges"));
+ td.AddField("start", FieldDescription(((char *)&g.startWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the start part"));
+ td.AddField("repeat", FieldDescription(((char *)&g.repeatWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the repeat part"));
+ td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the end part"));
+}
+
+void Gauge::Construct(void *data) {
+ new (data) Gauge;
+}
+
}