Skip to content

Commit

Permalink
adding different types of bars
Browse files Browse the repository at this point in the history
utf8 bars can be used by going into setup(F2) These bars enable subpixel rendering
  • Loading branch information
rustedusted committed Oct 17, 2024
1 parent 4102862 commit 5ffb9e6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions DisplayOptionsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 32 additions & 2 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ in the source distribution for its full text.
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>

#include "CRT.h"
#include "Macros.h"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 5ffb9e6

Please sign in to comment.