From 7e4b9f81865ce98ae7ab1cc3696a7adb192df0cc Mon Sep 17 00:00:00 2001 From: Hisham Date: Wed, 23 Nov 2016 23:45:58 -0200 Subject: [PATCH] Double the resolution of the scroll bar --- CRT.c | 40 +++++++++++++++++++++++++++++++--------- Panel.c | 35 +++++++++++++++++++++++++---------- Structures.h | 12 ++++++++++-- configure.ac | 2 +- 4 files changed, 67 insertions(+), 22 deletions(-) diff --git a/CRT.c b/CRT.c index e735619..47fd7a2 100644 --- a/CRT.c +++ b/CRT.c @@ -52,6 +52,8 @@ typedef enum { DimColor, ScrollBarColor, ScrollHandleColor, + ScrollHandleTopColor, + ScrollHandleBottomColor, HeaderColor, StatusColor, KeyColor, @@ -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]; @@ -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]; @@ -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 @@ -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); @@ -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(); } diff --git a/Panel.c b/Panel.c index 61904d6..dfba9b2 100644 --- a/Panel.c +++ b/Panel.c @@ -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); } diff --git a/Structures.h b/Structures.h index 5e5dbe7..0263eec 100644 --- a/Structures.h +++ b/Structures.h @@ -289,6 +289,8 @@ typedef enum { DimColor, ScrollBarColor, ScrollHandleColor, + ScrollHandleTopColor, + ScrollHandleBottomColor, HeaderColor, StatusColor, KeyColor, @@ -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]; diff --git a/configure.ac b/configure.ac index 983a0b6..b133bc0 100644 --- a/configure.ac +++ b/configure.ac @@ -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