From: ewt Date: Sun, 31 Mar 1996 02:15:47 +0000 (+0000) Subject: Initial revision X-Git-Tag: 0-1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab3827f83426ffa4123f5c11168d3806dcd881c1;p=thirdparty%2Fnewt.git Initial revision --- diff --git a/scrollbar.c b/scrollbar.c new file mode 100644 index 0000000..66632dd --- /dev/null +++ b/scrollbar.c @@ -0,0 +1,95 @@ +#include +#include +#include + +#include "newt.h" +#include "newt_pr.h" + +struct scrollbar { + int curr; + int cs, csThumb; +} ; + +static void sbDraw(newtComponent co); +static void sbDestroy(newtComponent co); +static void sbDrawThumb(newtComponent co, int isOn); + +static struct componentOps sbOps = { + sbDraw, + newtDefaultEventHandler, + sbDestroy, +} ; + +void newtScrollbarSet(newtComponent co, int where, int total) { + struct scrollbar * sb = co->data; + int new; + + new = (where * (co->height - 1)) / total; + if (new != sb->curr) { + sbDrawThumb(co, 0); + sb->curr = new; + sbDrawThumb(co, 1); + } +} + +newtComponent newtVerticalScrollbar(int left, int top, int height, + int normalColorset, int thumbColorset) { + newtComponent co; + struct scrollbar * sb; + + co = malloc(sizeof(*co)); + sb = malloc(sizeof(*sb)); + co->data = sb; + + sb->curr = 0; + sb->cs = normalColorset; + sb->csThumb = thumbColorset; + + co->ops = &sbOps; + co->left = left; + co->top = top; + co->height = height; + co->width = 1; + co->takesFocus = 0; + + return co; +} + +static void sbDraw(newtComponent co) { + struct scrollbar * sb = co->data; + int i; + + SLsmg_set_color(sb->cs); + + SLsmg_set_char_set(1); + for (i = 0; i < co->height; i++) { + newtGotorc(i + co->top, co->left); + SLsmg_write_char('\150'); + } + + SLsmg_set_char_set(0); + + sbDrawThumb(co, 1); +} + +static void sbDrawThumb(newtComponent co, int isOn) { + struct scrollbar * sb = co->data; + + newtGotorc(sb->curr + co->top, co->left); + SLsmg_set_char_set(1); + + if (isOn) + SLsmg_set_color(sb->csThumb); + else + SLsmg_set_color(sb->cs); + + SLsmg_write_char('\150'); + SLsmg_set_char_set(0); +} + +static void sbDestroy(newtComponent co) { + struct scrollbar * sb = co->data; + + free(sb); + free(co); +}