]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Gauge.cpp
added initializer lists to Hero and Monster models
[l2e.git] / src / graphics / Gauge.cpp
1 /*
2  * Gauge.cpp
3  *
4  *  Created on: Aug 7, 2012
5  *      Author: holy
6  */
7
8 #include "Gauge.h"
9
10 using geometry::Point;
11
12 namespace graphics {
13
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;
17
18         // start
19         srcRect.h = height;
20         destRect.x = position.X();
21         destRect.y = position.Y();
22         // full part
23         if (fullWidth >= startWidth) { // completely filled
24                 srcRect.x = fullX;
25                 srcRect.y = fullY;
26                 srcRect.w = startWidth;
27                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
28         } else if (fullWidth > 0) { // partially filled
29                 srcRect.x = fullX;
30                 srcRect.y = fullY;
31                 srcRect.w = fullWidth;
32                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
33         }
34         // empty part
35         if (fullWidth == 0) { // completely empty
36                 srcRect.x = emptyX;
37                 srcRect.y = emptyY;
38                 srcRect.w = startWidth;
39                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
40         } else if (fullWidth < startWidth) { // partially empty
41                 srcRect.x = emptyX + fullWidth;
42                 srcRect.y = emptyY;
43                 srcRect.w = startWidth - fullWidth;
44                 destRect.x = position.X() + fullWidth;
45                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
46         }
47
48         destRect.x = position.X() + startWidth;
49
50         // fill
51         if (fullWidth >= width - endWidth) { // completely filled
52                 srcRect.x = fullX + startWidth;
53                 srcRect.y = fullY;
54                 srcRect.w = repeatWidth;
55                 int fillWidth(width - startWidth - endWidth);
56                 int fillCursor(0);
57                 while (fillCursor < fillWidth) {
58                         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
59                         destRect.x += repeatWidth;
60                         fillCursor += repeatWidth;
61                 }
62         } else if (fullWidth <= startWidth) { // completely empty
63                 srcRect.x = emptyX + startWidth;
64                 srcRect.y = emptyY;
65                 srcRect.w = repeatWidth;
66                 int fillWidth(width - startWidth - endWidth);
67                 int fillCursor(0);
68                 while (fillCursor < fillWidth) {
69                         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
70                         destRect.x += repeatWidth;
71                         fillCursor += repeatWidth;
72                 }
73         } else { // partially filled/empty
74                 srcRect.x = fullX + startWidth;
75                 srcRect.y = fullY;
76                 srcRect.w = repeatWidth;
77                 int fillCursor(0);
78                 while (fillCursor < fullWidth) {
79                         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
80                         destRect.x += repeatWidth;
81                         fillCursor += repeatWidth;
82                 }
83                 srcRect.x = emptyX + startWidth;
84                 srcRect.y = emptyY;
85                 int remaining(width - startWidth - endWidth);
86                 while (fillCursor < remaining) {
87                         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
88                         destRect.x += repeatWidth;
89                         fillCursor += repeatWidth;
90                 }
91         }
92
93         // end
94         // full part
95         if (fullWidth >= width) { // completely filled
96                 srcRect.x = fullX + startWidth + repeatWidth;
97                 srcRect.y = fullY;
98                 srcRect.w = endWidth;
99                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
100         } else if (fullWidth > (width - endWidth)) { // partially filled
101                 srcRect.x = fullX + startWidth + repeatWidth;
102                 srcRect.y = fullY;
103                 srcRect.w = endWidth - width + fullWidth;
104                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
105         }
106         // empty part
107         if (fullWidth <= width - endWidth) { // completely empty
108                 srcRect.x = emptyX + startWidth + repeatWidth;
109                 srcRect.y = emptyY;
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;
114                 srcRect.y = emptyY;
115                 srcRect.w = width - fullWidth;
116                 destRect.x = position.X() + fullWidth;
117                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
118         }
119
120 }
121
122 }