From 5ffb9e600948ba59120aab87a84883091f50c21c 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 | 34 ++++++++++++++++++++++++++++++++-- Settings.h | 2 ++ 3 files changed, 35 insertions(+), 2 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..cbef7d101 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); @@ -124,26 +136,44 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { // First draw in the bar[] buffer... int offset = 0; + + const Settings* settings = this->host->settings; + const wchar_t* barChars = &bars[settings->barType][1]; + const size_t barLen = wcslen(barChars); + const size_t wsub = w * barLen; + for (uint8_t i = 0; i < this->curItems; i++) { double value = this->values[i]; - if (isPositive(value) && this->total > 0.0) { + int actualWidth = 0; + + if (isPositive(value) && this->total > 0.0 && (value * wsub > 0.5 * this->total)) { value = MINIMUM(value, this->total); + actualWidth = ceil((value / this->total) * wsub); blockSizes[i] = ceil((value / this->total) * w); } else { blockSizes[i] = 0; + continue; } + 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][barLen]); } else { RichString_setChar(&bar, startPos + j, '|'); } } + } + + RichString_setChar(&bar, startPos + nextOffset - 1, barChars[actualWidth % barLen]); + offset = nextOffset; } 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))