From: Miroslav Lichvar Date: Wed, 18 May 2011 17:23:39 +0000 (+0200) Subject: allowing changing colors in individual labels, scrollbars, entries, scales X-Git-Tag: r0-52-13~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=099b22e5e57b20fa6cac92111eed8cdeacb2f4a3;p=thirdparty%2Fnewt.git allowing changing colors in individual labels, scrollbars, entries, scales --- diff --git a/entry.c b/entry.c index 5585ce5..a5ae688 100644 --- a/entry.c +++ b/entry.c @@ -23,6 +23,8 @@ struct entry { int firstChar; /* first character position being shown */ newtEntryFilter filter; void * filterData; + int cs; + int csDisabled; }; static int previous_char(const char *buf, int pos); @@ -117,6 +119,9 @@ newtComponent newtEntry(int left, int top, const char * initialValue, int width, en->cursorPosition = 0; } + en->cs = NEWT_COLORSET_ENTRY; + en->csDisabled = NEWT_COLORSET_DISENTRY; + return co; } @@ -184,9 +189,9 @@ static void entryDraw(newtComponent co) { if (!co->isMapped) return; if (en->flags & NEWT_FLAG_DISABLED) - SLsmg_set_color(NEWT_COLORSET_DISENTRY); + SLsmg_set_color(en->csDisabled); else - SLsmg_set_color(NEWT_COLORSET_ENTRY); + SLsmg_set_color(en->cs); if (en->flags & NEWT_FLAG_HIDDEN) { newtGotorc(co->top, co->left); @@ -255,6 +260,14 @@ void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense) { newtGotorc(row, col); } +void newtEntrySetColors(newtComponent co, int normal, int disabled) { + struct entry * en = co->data; + + en->cs = normal; + en->csDisabled = disabled; + entryDraw(co); +} + static void entryDestroy(newtComponent co) { struct entry * en = co->data; diff --git a/label.c b/label.c index bc9e510..85fa518 100644 --- a/label.c +++ b/label.c @@ -8,6 +8,7 @@ struct label { char * text; int length; + int cs; }; static void labelDraw(newtComponent co); @@ -41,6 +42,7 @@ newtComponent newtLabel(int left, int top, const char * text) { la->length = strlen(text); la->text = strdup(text); + la->cs = COLORSET_LABEL; return co; } @@ -63,12 +65,19 @@ void newtLabelSetText(newtComponent co, const char * text) { labelDraw(co); } +void newtLabelSetColors(newtComponent co, int colorset) { + struct label * la = co->data; + + la->cs = colorset; + labelDraw(co); +} + static void labelDraw(newtComponent co) { struct label * la = co->data; if (!co->isMapped) return; - SLsmg_set_color(COLORSET_LABEL); + SLsmg_set_color(la->cs); newtGotorc(co->top, co->left); SLsmg_write_string(la->text); diff --git a/newt.0.52.ver b/newt.0.52.ver index bad81e8..10ea1b1 100644 --- a/newt.0.52.ver +++ b/newt.0.52.ver @@ -152,3 +152,12 @@ NEWT_0.52.11 { global: newtRadioSetCurrent; } NEWT_0.52.9; + +NEWT_0.52.13 { + global: + newtEntrySetColors; + newtLabelSetColors; + newtScaleSetColors; + newtScrollbarSetColors; + newtTextboxSetColors; +} NEWT_0.52.11; diff --git a/newt.h b/newt.h index 81a57ca..103b139 100644 --- a/newt.h +++ b/newt.h @@ -161,9 +161,11 @@ void newtGetScreenSize(int * cols, int * rows); newtComponent newtLabel(int left, int top, const char * text); void newtLabelSetText(newtComponent co, const char * text); +void newtLabelSetColors(newtComponent co, int colorset); newtComponent newtVerticalScrollbar(int left, int top, int height, int normalColorset, int thumbColorset); void newtScrollbarSet(newtComponent co, int where, int total); +void newtScrollbarSetColors(newtComponent co, int normal, int thumb); newtComponent newtListbox(int left, int top, int height, int flags); void * newtListboxGetCurrent(newtComponent co); @@ -214,6 +216,7 @@ newtComponent newtTextbox(int left, int top, int width, int height, int flags); void newtTextboxSetText(newtComponent co, const char * text); void newtTextboxSetHeight(newtComponent co, int height); int newtTextboxGetNumLines(newtComponent co); +void newtTextboxSetColors(newtComponent co, int normal, int active); char * newtReflowText(char * text, int width, int flexDown, int flexUp, int * actualWidth, int * actualHeight); @@ -251,9 +254,11 @@ void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd); void newtEntrySetFilter(newtComponent co, newtEntryFilter filter, void * data); char * newtEntryGetValue(newtComponent co); void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense); +void newtEntrySetColors(newtComponent co, int normal, int disabled); newtComponent newtScale(int left, int top, int width, long long fullValue); void newtScaleSet(newtComponent co, unsigned long long amount); +void newtScaleSetColors(newtComponent co, int empty, int full); void newtComponentAddCallback(newtComponent co, newtCallback f, void * data); void newtComponentTakesFocus(newtComponent co, int val); diff --git a/scale.c b/scale.c index f9a1f40..3dbfca9 100644 --- a/scale.c +++ b/scale.c @@ -9,6 +9,8 @@ struct scale { long long fullValue; int charsSet; unsigned int percentage; + int csEmpty; + int csFull; }; static void scaleDraw(newtComponent co); @@ -41,6 +43,8 @@ newtComponent newtScale(int left, int top, int width, long long fullValue) { sc->fullValue = fullValue; sc->charsSet = 0; sc->percentage = 0; + sc->csEmpty = NEWT_COLORSET_EMPTYSCALE; + sc->csFull = NEWT_COLORSET_FULLSCALE; return co; } @@ -67,6 +71,14 @@ void newtScaleSet(newtComponent co, unsigned long long amount) { } } +void newtScaleSetColors(newtComponent co, int empty, int full) { + struct scale * sc = co->data; + + sc->csEmpty = empty; + sc->csFull = full; + scaleDraw(co); +} + static void scaleDraw(newtComponent co) { struct scale * sc = co->data; int i; @@ -79,11 +91,11 @@ static void scaleDraw(newtComponent co) { sprintf(percent, "%3d%%", sc->percentage); - SLsmg_set_color(NEWT_COLORSET_FULLSCALE); + SLsmg_set_color(sc->csFull); for (i = 0; i < co->width; i++) { if (i == sc->charsSet) - SLsmg_set_color(NEWT_COLORSET_EMPTYSCALE); + SLsmg_set_color(sc->csEmpty); if (i >= xlabel && i < xlabel+4) SLsmg_write_char(percent[i-xlabel]); else diff --git a/scrollbar.c b/scrollbar.c index b89ede2..0c706b3 100644 --- a/scrollbar.c +++ b/scrollbar.c @@ -69,6 +69,14 @@ newtComponent newtVerticalScrollbar(int left, int top, int height, return co; } +void newtScrollbarSetColors(newtComponent co, int normal, int thumb) { + struct scrollbar * sb = co->data; + + sb->cs = normal; + sb->csThumb = thumb; + sbDraw(co); +} + static void sbDraw(newtComponent co) { struct scrollbar * sb = co->data; int i; diff --git a/textbox.c b/textbox.c index 6429062..8bbd409 100644 --- a/textbox.c +++ b/textbox.c @@ -14,10 +14,12 @@ struct textbox { int numLines; int linesAlloced; int doWrap; - newtComponent sb_act, sb; + newtComponent sb; int topLine; int textWidth; int isActive; + int cs; + int csActive; }; static char * expandTabs(const char * text); @@ -45,7 +47,6 @@ static void textboxMapped(newtComponent co, int isMapped) { co->isMapped = isMapped; if (tb->sb) { tb->sb->ops->mapped(tb->sb, isMapped); - tb->sb_act->ops->mapped(tb->sb_act, isMapped); } } @@ -57,7 +58,6 @@ static void textboxPlace(newtComponent co, int newLeft, int newTop) { if (tb->sb) { tb->sb->ops->place(tb->sb, co->left + co->width - 1, co->top); - tb->sb_act->ops->place(tb->sb_act, co->left + co->width - 1, co->top); } } @@ -115,21 +115,29 @@ newtComponent newtTextbox(int left, int top, int width, int height, int flags) { tb->topLine = 0; tb->textWidth = width; tb->isActive = 0; + tb->cs = COLORSET_TEXTBOX; + tb->csActive = COLORSET_ACTTEXTBOX; if (flags & NEWT_FLAG_SCROLL) { co->width += 2; - tb->sb_act = newtVerticalScrollbar(co->left + co->width - 1, co->top, - co->height, COLORSET_ACTTEXTBOX, COLORSET_TEXTBOX); tb->sb = newtVerticalScrollbar(co->left + co->width - 1, co->top, - co->height, COLORSET_TEXTBOX, COLORSET_TEXTBOX); + co->height, tb->cs, tb->cs); co->takesFocus = 1; } else { - tb->sb_act = tb->sb = NULL; + tb->sb = NULL; } return co; } +void newtTextboxSetColors(newtComponent co, int normal, int active) { + struct textbox * tb = co->data; + + tb->cs = normal; + tb->csActive = active; + textboxDraw(co); +} + static char * expandTabs(const char * text) { int bufAlloced = strlen(text) + 40; char * buf, * dest; @@ -369,16 +377,12 @@ static void textboxDraw(newtComponent c) { if (tb->sb) { size = tb->numLines - c->height; - if (tb->isActive) { - newtScrollbarSet(tb->sb_act, tb->topLine, size ? size : 0); - tb->sb_act->ops->draw(tb->sb_act); - } else { - newtScrollbarSet(tb->sb, tb->topLine, size ? size : 0); - tb->sb->ops->draw(tb->sb); - } + newtScrollbarSet(tb->sb, tb->topLine, size ? size : 0); + newtScrollbarSetColors(tb->sb, tb->isActive ? tb->csActive : + tb->cs, tb->cs); } - SLsmg_set_color(NEWT_COLORSET_TEXTBOX); + SLsmg_set_color(tb->cs); for (i = 0; (i + tb->topLine) < tb->numLines && i < c->height; i++) { newtGotorc(c->top + i, c->left); @@ -469,8 +473,6 @@ static void textboxDestroy(newtComponent co) { if (tb->sb) tb->sb->ops->destroy(tb->sb); - if (tb->sb_act) - tb->sb_act->ops->destroy(tb->sb_act); for (i = 0; i < tb->numLines; i++) free(tb->lines[i]); free(tb->lines);