Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
ProgressBar.cpp
1#include "ProgressBar.hpp"
2#include "RootDisplay.hpp"
3
4namespace Chesto {
5
6ProgressBar::ProgressBar()
7{
8 // total width of full progress bar
9 this->width = 450;
10 this->height = 5; //HACKY: progress bars are 9 px tall and erroneously extend 4 px above their y-position (other elements use y-position as top, not center)
11 this->color = 0x56c1dfff;
12}
13
15{
16 // if we're hidden, don't render
17 if (hidden) return;
18
19 if (this->percent < 0)
20 return;
21
22 auto renderer = getRenderer();
23
24 if (dimBg)
25 {
26 // draw a big dim layer around the entire window before drawing this progress bar
27 CST_Rect dim = { 0, 0, RootDisplay::screenWidth, RootDisplay::screenHeight };
28
29 CST_SetDrawBlend(renderer, true);
30 CST_SetDrawColorRGBA(renderer, 0x00, 0x00, 0x00, 0xbb);
31 CST_FillRect(renderer, &dim);
32 }
33
34 this->recalcPosition(parent);
35
36 // int blue = this->color;
37 // int gray = 0x989898ff;
38
39 // draw full grayed out bar first
40 CST_Rect gray_rect;
41 gray_rect.x = this->xAbs;
42 gray_rect.y = this->yAbs - 4;
43 gray_rect.w = this->width;
44 gray_rect.h = 9;
45
46 CST_SetDrawColorRGBA(renderer, 0x98, 0x98, 0x98, 0xff); //gray2
47 CST_FillRect(renderer, &gray_rect);
48
49 // draw ending "circle"
50 CST_filledCircleRGBA(renderer, this->xAbs + this->width, this->yAbs, 4, 0x98, 0x98, 0x98, 0xff);
51
52 // draw left "circle" (rounded part of bar)
53 CST_filledCircleRGBA(renderer, this->xAbs, this->yAbs, 4, 0x56, 0xc1, 0xdf, 0xff);
54
55 // draw blue progress bar so far
56 CST_Rect blue_rect;
57 blue_rect.x = this->xAbs;
58 blue_rect.y = this->yAbs - 4;
59 blue_rect.w = this->width * this->percent;
60 blue_rect.h = 9;
61
62 if (this->percent > 1) {
63 // prevent going too far past the end
64 blue_rect.w = this->width;
65 }
66
67 CST_SetDrawColorRGBA(renderer, 0x56, 0xc1, 0xdf, 0xff); // blue2
68 CST_FillRect(renderer, &blue_rect);
69
70 // draw right "circle" (rounded part of bar, and ending)
71 CST_filledCircleRGBA(renderer, this->xAbs + width * this->percent, this->yAbs, 4, 0x56, 0xc1, 0xdf, 0xff);
72}
73
74} // namespace Chesto
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Definition: Element.hpp:132
bool hidden
whether this element should skip rendering or not
Definition: Element.hpp:119
Element * parent
the parent element (reference only, not owned)
Definition: Element.hpp:116
void render(Element *parent)
display the current state of the display
Definition: ProgressBar.cpp:14