Skip to content

Commit

Permalink
Store itemNum in GraphColorCell
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 committed Jan 28, 2024
1 parent dd01860 commit 27d4b85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
21 changes: 7 additions & 14 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,6 @@ static void GraphMeterMode_reallocateGraphBuffer(Meter* this, const GraphDrawCon

// Fill new spaces with blank records
memset(data->buffer, 0, moveOffset * sizeof(*data->buffer));
if (context->maxItems > 1) {
for (size_t i = 0; i < moveOffset; i++) {
if (context->isPercentChart || i % nCellsPerValue > 0) {
data->buffer[i].c.itemIndex = UINT8_MAX;
}
}
}

bufferInitialized:
data->nValues = nValues;
Expand Down Expand Up @@ -572,7 +565,7 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre
static void GraphMeterMode_paintCellsForItem(GraphColorCell* cellsStart, unsigned int increment, uint8_t itemIndex, unsigned int nCells, uint16_t mask) {
GraphColorCell* cell = cellsStart;
while (nCells > 0) {
cell->c.itemIndex = itemIndex;
cell->c.itemNum = itemIndex + 1;
if (nCells == 1) {
cell->c.details = (uint8_t)mask;
} else if (cell == cellsStart) {
Expand Down Expand Up @@ -896,9 +889,9 @@ static void GraphMeterMode_recordNewValue(Meter* this, const GraphDrawContext* c
// Clear cells
unsigned int i = ((unsigned int)numDots + 8 - 1) / 8; // Round up
i = GraphMeterMode_valueCellIndex(graphHeight, isPercentChart, 0, i, NULL, NULL);
for (; i < nCellsPerValue; i++) {
valueStart[i].c.itemIndex = UINT8_MAX;
valueStart[i].c.details = 0x00;
if (i != (unsigned int)-1) {
assert(i < nCellsPerValue);
memset(&valueStart[i], 0, (nCellsPerValue - i) * sizeof(*valueStart));
}

if (sum <= 0.0)
Expand Down Expand Up @@ -982,7 +975,7 @@ static int GraphMeterMode_lookupCell(const Meter* this, const GraphDrawContext*
assert(y < graphHeight);
y = graphHeight - 1 - y;

uint8_t itemIndex = UINT8_MAX;
uint8_t itemIndex = (uint8_t)-1;
*details = 0x00; // Empty the cell

if (maxItems < 1)
Expand Down Expand Up @@ -1040,7 +1033,7 @@ static int GraphMeterMode_lookupCell(const Meter* this, const GraphDrawContext*
}

const GraphColorCell* cell = &valueStart[i];
itemIndex = cell->c.itemIndex;
itemIndex = cell->c.itemNum - 1;
*details = GraphMeterMode_scaleCellDetails(cell->c.details, scaleFactor);
}
/* fallthrough */
Expand All @@ -1049,7 +1042,7 @@ static int GraphMeterMode_lookupCell(const Meter* this, const GraphDrawContext*
if (y == 0)
*details |= 0xC0;

if (itemIndex == UINT8_MAX)
if (itemIndex == (uint8_t)-1)
return BAR_SHADOW;

assert(itemIndex < maxItems);
Expand Down
2 changes: 1 addition & 1 deletion Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ typedef union GraphColorCell_ {
int16_t scaleExp;
uint16_t numDots;
struct GraphColorCellCell_ {
uint8_t itemIndex;
uint8_t itemNum;
uint8_t details;
} c;
} GraphColorCell;
Expand Down

0 comments on commit 27d4b85

Please sign in to comment.