4 * Created on: Aug 7, 2012
10 #include "../loader/TypeDescription.h"
12 using geometry::Vector;
13 using loader::FieldDescription;
14 using loader::TypeDescription;
18 void Gauge::Draw(SDL_Surface *dest, const Vector<int> &position, int width, Uint8 fill) const {
19 SDL_Rect srcRect, destRect;
21 int filledWidth = fill * (width - startWidth - endWidth) / 255;
22 int emptyWidth = (255 - fill) * (width - startWidth - endWidth) / 255;
25 destRect.x = position.X();
26 destRect.y = position.Y();
27 destRect.w = filledWidth + startWidth;
29 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0x00));
30 destRect.x += destRect.w;
31 destRect.w = emptyWidth + endWidth;
32 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
37 srcRect.w = startWidth;
39 destRect.x = position.X();
40 destRect.y = position.Y();
43 srcRect.x = emptyOffset.X();
44 srcRect.y = emptyOffset.Y();
45 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
47 srcRect.x = fullOffset.X();
48 srcRect.y = fullOffset.Y();
49 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
52 destRect.x = position.X() + startWidth;
55 srcRect.x = fullOffset.X() + startWidth;
56 srcRect.y = fullOffset.Y();
57 srcRect.w = repeatWidth;
58 while (filledWidth > repeatWidth) {
59 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
60 destRect.x += repeatWidth;
61 filledWidth -= repeatWidth;
63 srcRect.x = emptyOffset.X() + startWidth;
64 srcRect.y = emptyOffset.Y();
65 while (emptyWidth > repeatWidth) {
66 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
67 destRect.x += repeatWidth;
68 emptyWidth -= repeatWidth;
74 srcRect.x = fullOffset.X() + startWidth + repeatWidth;
75 srcRect.y = fullOffset.Y();
76 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
78 srcRect.x = emptyOffset.X() + startWidth + repeatWidth;
79 srcRect.y = emptyOffset.Y();
80 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
86 void Gauge::CreateTypeDescription() {
89 int imageId(TypeDescription::GetTypeId("Image"));
90 int numberId(TypeDescription::GetTypeId("Number"));
91 int vectorId(TypeDescription::GetTypeId("Vector"));
93 TypeDescription &td(TypeDescription::CreateOrGet("Gauge"));
95 "Gauges display a percentage by filling the left part different than the right.\n"
96 "The fill level is only mapped with repeat.\n"
97 "Start is filled if the level in greater than zero, end is filled if the level is at its maximum.");
98 td.SetConstructor(&Construct);
99 td.SetSize(sizeof(Gauge));
101 td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), imageId).SetReferenced().SetDescription("the underlying graphic from which the gauge parts are cut"));
102 td.AddField("full", FieldDescription(((char *)&g.fullOffset) - ((char *)&g), vectorId).SetDescription("top-left corner of the filled gauge"));
103 td.AddField("empty", FieldDescription(((char *)&g.emptyOffset) - ((char *)&g), vectorId).SetDescription("top-left corner of the empty gauge"));
104 td.AddField("height", FieldDescription(((char *)&g.height) - ((char *)&g), numberId).SetDescription("height of the gauges"));
105 td.AddField("start", FieldDescription(((char *)&g.startWidth) - ((char *)&g), numberId).SetDescription("width of the start part"));
106 td.AddField("repeat", FieldDescription(((char *)&g.repeatWidth) - ((char *)&g), numberId).SetDescription("width of the repeat part"));
107 td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), numberId).SetDescription("width of the end part"));
110 void Gauge::Construct(void *data) {