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, int fullWidth) const {
16 SDL_Rect srcRect, destRect;
20 destRect.x = position.X();
21 destRect.y = position.Y();
23 if (fullWidth >= startWidth) { // completely filled
26 srcRect.w = startWidth;
27 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
28 } else if (fullWidth > 0) { // partially filled
31 srcRect.w = fullWidth;
32 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
35 if (fullWidth == 0) { // completely empty
38 srcRect.w = startWidth;
39 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
40 } else if (fullWidth < startWidth) { // partially empty
41 srcRect.x = emptyX + fullWidth;
43 srcRect.w = startWidth - fullWidth;
44 destRect.x = position.X() + fullWidth;
45 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
48 destRect.x = position.X() + startWidth;
51 if (fullWidth >= width - endWidth) { // completely filled
52 srcRect.x = fullX + startWidth;
54 srcRect.w = repeatWidth;
55 int fillWidth(width - startWidth - endWidth);
57 while (fillCursor < fillWidth) {
58 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
59 destRect.x += repeatWidth;
60 fillCursor += repeatWidth;
62 } else if (fullWidth <= startWidth) { // completely empty
63 srcRect.x = emptyX + startWidth;
65 srcRect.w = repeatWidth;
66 int fillWidth(width - startWidth - endWidth);
68 while (fillCursor < fillWidth) {
69 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
70 destRect.x += repeatWidth;
71 fillCursor += repeatWidth;
73 } else { // partially filled/empty
74 srcRect.x = fullX + startWidth;
76 srcRect.w = repeatWidth;
78 while (fillCursor < fullWidth) {
79 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
80 destRect.x += repeatWidth;
81 fillCursor += repeatWidth;
83 srcRect.x = emptyX + startWidth;
85 int remaining(width - startWidth - endWidth);
86 while (fillCursor < remaining) {
87 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
88 destRect.x += repeatWidth;
89 fillCursor += repeatWidth;
95 if (fullWidth >= width) { // completely filled
96 srcRect.x = fullX + startWidth + repeatWidth;
99 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
100 } else if (fullWidth > (width - endWidth)) { // partially filled
101 srcRect.x = fullX + startWidth + repeatWidth;
103 srcRect.w = endWidth - width + fullWidth;
104 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
107 if (fullWidth <= width - endWidth) { // completely empty
108 srcRect.x = emptyX + startWidth + repeatWidth;
110 srcRect.w = startWidth;
111 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
112 } else if (fullWidth > (width - endWidth) && fullWidth < width) { // partially empty
113 srcRect.x = emptyX + startWidth + repeatWidth + fullWidth - width + endWidth;
115 srcRect.w = width - fullWidth;
116 destRect.x = position.X() + fullWidth;
117 SDL_BlitSurface(surface, &srcRect, dest, &destRect);