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"));
94 td.SetSize(sizeof(Gauge));
96 td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), imageId, true));
97 td.AddField("full", FieldDescription(((char *)&g.fullOffset) - ((char *)&g), vectorId, false));
98 td.AddField("empty", FieldDescription(((char *)&g.emptyOffset) - ((char *)&g), vectorId, false));
99 td.AddField("height", FieldDescription(((char *)&g.height) - ((char *)&g), numberId, false));
100 td.AddField("start", FieldDescription(((char *)&g.startWidth) - ((char *)&g), numberId, false));
101 td.AddField("repeat", FieldDescription(((char *)&g.repeatWidth) - ((char *)&g), numberId, false));
102 td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), numberId, false));