From 546915b825b3f70b9ff5fcaff84b64d658faa71f Mon Sep 17 00:00:00 2001 From: PM Date: Mon, 14 Oct 2024 12:39:30 +0530 Subject: [PATCH] adding different types of bars utf8 bars can be used by going into setup(F2) These bars enable subpixel rendering --- DisplayOptionsPanel.c | 1 + Meter.c | 41 +++++++++++++++++++++++++++++++++++++---- Settings.h | 2 ++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 8fa347294..a569ff9eb 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -156,6 +156,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef("Highlight new and old processes", &(settings->highlightChanges))); Panel_add(super, (Object*) NumberItem_newByRef("- Highlight time (in seconds)", &(settings->highlightDelaySecs), 0, 1, 24 * 60 * 60)); Panel_add(super, (Object*) NumberItem_newByRef("Hide main function bar (0 - off, 1 - on ESC until next input, 2 - permanently)", &(settings->hideFunctionBar), 0, 0, 2)); + Panel_add(super, (Object*) NumberItem_newByRef("Bar Type (0-7)", &(settings->barType), 0, 0, 7)); #ifdef HAVE_LIBHWLOC Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity))); #endif diff --git a/Meter.c b/Meter.c index 4463a90a0..0d375adfa 100644 --- a/Meter.c +++ b/Meter.c @@ -13,6 +13,7 @@ in the source distribution for its full text. #include #include #include +#include #include "CRT.h" #include "Macros.h" @@ -70,6 +71,17 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) { static const char BarMeterMode_characters[] = "|#*@$%&."; +static const wchar_t* bars[8] = { + L" ||||||||", + L" ########", + L"⠀⡀⡄⡆⡇⣇⣧⣷⣿", + L" ░░▒▒▓▓██", + L" ▏▎▍▌▋▊▉█", + L" ▁▂▃▄▅▆▇█", + L" ▌▌▌▌████", + L" ▔🮂🮃▀🮄🮅🮆█" +}; + static void BarMeterMode_draw(Meter* this, int x, int y, int w) { // Draw the caption const char* caption = Meter_getCaption(this); @@ -120,14 +132,27 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { assert(startPos <= w); assert(startPos + w <= RichString_sizeVal(bar)); + const Settings* settings = this->host->settings; int blockSizes[10]; // First draw in the bar[] buffer... int offset = 0; + const wchar_t* barChar = &bars[settings->barType][1]; + const uint8_t barLen = wcslen(barChar); + const uint8_t wsub = w * barLen; + for (uint8_t i = 0; i < this->curItems; i++) { double value = this->values[i]; + int actualWidth = 0; + + // ignore extremely small values + if((value / this->total) * wsub < 0.5){ + blockSizes[i] = 0; + continue; + } if (isPositive(value) && this->total > 0.0) { value = MINIMUM(value, this->total); + actualWidth = ceil((value / this->total) * wsub); blockSizes[i] = ceil((value / this->total) * w); } else { blockSizes[i] = 0; @@ -135,15 +160,23 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { int nextOffset = offset + blockSizes[i]; // (Control against invalid values) nextOffset = CLAMP(nextOffset, 0, w); - for (int j = offset; j < nextOffset; j++) + + + for (int j = offset; j < nextOffset; j++){ if (RichString_getCharVal(bar, startPos + j) == ' ') { if (CRT_colorScheme == COLORSCHEME_MONOCHROME) { assert(i < strlen(BarMeterMode_characters)); RichString_setChar(&bar, startPos + j, BarMeterMode_characters[i]); + } else if (settings->barType) { + RichString_setChar(&bar, startPos + j, bars[settings->barType][8]); } else { RichString_setChar(&bar, startPos + j, '|'); } } + } + + RichString_setChar(&bar, startPos + nextOffset-1, barChar[actualWidth % barLen]); + offset = nextOffset; } @@ -151,9 +184,9 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { offset = 0; for (uint8_t i = 0; i < this->curItems; i++) { int attr = this->curAttributes ? this->curAttributes[i] : Meter_attributes(this)[i]; - RichString_setAttrn(&bar, CRT_colors[attr], startPos + offset, blockSizes[i]); - RichString_printoffnVal(bar, y, x + offset, startPos + offset, MINIMUM(blockSizes[i], w - offset)); - offset += blockSizes[i]; + RichString_setAttrn(&bar, CRT_colors[attr], startPos + offset, ceil(blockSizes[i])); + RichString_printoffnVal(bar, y, x + offset, startPos + offset, MINIMUM(ceil(blockSizes[i]), w - offset)); + offset += ceil((double)blockSizes[i]); offset = CLAMP(offset, 0, w); } if (offset < w) { diff --git a/Settings.h b/Settings.h index 5d17fb346..389453333 100644 --- a/Settings.h +++ b/Settings.h @@ -111,6 +111,8 @@ typedef struct Settings_ { bool changed; uint64_t lastUpdate; + + int barType; } Settings; #define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromOne ? (cpu)+1 : (cpu))