4 * Created on: Aug 7, 2012
10 using geometry::Vector;
14 void Gauge::Draw(SDL_Surface *dest, const Vector<int> &position, int width, Uint8 fill) const {
15 SDL_Rect srcRect, destRect;
17 int filledWidth = fill * (width - startWidth - endWidth) / 255;
18 int emptyWidth = (255 - fill) * (width - startWidth - endWidth) / 255;
21 destRect.x = position.X();
22 destRect.y = position.Y();
23 destRect.w = filledWidth + startWidth;
25 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0x00));
26 destRect.x += destRect.w;
27 destRect.w = emptyWidth + endWidth;
28 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
33 srcRect.w = startWidth;
35 destRect.x = position.X();
36 destRect.y = position.Y();
39 srcRect.x = emptyOffset.X();
40 srcRect.y = emptyOffset.Y();
41 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
43 srcRect.x = fullOffset.X();
44 srcRect.y = fullOffset.Y();
45 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
48 destRect.x = position.X() + startWidth;
51 srcRect.x = fullOffset.X() + startWidth;
52 srcRect.y = fullOffset.Y();
53 srcRect.w = repeatWidth;
54 while (filledWidth > repeatWidth) {
55 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
56 destRect.x += repeatWidth;
57 filledWidth -= repeatWidth;
59 srcRect.x = emptyOffset.X() + startWidth;
60 srcRect.y = emptyOffset.Y();
61 while (emptyWidth > repeatWidth) {
62 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
63 destRect.x += repeatWidth;
64 emptyWidth -= repeatWidth;
70 srcRect.x = fullOffset.X() + startWidth + repeatWidth;
71 srcRect.y = fullOffset.Y();
72 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
74 srcRect.x = emptyOffset.X() + startWidth + repeatWidth;
75 srcRect.y = emptyOffset.Y();
76 SDL_BlitSurface(surface, &srcRect, dest, &destRect);