4 * Created on: Aug 7, 2012
10 using geometry::Point;
14 // TODO: add start and end "ignore" offsets
15 void Gauge::Draw(SDL_Surface *dest, Point<int> position, int width, Uint8 level) const {
16 int fullWidth(width * level / 255);
17 SDL_Rect srcRect, destRect;
21 destRect.x = position.X();
22 destRect.y = position.Y();
24 if (fullWidth >= startWidth) { // completely filled
27 srcRect.w = startWidth;
28 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
29 } else if (fullWidth > 0) { // partially filled
32 srcRect.w = fullWidth;
33 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
36 if (fullWidth == 0) { // completely empty
39 srcRect.w = startWidth;
40 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
41 } else if (fullWidth < startWidth) { // partially empty
42 srcRect.x = emptyX + fullWidth;
44 srcRect.w = startWidth - fullWidth;
45 destRect.x = position.X() + fullWidth;
46 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
49 destRect.x = position.X() + startWidth;
52 if (fullWidth >= width - endWidth) { // completely filled
53 srcRect.x = fullX + startWidth;
55 srcRect.w = repeatWidth;
56 int fillWidth(width - startWidth - endWidth);
58 while (fillCursor < fillWidth) {
59 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
60 destRect.x += repeatWidth;
61 fillCursor += repeatWidth;
63 } else if (fullWidth <= startWidth) { // completely empty
64 srcRect.x = emptyX + startWidth;
66 srcRect.w = repeatWidth;
67 int fillWidth(width - startWidth - endWidth);
69 while (fillCursor < fillWidth) {
70 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
71 destRect.x += repeatWidth;
72 fillCursor += repeatWidth;
74 } else { // partially filled/empty
75 srcRect.x = fullX + startWidth;
77 srcRect.w = repeatWidth;
79 while (fillCursor < fullWidth) {
80 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
81 destRect.x += repeatWidth;
82 fillCursor += repeatWidth;
84 srcRect.x = emptyX + startWidth;
86 int remaining(width - startWidth - endWidth);
87 while (fillCursor < remaining) {
88 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
89 destRect.x += repeatWidth;
90 fillCursor += repeatWidth;
96 if (fullWidth >= width) { // completely filled
97 srcRect.x = fullX + startWidth + repeatWidth;
100 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
101 } else if (fullWidth > (width - endWidth)) { // partially filled
102 srcRect.x = fullX + startWidth + repeatWidth;
104 srcRect.w = endWidth - width + fullWidth;
105 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
108 if (fullWidth <= width - endWidth) { // completely empty
109 srcRect.x = emptyX + startWidth + repeatWidth;
111 srcRect.w = startWidth;
112 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
113 } else if (fullWidth > (width - endWidth) && fullWidth < width) { // partially empty
114 srcRect.x = emptyX + startWidth + repeatWidth + fullWidth - width + endWidth;
116 srcRect.w = width - fullWidth;
117 destRect.x = position.X() + fullWidth;
118 SDL_BlitSurface(surface, &srcRect, dest, &destRect);