From 09de6831b3483eb67623faac8a18002b62b7a8fa Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Wed, 30 Jul 2025 04:37:32 +0800 Subject: [PATCH 1/2] Add xOffsetOfMeterColumn() sub-function in CPUMeterCommonDraw() Make the 'x' offset calculation in CPUMeterCommonDraw() a sub-function. There should be no changes to the compiled code. Signed-off-by: Kang-Che Sung --- CPUMeter.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 69da88db0..fa4bd903d 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -300,17 +300,22 @@ static void OctoColCPUsMeter_updateMode(Meter* this, MeterModeId mode) { CPUMeterCommonUpdateMode(this, mode, 8); } +static int xOffsetOfMeterColumn(int w, int nCol, int col) { + int colwidth = w / nCol; + int diff = w % nCol; + int d = MINIMUM(diff, col); // dynamic spacer + return (col * colwidth) + d; +} + static void CPUMeterCommonDraw(Meter* this, int x, int y, int w, int ncol) { CPUMeterData* data = this->meterData; Meter** meters = data->meters; int start, count; AllCPUsMeter_getRange(this, &start, &count); int colwidth = w / ncol; - int diff = w % ncol; int nrows = (count + ncol - 1) / ncol; for (int i = 0; i < count; i++) { - int d = (i / nrows) > diff ? diff : (i / nrows); // dynamic spacer - int xpos = x + ((i / nrows) * colwidth) + d; + int xpos = x + xOffsetOfMeterColumn(w, ncol, i / nrows); int ypos = y + ((i % nrows) * meters[0]->h); meters[i]->draw(meters[i], xpos, ypos, colwidth); } From 3659c9009b08705f47ffb1b0af915e665ae454b3 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Sat, 29 Mar 2025 02:52:25 +0800 Subject: [PATCH 2/2] CPUMeter: Improve spacing between sub-meter algorithm The new algorithm will make the meter bars aligned when groups of CPU meters with 2, 4 and 8 sub-columns are placed together in one larger column. It utilizes the fact that the number of sub-columns of CPU meters are in power of 2 only, and calculates spacing with bit tricks. Signed-off-by: Kang-Che Sung --- CPUMeter.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index fa4bd903d..39e40ef3e 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -12,6 +12,7 @@ in the source distribution for its full text. #include #include #include +#include #include #include @@ -302,9 +303,13 @@ static void OctoColCPUsMeter_updateMode(Meter* this, MeterModeId mode) { static int xOffsetOfMeterColumn(int w, int nCol, int col) { int colwidth = w / nCol; - int diff = w % nCol; - int d = MINIMUM(diff, col); // dynamic spacer - return (col * colwidth) + d; + + // Spacing between meters based on the remainder of (w % nCol) + uint32_t v = (unsigned int)((w % nCol) * 32 / nCol); + v = ((v * 0x00210842U) & 0x02082082U) * (unsigned int)col; + v = (uint32_t)(((v + 0x02108420U) & 0x7DE71840U) * 0x00210842ULL) >> 27; + int spacing = (int)v; + return col * colwidth + spacing; } static void CPUMeterCommonDraw(Meter* this, int x, int y, int w, int ncol) {