]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Gauge.cpp
alternate approach to battle animation
[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 void Gauge::Draw(SDL_Surface *dest, const Point<int> &position, int width, Uint8 fill) const {
15         SDL_Rect srcRect, destRect;
16
17         int filledWidth = fill * (width - startWidth - endWidth) / 255;
18         int emptyWidth = (255 - fill) * (width - startWidth - endWidth) / 255;
19
20         // start
21         srcRect.w = startWidth;
22         srcRect.h = height;
23         destRect.x = position.X();
24         destRect.y = position.Y();
25         // full part
26         if (fill == 0) {
27                 srcRect.x = emptyX;
28                 srcRect.y = emptyY;
29                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
30         } else {
31                 srcRect.x = fullX;
32                 srcRect.y = fullY;
33                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
34         }
35
36         destRect.x = position.X() + startWidth;
37
38         // fill
39         srcRect.x = fullX + startWidth;
40         srcRect.y = fullY;
41         srcRect.w = repeatWidth;
42         while (filledWidth > repeatWidth) {
43                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
44                 destRect.x += repeatWidth;
45                 filledWidth -= repeatWidth;
46         }
47         srcRect.x = emptyX + startWidth;
48         srcRect.y = emptyY;
49         while (emptyWidth > repeatWidth) {
50                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
51                 destRect.x += repeatWidth;
52                 emptyWidth -= repeatWidth;
53         }
54
55         // end
56         srcRect.w = endWidth;
57         if (fill == 255) {
58                 srcRect.x = fullX + startWidth + repeatWidth;
59                 srcRect.y = fullY;
60                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
61         } else {
62                 srcRect.x = emptyX + startWidth + repeatWidth;
63                 srcRect.y = emptyY;
64                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
65         }
66
67 }
68
69 }