Skip to content

Commit db8ea97

Browse files
committed
adding different types of bars
utf8 bars can be used by going into setup(F2) These bars enable subpixel rendering
1 parent 4102862 commit db8ea97

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

DisplayOptionsPanel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
156156
Panel_add(super, (Object*) CheckItem_newByRef("Highlight new and old processes", &(settings->highlightChanges)));
157157
Panel_add(super, (Object*) NumberItem_newByRef("- Highlight time (in seconds)", &(settings->highlightDelaySecs), 0, 1, 24 * 60 * 60));
158158
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));
159+
Panel_add(super, (Object*) NumberItem_newByRef("Bar Type (0-7)", &(settings->barType), 0, 0, 7));
159160
#ifdef HAVE_LIBHWLOC
160161
Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
161162
#endif

Meter.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ in the source distribution for its full text.
1313
#include <math.h>
1414
#include <stdlib.h>
1515
#include <string.h>
16+
#include <wchar.h>
1617

1718
#include "CRT.h"
1819
#include "Macros.h"
@@ -70,6 +71,17 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
7071

7172
static const char BarMeterMode_characters[] = "|#*@$%&.";
7273

74+
static const wchar_t* bars[8] = {
75+
L" ||||||||",
76+
L" ########",
77+
L"⠀⡀⡄⡆⡇⣇⣧⣷⣿",
78+
L" ░░▒▒▓▓██",
79+
L" ▏▎▍▌▋▊▉█",
80+
L" ▁▂▃▄▅▆▇█",
81+
L" ▌▌▌▌████",
82+
L" ▔🮂🮃▀🮄🮅🮆█"
83+
};
84+
7385
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
7486
// Draw the caption
7587
const char* caption = Meter_getCaption(this);
@@ -124,26 +136,42 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
124136

125137
// First draw in the bar[] buffer...
126138
int offset = 0;
139+
140+
const Settings* settings = this->host->settings;
141+
const wchar_t* barChars = &bars[settings->barType][1];
142+
const size_t barLen = wcslen(barChars);
143+
const size_t wsub = w * barLen;
144+
127145
for (uint8_t i = 0; i < this->curItems; i++) {
128146
double value = this->values[i];
147+
int actualWidth = 0;
148+
129149
if (isPositive(value) && this->total > 0.0) {
130150
value = MINIMUM(value, this->total);
151+
actualWidth = ceil((value / this->total) * wsub);
131152
blockSizes[i] = ceil((value / this->total) * w);
132153
} else {
133154
blockSizes[i] = 0;
134155
}
135156
int nextOffset = offset + blockSizes[i];
136157
// (Control against invalid values)
137158
nextOffset = CLAMP(nextOffset, 0, w);
138-
for (int j = offset; j < nextOffset; j++)
159+
160+
for (int j = offset; j < nextOffset; j++) {
139161
if (RichString_getCharVal(bar, startPos + j) == ' ') {
140162
if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
141163
assert(i < strlen(BarMeterMode_characters));
142164
RichString_setChar(&bar, startPos + j, BarMeterMode_characters[i]);
165+
} else if (settings->barType) {
166+
RichString_setChar(&bar, startPos + j, bars[settings->barType][8]);
143167
} else {
144168
RichString_setChar(&bar, startPos + j, '|');
145169
}
146170
}
171+
}
172+
173+
RichString_setChar(&bar, startPos + nextOffset - 1, barChars[actualWidth % barLen]);
174+
147175
offset = nextOffset;
148176
}
149177

Settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ typedef struct Settings_ {
111111

112112
bool changed;
113113
uint64_t lastUpdate;
114+
115+
int barType;
114116
} Settings;
115117

116118
#define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromOne ? (cpu)+1 : (cpu))

0 commit comments

Comments
 (0)