3 #include "../loader/Interpreter.h"
4 #include "../loader/TypeDescription.h"
7 using loader::FieldDescription;
8 using loader::Interpreter;
9 using loader::TypeDescription;
13 void Gauge::Draw(SDL_Surface *dest, const Vector<int> &position, int width, Uint8 fill) const {
14 SDL_Rect srcRect, destRect;
16 int filledWidth = fill * (width - startWidth - endWidth) / 255;
17 int emptyWidth = (255 - fill) * (width - startWidth - endWidth) / 255;
20 destRect.x = position.X();
21 destRect.y = position.Y();
22 destRect.w = filledWidth + startWidth;
24 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0x00));
25 destRect.x += destRect.w;
26 destRect.w = emptyWidth + endWidth;
27 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
32 srcRect.w = startWidth;
34 destRect.x = position.X();
35 destRect.y = position.Y();
38 srcRect.x = emptyOffset.X();
39 srcRect.y = emptyOffset.Y();
40 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
42 srcRect.x = fullOffset.X();
43 srcRect.y = fullOffset.Y();
44 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
47 destRect.x = position.X() + startWidth;
50 srcRect.x = fullOffset.X() + startWidth;
51 srcRect.y = fullOffset.Y();
52 srcRect.w = repeatWidth;
53 while (filledWidth > repeatWidth) {
54 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
55 destRect.x += repeatWidth;
56 filledWidth -= repeatWidth;
58 srcRect.x = emptyOffset.X() + startWidth;
59 srcRect.y = emptyOffset.Y();
60 while (emptyWidth > repeatWidth) {
61 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
62 destRect.x += repeatWidth;
63 emptyWidth -= repeatWidth;
69 srcRect.x = fullOffset.X() + startWidth + repeatWidth;
70 srcRect.y = fullOffset.Y();
71 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
73 srcRect.x = emptyOffset.X() + startWidth + repeatWidth;
74 srcRect.y = emptyOffset.Y();
75 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
81 void Gauge::CreateTypeDescription() {
84 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Gauge"));
86 "Gauges display a percentage by filling the left part different than the right.\n"
87 "The fill level is only mapped with repeat.\n"
88 "Start is filled if the level in greater than zero, end is filled if the level is at its maximum.");
89 td.SetConstructor(&Construct);
90 td.SetSize(sizeof(Gauge));
92 td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), Interpreter::IMAGE_ID).SetReferenced().SetDescription("the underlying graphic from which the gauge parts are cut"));
93 td.AddField("full", FieldDescription(((char *)&g.fullOffset) - ((char *)&g), Interpreter::VECTOR_ID).SetDescription("top-left corner of the filled gauge"));
94 td.AddField("empty", FieldDescription(((char *)&g.emptyOffset) - ((char *)&g), Interpreter::VECTOR_ID).SetDescription("top-left corner of the empty gauge"));
95 td.AddField("height", FieldDescription(((char *)&g.height) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("height of the gauges"));
96 td.AddField("start", FieldDescription(((char *)&g.startWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the start part"));
97 td.AddField("repeat", FieldDescription(((char *)&g.repeatWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the repeat part"));
98 td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the end part"));
101 void Gauge::Construct(void *data) {