summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorChristian Hesse <mail@eworm.de>2015-08-14 16:59:14 +0200
committerChristian Hesse <mail@eworm.de>2015-08-19 22:42:34 +0200
commita2a34e89a1f56996ba2a58d72726d259766ad7b4 (patch)
tree02aabac684b7311f4b45051fa82ebeb7246afe45 /Meter.c
parentd8e23bb0847d766d7f3fdf8bdd11f7d70829fad8 (diff)
simplify Meter loop
* Use MIN() and MAX() to make sure values are inside bounds. This should fix an issue where Meters were missing dots at the bottom. * Remove variable 'level' and calculate on the fly.
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/Meter.c b/Meter.c
index f7ad61aa..ff0f7000 100644
--- a/Meter.c
+++ b/Meter.c
@@ -376,23 +376,17 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
for (int i = nValues - (w*2) + 2, k = 0; i < nValues; i+=2, k++) {
const double dot = (1.0 / (pixperrow * 4));
- int v1 = data->values[i] / dot;
- int v2 = data->values[i+1] / dot;
-
- if (v1 == 0) v1 = 1;
- if (v2 == 0) v2 = 1;
-
- int level = pixperrow * 3;
+ int v1 = MIN(pixperrow * 4, MAX(1, data->values[i] / dot));
+ int v2 = MIN(pixperrow * 4, MAX(1, data->values[i+1] / dot));
+
int colorIdx = GRAPH_1;
for (int line = 0; line < 4; line++) {
-
- int line1 = MIN(pixperrow, MAX(0, v1 - level));
- int line2 = MIN(pixperrow, MAX(0, v2 - level));
-
+ int line1 = MIN(pixperrow, MAX(0, v1 - (pixperrow * (3 - line))));
+ int line2 = MIN(pixperrow, MAX(0, v2 - (pixperrow * (3 - line))));
+
attrset(CRT_colors[colorIdx]);
mvaddstr(y+line, x+k, GraphMeterMode_dots[line1 * (pixperrow + 1) + line2]);
colorIdx = GRAPH_2;
- level -= pixperrow;
}
}
attrset(CRT_colors[RESET_COLOR]);

© 2014-2024 Faster IT GmbH | imprint | privacy policy