make arrays one dimensional

With more dimensional arrays we have to define the array size. Use
one dimensional arrays to be more flexible.
Additionally this allows to shrink array size for ASCII.
This commit is contained in:
Christian Hesse 2015-07-16 13:05:48 +02:00
parent 3e93f9b852
commit 9e67b6585e
2 changed files with 35 additions and 29 deletions

61
Meter.c
View File

@ -308,23 +308,24 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
/* ---------- GraphMeterMode ---------- */ /* ---------- GraphMeterMode ---------- */
static const char* GraphMeterMode_dotsUtf8[5][5] = { #define PIXPERROW_UTF8 4
{ /*00*/"", /*01*/"", /*02*/"", /*03*/"", /*04*/ "" }, static const char* GraphMeterMode_dotsUtf8[] = {
{ /*10*/"", /*11*/"", /*12*/"", /*13*/"", /*14*/ "" }, /*00*/"", /*01*/"", /*02*/"", /*03*/"", /*04*/ "",
{ /*20*/"", /*21*/"", /*22*/"", /*23*/"", /*24*/ "" }, /*10*/"", /*11*/"", /*12*/"", /*13*/"", /*14*/ "",
{ /*30*/"", /*31*/"", /*32*/"", /*33*/"", /*34*/ "" }, /*20*/"", /*21*/"", /*22*/"", /*23*/"", /*24*/ "",
{ /*40*/"", /*41*/"", /*42*/"", /*43*/"", /*44*/ "" }, /*30*/"", /*31*/"", /*32*/"", /*33*/"", /*34*/ "",
/*40*/"", /*41*/"", /*42*/"", /*43*/"", /*44*/ ""
}; };
static const char* GraphMeterMode_dotsAscii[5][5] = { #define PIXPERROW_ASCII 2
{ /*00*/" ", /*01*/".", /*02*/".", /*03*/":", /*04*/ ":" }, static const char* GraphMeterMode_dotsAscii[] = {
{ /*10*/".", /*11*/".", /*12*/".", /*13*/":", /*14*/ ":" }, /*00*/" ", /*01*/".", /*02*/":",
{ /*20*/".", /*21*/".", /*22*/".", /*23*/":", /*24*/ ":" }, /*10*/".", /*11*/".", /*12*/":",
{ /*30*/":", /*31*/":", /*32*/":", /*33*/":", /*34*/ ":" }, /*20*/":", /*21*/":", /*22*/":"
{ /*40*/":", /*41*/":", /*42*/":", /*43*/":", /*44*/ ":" },
}; };
static const char* (*GraphMeterMode_dots)[5]; static const char** GraphMeterMode_dots;
static int pixperrow;
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
@ -334,8 +335,10 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
if (CRT_utf8) { if (CRT_utf8) {
GraphMeterMode_dots = GraphMeterMode_dotsUtf8; GraphMeterMode_dots = GraphMeterMode_dotsUtf8;
pixperrow = PIXPERROW_UTF8;
} else { } else {
GraphMeterMode_dots = GraphMeterMode_dotsAscii; GraphMeterMode_dots = GraphMeterMode_dotsAscii;
pixperrow = PIXPERROW_ASCII;
} }
attrset(CRT_colors[METER_TEXT]); attrset(CRT_colors[METER_TEXT]);
@ -365,24 +368,24 @@ 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 / 16); const double dot = (1.0 / (pixperrow * 4));
int v1 = data->values[i] / dot; int v1 = data->values[i] / dot;
int v2 = data->values[i+1] / dot; int v2 = data->values[i+1] / dot;
if (v1 == 0) v1 = 1; if (v1 == 0) v1 = 1;
if (v2 == 0) v2 = 1; if (v2 == 0) v2 = 1;
int level = 12; 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(4, MAX(0, v1 - level)); int line1 = MIN(pixperrow, MAX(0, v1 - level));
int line2 = MIN(4, MAX(0, v2 - level)); int line2 = MIN(pixperrow, MAX(0, v2 - level));
attrset(CRT_colors[colorIdx]); attrset(CRT_colors[colorIdx]);
mvaddstr(y+line, x+k, GraphMeterMode_dots[line1][line2]); mvaddstr(y+line, x+k, GraphMeterMode_dots[line1 * (pixperrow + 1) + line2]);
colorIdx = GRAPH_2; colorIdx = GRAPH_2;
level -= 4; level -= pixperrow;
} }
} }
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
@ -390,23 +393,23 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
/* ---------- LEDMeterMode ---------- */ /* ---------- LEDMeterMode ---------- */
static const char* LEDMeterMode_digitsAscii[3][10] = { static const char* LEDMeterMode_digitsAscii[] = {
{ " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ "}, " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ ",
{ "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|"}, "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|",
{ "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"}, "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"
}; };
static const char* LEDMeterMode_digitsUtf8[3][10] = { static const char* LEDMeterMode_digitsUtf8[] = {
{ "┌──┐","","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐"}, "┌──┐","","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐",
{ "│ │","","┌──┘"," ──┤","└──┤","└──┐","├──┐","","├──┤","└──┤"}, "│ │","","┌──┘"," ──┤","└──┤","└──┐","├──┐","","├──┤","└──┤",
{ "└──┘","","└──╴","╶──┘","","╶──┘","└──┘","","└──┘"," ──┘"}, "└──┘","","└──╴","╶──┘","","╶──┘","└──┘","","└──┘"," ──┘"
}; };
static const char* (*LEDMeterMode_digits)[10]; static const char** LEDMeterMode_digits;
static void LEDMeterMode_drawDigit(int x, int y, int n) { static void LEDMeterMode_drawDigit(int x, int y, int n) {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
mvaddstr(y+i, x, LEDMeterMode_digits[i][n]); mvaddstr(y+i, x, LEDMeterMode_digits[i * 10 + n]);
} }
static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {

View File

@ -119,6 +119,9 @@ ListItem* Meter_toListItem(Meter* this, bool moving);
/* ---------- GraphMeterMode ---------- */ /* ---------- GraphMeterMode ---------- */
#define PIXPERROW_UTF8 4
#define PIXPERROW_ASCII 2
/* ---------- LEDMeterMode ---------- */ /* ---------- LEDMeterMode ---------- */
extern MeterMode* Meter_modes[]; extern MeterMode* Meter_modes[];