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.
This commit is contained in:
Christian Hesse 2015-08-14 16:59:14 +02:00
parent d8e23bb084
commit a2a34e89a1
1 changed files with 6 additions and 12 deletions

14
Meter.c
View File

@ -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++) { for (int i = nValues - (w*2) + 2, k = 0; i < nValues; i+=2, k++) {
const double dot = (1.0 / (pixperrow * 4)); const double dot = (1.0 / (pixperrow * 4));
int v1 = data->values[i] / dot; int v1 = MIN(pixperrow * 4, MAX(1, data->values[i] / dot));
int v2 = data->values[i+1] / dot; int v2 = MIN(pixperrow * 4, MAX(1, data->values[i+1] / dot));
if (v1 == 0) v1 = 1;
if (v2 == 0) v2 = 1;
int level = pixperrow * 3;
int colorIdx = GRAPH_1; int colorIdx = GRAPH_1;
for (int line = 0; line < 4; line++) { for (int line = 0; line < 4; line++) {
int line1 = MIN(pixperrow, MAX(0, v1 - (pixperrow * (3 - line))));
int line1 = MIN(pixperrow, MAX(0, v1 - level)); int line2 = MIN(pixperrow, MAX(0, v2 - (pixperrow * (3 - line))));
int line2 = MIN(pixperrow, MAX(0, v2 - level));
attrset(CRT_colors[colorIdx]); attrset(CRT_colors[colorIdx]);
mvaddstr(y+line, x+k, GraphMeterMode_dots[line1 * (pixperrow + 1) + line2]); mvaddstr(y+line, x+k, GraphMeterMode_dots[line1 * (pixperrow + 1) + line2]);
colorIdx = GRAPH_2; colorIdx = GRAPH_2;
level -= pixperrow;
} }
} }
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);