4 * Created on: Aug 7, 2012
10 #include "../loader/Interpreter.h"
11 #include "../loader/TypeDescription.h"
13 using geometry::Vector;
14 using loader::FieldDescription;
15 using loader::Interpreter;
16 using loader::TypeDescription;
20 void Gauge::Draw(SDL_Surface *dest, const Vector<int> &position, int width, Uint8 fill) const {
21 SDL_Rect srcRect, destRect;
23 int filledWidth = fill * (width - startWidth - endWidth) / 255;
24 int emptyWidth = (255 - fill) * (width - startWidth - endWidth) / 255;
27 destRect.x = position.X();
28 destRect.y = position.Y();
29 destRect.w = filledWidth + startWidth;
31 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0x00));
32 destRect.x += destRect.w;
33 destRect.w = emptyWidth + endWidth;
34 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
39 srcRect.w = startWidth;
41 destRect.x = position.X();
42 destRect.y = position.Y();
45 srcRect.x = emptyOffset.X();
46 srcRect.y = emptyOffset.Y();
47 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
49 srcRect.x = fullOffset.X();
50 srcRect.y = fullOffset.Y();
51 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
54 destRect.x = position.X() + startWidth;
57 srcRect.x = fullOffset.X() + startWidth;
58 srcRect.y = fullOffset.Y();
59 srcRect.w = repeatWidth;
60 while (filledWidth > repeatWidth) {
61 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
62 destRect.x += repeatWidth;
63 filledWidth -= repeatWidth;
65 srcRect.x = emptyOffset.X() + startWidth;
66 srcRect.y = emptyOffset.Y();
67 while (emptyWidth > repeatWidth) {
68 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
69 destRect.x += repeatWidth;
70 emptyWidth -= repeatWidth;
76 srcRect.x = fullOffset.X() + startWidth + repeatWidth;
77 srcRect.y = fullOffset.Y();
78 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
80 srcRect.x = emptyOffset.X() + startWidth + repeatWidth;
81 srcRect.y = emptyOffset.Y();
82 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
88 void Gauge::CreateTypeDescription() {
91 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Gauge"));
93 "Gauges display a percentage by filling the left part different than the right.\n"
94 "The fill level is only mapped with repeat.\n"
95 "Start is filled if the level in greater than zero, end is filled if the level is at its maximum.");
96 td.SetConstructor(&Construct);
97 td.SetSize(sizeof(Gauge));
99 td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), Interpreter::IMAGE_ID).SetReferenced().SetDescription("the underlying graphic from which the gauge parts are cut"));
100 td.AddField("full", FieldDescription(((char *)&g.fullOffset) - ((char *)&g), Interpreter::VECTOR_ID).SetDescription("top-left corner of the filled gauge"));
101 td.AddField("empty", FieldDescription(((char *)&g.emptyOffset) - ((char *)&g), Interpreter::VECTOR_ID).SetDescription("top-left corner of the empty gauge"));
102 td.AddField("height", FieldDescription(((char *)&g.height) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("height of the gauges"));
103 td.AddField("start", FieldDescription(((char *)&g.startWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the start part"));
104 td.AddField("repeat", FieldDescription(((char *)&g.repeatWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the repeat part"));
105 td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the end part"));
108 void Gauge::Construct(void *data) {