Skip to content

Commit 546915b

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 546915b

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

Diff for: DisplayOptionsPanel.c

+1
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

Diff for: Meter.c

+37-4
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,40 +132,61 @@ 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* barChar = &bars[settings->barType][1];
141+
const uint8_t barLen = wcslen(barChar);
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+
165+
for (int j = offset; j < nextOffset; j++){
139166
if (RichString_getCharVal(bar, startPos + j) == ' ') {
140167
if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
141168
assert(i < strlen(BarMeterMode_characters));
142169
RichString_setChar(&bar, startPos + j, BarMeterMode_characters[i]);
170+
} else if (settings->barType) {
171+
RichString_setChar(&bar, startPos + j, bars[settings->barType][8]);
143172
} else {
144173
RichString_setChar(&bar, startPos + j, '|');
145174
}
146175
}
176+
}
177+
178+
RichString_setChar(&bar, startPos + nextOffset-1, barChar[actualWidth % barLen]);
179+
147180
offset = nextOffset;
148181
}
149182

150183
// ...then print the buffer.
151184
offset = 0;
152185
for (uint8_t i = 0; i < this->curItems; i++) {
153186
int attr = this->curAttributes ? this->curAttributes[i] : Meter_attributes(this)[i];
154-
RichString_setAttrn(&bar, CRT_colors[attr], startPos + offset, blockSizes[i]);
155-
RichString_printoffnVal(bar, y, x + offset, startPos + offset, MINIMUM(blockSizes[i], w - offset));
156-
offset += blockSizes[i];
187+
RichString_setAttrn(&bar, CRT_colors[attr], startPos + offset, ceil(blockSizes[i]));
188+
RichString_printoffnVal(bar, y, x + offset, startPos + offset, MINIMUM(ceil(blockSizes[i]), w - offset));
189+
offset += ceil((double)blockSizes[i]);
157190
offset = CLAMP(offset, 0, w);
158191
}
159192
if (offset < w) {

Diff for: Settings.h

+2
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)