Skip to content

Commit

Permalink
Adjust GraphMeterMode_draw() code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 authored and BenBE committed Jul 23, 2024
1 parent 25391b2 commit 1887699
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ static const char* const GraphMeterMode_dotsAscii[] = {
};

static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
// Draw the caption
const char* caption = Meter_getCaption(this);
attrset(CRT_colors[METER_TEXT]);
const int captionLen = 3;
Expand All @@ -198,6 +199,8 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
w -= captionLen;

GraphData* data = &this->drawData;

// Expand the graph data buffer if necessary
assert(data->nValues / 2 <= INT_MAX);
if (w > (int)(data->nValues / 2) && MAX_METER_GRAPHDATA_VALUES > data->nValues) {
size_t oldNValues = data->nValues;
Expand All @@ -212,6 +215,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
if (nValues < 1)
return;

// Record new value if necessary
const Machine* host = this->host;
if (!timercmp(&host->realtime, &(data->time), <)) {
int globalDelay = host->settings->delay;
Expand All @@ -226,6 +230,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
if (w <= 0)
return;

// Graph drawing style (character set, etc.)
const char* const* GraphMeterMode_dots;
int GraphMeterMode_pixPerRow;
#ifdef HAVE_LIBNCURSESW
Expand All @@ -239,12 +244,14 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
GraphMeterMode_pixPerRow = PIXPERROW_ASCII;
}

// Starting positions of graph data and terminal column
if ((size_t)w > nValues / 2) {
x += w - nValues / 2;
w = nValues / 2;
}
size_t i = nValues - (size_t)w * 2;

// Draw the actual graph
for (int col = 0; i < nValues - 1; i += 2, col++) {
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
double total = MAXIMUM(this->total, 1);
Expand Down

0 comments on commit 1887699

Please sign in to comment.