Skip to content

Commit 7ebc8e0

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 7ebc8e0

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

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: 33 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);
@@ -120,30 +132,50 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
120132
assert(startPos <= w);
121133
assert(startPos + w <= RichString_sizeVal(bar));
122134

135+
const Settings* settings = this->host->settings;
123136
int blockSizes[10];
124137

125138
// First draw in the bar[] buffer...
126139
int offset = 0;
140+
const wchar_t* barChars = &bars[settings->barType][1];
141+
const size_t barLen = wcslen(barChars);
142+
const uint8_t wsub = w * barLen;
143+
127144
for (uint8_t i = 0; i < this->curItems; i++) {
128145
double value = this->values[i];
146+
int actualWidth = 0;
147+
148+
// ignore extremely small values
149+
if ((value / this->total) * wsub < 0.5) {
150+
blockSizes[i] = 0;
151+
continue;
152+
}
129153
if (isPositive(value) && this->total > 0.0) {
130154
value = MINIMUM(value, this->total);
155+
actualWidth = ceil((value / this->total) * wsub);
131156
blockSizes[i] = ceil((value / this->total) * w);
132157
} else {
133158
blockSizes[i] = 0;
134159
}
135160
int nextOffset = offset + blockSizes[i];
136161
// (Control against invalid values)
137162
nextOffset = CLAMP(nextOffset, 0, w);
138-
for (int j = offset; j < nextOffset; j++)
163+
164+
for (int j = offset; j < nextOffset; j++){
139165
if (RichString_getCharVal(bar, startPos + j) == ' ') {
140166
if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
141167
assert(i < strlen(BarMeterMode_characters));
142168
RichString_setChar(&bar, startPos + j, BarMeterMode_characters[i]);
169+
} else if (settings->barType) {
170+
RichString_setChar(&bar, startPos + j, bars[settings->barType][8]);
143171
} else {
144172
RichString_setChar(&bar, startPos + j, '|');
145173
}
146174
}
175+
}
176+
177+
RichString_setChar(&bar, startPos + nextOffset-1, barChars[actualWidth % barLen]);
178+
147179
offset = nextOffset;
148180
}
149181

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)