Skip to content

Commit

Permalink
Meter: introduce comprisedValues option
Browse files Browse the repository at this point in the history
Useful for bar mode if latter values of the meter comprise previous
ones.
  • Loading branch information
cgzones authored and BenBE committed Apr 11, 2023
1 parent da255cb commit ccf745e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
assert(startPos + w <= RichString_sizeVal(bar));

int blockSizes[10];
int blockSizeSum = 0;

// First draw in the bar[] buffer...
int offset = 0;
Expand All @@ -230,6 +231,12 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
} else {
blockSizes[i] = 0;
}

if (Meter_comprisedValues(this)) {
blockSizes[i] = MAXIMUM(blockSizes[i] - blockSizeSum, 0);
blockSizeSum += blockSizes[i];
}

int nextOffset = offset + blockSizes[i];
// (Control against invalid values)
nextOffset = CLAMP(nextOffset, 0, w);
Expand Down Expand Up @@ -323,10 +330,14 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
for (int i = 0; i < nValues - 1; i++)
data->values[i] = data->values[i + 1];

double value = 0.0;
for (uint8_t i = 0; i < this->curItems; i++)
value += !isnan(this->values[i]) ? this->values[i] : 0;
data->values[nValues - 1] = value;
if (Meter_comprisedValues(this)) {
data->values[nValues - 1] = (this->curItems > 0) ? this->values[this->curItems - 1] : 0.0;
} else {
double value = 0.0;
for (uint8_t i = 0; i < this->curItems; i++)
value += !isnan(this->values[i]) ? this->values[i] : 0;
data->values[nValues - 1] = value;
}
}

int i = nValues - (w * 2), k = 0;
Expand Down
2 changes: 2 additions & 0 deletions Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef struct MeterClass_ {
const char* const description; /* optional meter description in header setup menu */
const uint8_t maxItems;
const bool isMultiColumn; /* whether the meter draws multiple sub-columns (defaults to false) */
const bool comprisedValues; /* whether latter values comprise previous ones (defaults to false) */
} MeterClass;

#define As_Meter(this_) ((const MeterClass*)((this_)->super.klass))
Expand All @@ -94,6 +95,7 @@ typedef struct MeterClass_ {
#define Meter_name(this_) As_Meter(this_)->name
#define Meter_uiName(this_) As_Meter(this_)->uiName
#define Meter_isMultiColumn(this_) As_Meter(this_)->isMultiColumn
#define Meter_comprisedValues(this_) As_Meter(this_)->comprisedValues

typedef struct GraphData_ {
struct timeval time;
Expand Down

0 comments on commit ccf745e

Please sign in to comment.