From e93028d7fa0c5f00b5dc3336fd28abaf905cd572 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Thu, 24 Dec 2015 09:51:37 +0800 Subject: [PATCH] New macro GRAPH_HEIGHT for Graph Meter height Currently GRAPH_HEIGHT=4 . This prevents hard-coding the height of the graph meters, and allows user to change it at compile-time. (It's still unchangeable in runtime yet. Can a Setup option be implemented for this thing?) --- Meter.c | 16 +++++++++------- Meter.h | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Meter.c b/Meter.c index 834c9b0..1b71599 100644 --- a/Meter.c +++ b/Meter.c @@ -358,6 +358,8 @@ static const char* GraphMeterMode_dotsAscii[] = { /*20*/":", /*21*/":", /*22*/":" }; +#define GRAPH_HEIGHT 4 /* Unit: rows (lines) */ + static const char** GraphMeterMode_dots; static int GraphMeterMode_pixPerRow; @@ -405,14 +407,14 @@ 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 / (GraphMeterMode_pixPerRow * 4)); - int v1 = MIN(GraphMeterMode_pixPerRow * 4, MAX(1, data->values[i] / dot)); - int v2 = MIN(GraphMeterMode_pixPerRow * 4, MAX(1, data->values[i+1] / dot)); + const double dot = (1.0 / (GraphMeterMode_pixPerRow * GRAPH_HEIGHT)); + int v1 = MIN(GraphMeterMode_pixPerRow * GRAPH_HEIGHT, MAX(1, data->values[i] / dot)); + int v2 = MIN(GraphMeterMode_pixPerRow * GRAPH_HEIGHT, MAX(1, data->values[i+1] / dot)); int colorIdx = GRAPH_1; - for (int line = 0; line < 4; line++) { - int line1 = MIN(GraphMeterMode_pixPerRow, MAX(0, v1 - (GraphMeterMode_pixPerRow * (3 - line)))); - int line2 = MIN(GraphMeterMode_pixPerRow, MAX(0, v2 - (GraphMeterMode_pixPerRow * (3 - line)))); + for (int line = 0; line < GRAPH_HEIGHT; line++) { + int line1 = MIN(GraphMeterMode_pixPerRow, MAX(0, v1 - (GraphMeterMode_pixPerRow * (GRAPH_HEIGHT - 1 - line)))); + int line2 = MIN(GraphMeterMode_pixPerRow, MAX(0, v2 - (GraphMeterMode_pixPerRow * (GRAPH_HEIGHT - 1 - line)))); attrset(CRT_colors[colorIdx]); mvaddstr(y+line, x+k, GraphMeterMode_dots[line1 * (GraphMeterMode_pixPerRow + 1) + line2]); @@ -500,7 +502,7 @@ static MeterMode TextMeterMode = { static MeterMode GraphMeterMode = { .uiName = "Graph", - .h = 4, + .h = GRAPH_HEIGHT, .draw = GraphMeterMode_draw, }; diff --git a/Meter.h b/Meter.h index fe102fb..e945de7 100644 --- a/Meter.h +++ b/Meter.h @@ -127,6 +127,8 @@ ListItem* Meter_toListItem(Meter* this, bool moving); #endif #define PIXPERROW_ASCII 2 +#define GRAPH_HEIGHT 4 /* Unit: rows (lines) */ + /* ---------- LEDMeterMode ---------- */ -- GitLab