Skip to content

Commit

Permalink
Double the resolution of the scroll bar
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Nov 24, 2016
1 parent d4884d0 commit 7e4b9f8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 22 deletions.
40 changes: 31 additions & 9 deletions CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ typedef enum {
DimColor,
ScrollBarColor,
ScrollHandleColor,
ScrollHandleTopColor,
ScrollHandleBottomColor,
HeaderColor,
StatusColor,
KeyColor,
Expand Down Expand Up @@ -101,11 +103,17 @@ typedef enum {
#define CTRL_MASK 4
#define ALTL_MASK 8
extern bool CRT_linuxConsole;
extern int CRT_delay;
extern char CRT_scrollHandle;
extern char* CRT_scrollHandle;
extern char* CRT_scrollHandleTop;
extern char* CRT_scrollHandleBottom;
extern char CRT_scrollBar;
extern char* CRT_scrollBar;
extern int CRT_colors[Colors];
Expand All @@ -121,9 +129,13 @@ bool CRT_hasColors;

int CRT_delay;

char CRT_scrollHandle;
char* CRT_scrollHandle;

char CRT_scrollBar;
char* CRT_scrollHandleTop;

char* CRT_scrollHandleBottom;

char* CRT_scrollBar;

int CRT_colors[Colors];

Expand Down Expand Up @@ -172,11 +184,15 @@ void CRT_init() {

CRT_hasColors = Display_init(term);
if (CRT_hasColors) {
CRT_scrollHandle = ' ';
CRT_scrollBar = ' ';
CRT_scrollHandle = strdup("█");
CRT_scrollHandleTop = strdup("▀");
CRT_scrollHandleBottom = strdup("▄");
CRT_scrollBar = strdup(" ");
} else {
CRT_scrollHandle = '*';
CRT_scrollBar = '|';
CRT_scrollHandle = strdup("*");
CRT_scrollHandleTop = strdup("*");
CRT_scrollHandleBottom = strdup("*");
CRT_scrollBar = strdup("|");
}

#define ANTARCTIC_THEME
Expand Down Expand Up @@ -204,7 +220,9 @@ void CRT_init() {
CRT_colors[VerySpecialColor] = A_BOLD | CRT_color(Yellow, Red);
CRT_colors[DimColor] = CRT_color(Yellow, Black);
CRT_colors[ScrollBarColor] = CRT_color(White, Blue);
CRT_colors[ScrollHandleColor] = CRT_color(White, Cyan);
CRT_colors[ScrollHandleColor] = CRT_color(Cyan, Blue);
CRT_colors[ScrollHandleTopColor] = CRT_color(Cyan, Blue);
CRT_colors[ScrollHandleBottomColor] = CRT_color(Cyan, Blue);
CRT_colors[StatusColor] = CRT_color(Black, Cyan);
CRT_colors[KeyColor] = A_REVERSE | CRT_color(Black, White);
CRT_colors[FieldColor] = CRT_color(White, Blue);
Expand Down Expand Up @@ -489,6 +507,10 @@ void CRT_init() {
}

void CRT_done() {
free(CRT_scrollHandle);
free(CRT_scrollHandleTop);
free(CRT_scrollHandleBottom);
free(CRT_scrollBar);
Hashtable_delete(CRT_keys);
Display_done();
}
Expand Down
35 changes: 25 additions & 10 deletions Panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,38 @@ void Panel_draw(Panel* this) {

/* paint scrollbar */
{
float step = (float)h / (float) itemCount ;
int handleHeight = ceil(step * (float)h);
int startAt = step * (float)this->scrollV;
int nBlocks = h * 2;
float linesPerBlock = (float)itemCount / (float)nBlocks;
int handleHeight = ceil((float)h / linesPerBlock);
int startAt = (float)this->scrollV / linesPerBlock;
Color bar = CRT_colors[ScrollBarColor];
Color handle = CRT_colors[ScrollHandleColor];
for (int i = 0; i < h; i++) {
char ch;
Color handleTop = CRT_colors[ScrollHandleTopColor];
Color handleBottom = CRT_colors[ScrollHandleBottomColor];
RichString_begin(barStr);
for (int i = 0; i < nBlocks; i += 2) {
bool set1 = false;
bool set2 = false;
if (i >= startAt && handleHeight) {
Display_attrset(handle);
ch = CRT_scrollHandle;
set1 = true;
handleHeight--;
}
if (i+1 >= startAt && handleHeight) {
set2 = true;
handleHeight--;
}
if (set1 && set2) {
RichString_write(&barStr, handle, CRT_scrollHandle);
} else if (set1) {
RichString_write(&barStr, handleTop, CRT_scrollHandleTop);
} else if (set2) {
RichString_write(&barStr, handleBottom, CRT_scrollHandleBottom);
} else {
Display_attrset(bar);
ch = CRT_scrollBar;
RichString_write(&barStr, bar, CRT_scrollBar);
}
Display_writeChAt(y + i, w, ch);
Display_writeChstrAtn(y + (i/2), w, RichString_at(barStr, 0), 1);
}
RichString_end(barStr);
Display_attrset(this->color);
}

Expand Down
12 changes: 10 additions & 2 deletions Structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ typedef enum {
DimColor,
ScrollBarColor,
ScrollHandleColor,
ScrollHandleTopColor,
ScrollHandleBottomColor,
HeaderColor,
StatusColor,
KeyColor,
Expand Down Expand Up @@ -338,11 +340,17 @@ typedef enum {
#define CTRL_MASK 4
#define ALTL_MASK 8

extern bool CRT_linuxConsole;

extern int CRT_delay;

extern char CRT_scrollHandle;
extern char* CRT_scrollHandle;

extern char* CRT_scrollHandleTop;

extern char* CRT_scrollHandleBottom;

extern char CRT_scrollBar;
extern char* CRT_scrollBar;

extern int CRT_colors[Colors];

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ then
enable_bundled_lua=yes
else
AX_LUA_HEADERS
AX_LUA_TRY_LIB_VERSION([501], [503], [], [enable_bundled_lua="yes"])
AX_LUA_TRY_LIB_VERSION([501], [504], [], [enable_bundled_lua="yes"])
fi
fi

Expand Down

0 comments on commit 7e4b9f8

Please sign in to comment.