CountDownBars non-tick-pixels darker

This commit is contained in:
Patrick Haßel 2023-12-31 14:11:24 +01:00
parent 07a41a34cf
commit 9a01e99eec

View File

@ -114,24 +114,33 @@ private:
} }
void drawCountdownBars(Display &display, uint8_t hours, uint8_t minutes, uint8_t seconds) { void drawCountdownBars(Display &display, uint8_t hours, uint8_t minutes, uint8_t seconds) {
drawBar(display, 0, 0, 24, 1, 0, 24, hours, RED); drawBar(display, 0, 0, 24, 1, 0, 24, hours, RED, 6);
drawBar(display, 0, 2, 30, 2, 0, 60, minutes, BLUE); drawBar(display, 0, 2, 30, 2, 0, 60, minutes, BLUE, 5);
drawBar(display, 0, 5, 30, 2, 0, 60, seconds, GREEN); drawBar(display, 0, 5, 30, 2, 0, 60, seconds, GREEN, 10);
} }
void drawBar(Display &display, uint8_t _x, uint8_t _y, uint8_t _w, uint8_t _h, uint8_t min, uint8_t max, uint8_t value, const Color &color) { void drawBar(Display &display, uint8_t _x, uint8_t _y, uint8_t _w, uint8_t _h, uint8_t min, uint8_t max, uint8_t value, const Color &color, uint8_t ticks) {
auto onCount = (uint8_t) round(((double) value - min) / (max - min) * _w * _h); auto totalOnCount = (uint8_t) round(((double) value - min) / (max - min) * _w * _h);
uint8_t doneOnCount = 0;
for (uint8_t y = 0; y < _h; y++) { for (uint8_t y = 0; y < _h; y++) {
for (uint8_t x = 0; x < _w; x++) { for (uint8_t x = 0; x < _w; x++) {
if (onCount <= 0) { if (doneOnCount >= totalOnCount) {
return; return;
} }
onCount--; doneOnCount++;
display.set(_x + x, _y + y, color); display.set(_x + x, _y + y, (doneOnCount % ticks) == 0 ? color : factor(color, 0.5));
} }
} }
} }
static Color factor(Color color, double factor) {
return {
(uint8_t) round(color.r * factor),
(uint8_t) round(color.g * factor),
(uint8_t) round(color.b * factor),
};
}
void drawCountdownNumbers(Display &display, uint8_t hours, uint8_t minutes, uint8_t seconds) const { void drawCountdownNumbers(Display &display, uint8_t hours, uint8_t minutes, uint8_t seconds) const {
uint8_t x = 0; uint8_t x = 0;
if (days > 0) { if (days > 0) {