summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2008-11-07 13:51:04 (GMT)
committer Jaromil <jaromil@dyne.org>2008-11-07 13:51:04 (GMT)
commit7e3d885d17737a15bed76bb59201d4d5092b24d3 (patch)
tree4cc792e6fc631e6b805341a5097bd5c347e8fb6c
parent0a1fbe195fa2abc837ea3e87b5656c3bd554d062 (diff)
colored widgets
-rw-r--r--cmdline.cpp8
-rw-r--r--slw/slw.cpp51
-rw-r--r--slw/slw.h7
-rw-r--r--slw/slw_console.cpp52
4 files changed, 110 insertions, 8 deletions
diff --git a/cmdline.cpp b/cmdline.cpp
index 4dbbe60..79611da 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -234,12 +234,14 @@ SLW_Text *status;
int record_console() {
// initialize the text console
- if(! con->init() ) return(-1);
+ assert( con->init() );
// initialize the status line
status->border = false;
+ status->set_color(21);
status->set_name("status box");
- if(! con->place(status, 0, con->h-10, con->w, con->h) ) {
+
+ if(! con->place(status, 0, con->h-1, con->w, con->h) ) {
error("error placing the status widget");
return(-1);
}
@@ -251,7 +253,7 @@ int record_console() {
// initialize the text canvas
txt->set_name("editor");
// txt->border = true;
- if(! con->place(txt, 0, 0, con->w, con->h-6) ) { // con->w, con->h-20) ) {
+ if(! con->place(txt, 0, 0, con->w, con->h-2) ) { // con->w, con->h-20) ) {
error("error placing the text widget");
return(-1);
}
diff --git a/slw/slw.cpp b/slw/slw.cpp
index 22755c0..133c13b 100644
--- a/slw/slw.cpp
+++ b/slw/slw.cpp
@@ -51,6 +51,8 @@ SLangWidget::SLangWidget()
// maximum lenght for a row
max_row = 512;
+
+ color = 1; // white on black
// generate a blank row for line blanking
@@ -109,6 +111,8 @@ bool SLangWidget::putch(CHAR ch, int x, int y) {
warning("putch called with invalid coords");
return false;
}
+
+ SLsmg_set_color(color);
SLsmg_gotorc( y + orig_y, x + orig_x );
SLsmg_write_char(ch);
@@ -166,9 +170,12 @@ int SLangWidget::putnch(CHAR *str, int x, int y, int nchars) {
} else // line fits in width
len = nchars;
+ SLsmg_set_color(color);
+
SLsmg_gotorc( y+orig_y, x+orig_x );
+
SLsmg_write_nchars( str, len );
-
+
return nwrap;
}
@@ -178,6 +185,8 @@ void SLangWidget::blank_row(int y) {
warning("blank_row failed: y=%u",y);
return;
}
+
+ SLsmg_set_color(color);
SLsmg_gotorc( y+orig_y, orig_x );
@@ -187,6 +196,7 @@ void SLangWidget::blank_row(int y) {
void SLangWidget::blank() {
register int c;
+ SLsmg_set_color(color);
for(c=h;c>=0;c--) {
SLsmg_gotorc( c+orig_y,orig_x);
SLsmg_write_nchars( blankrow, w);
@@ -214,3 +224,42 @@ bool SLangWidget::check(int x, int y) {
return true;
}
+void SLangWidget::set_color(int col) {
+ // check if color is valid
+ switch(col) {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 11:
+ case 12:
+ case 13:
+ case 14:
+ case 15:
+ case 16:
+ case 17:
+ case 21:
+ case 22:
+ case 23:
+ case 24:
+ case 25:
+ case 26:
+ case 27:
+ case 31:
+ case 32:
+ case 33:
+ case 34:
+ case 35:
+ case 36:
+ case 37:
+ func("color of widget %s set to %u",name, col);
+ color = col;
+ break;
+ default:
+ warning("invalid color %u selected for widget %s", col, name);
+ break;
+ }
+}
diff --git a/slw/slw.h b/slw/slw.h
index fd78639..b984aab 100644
--- a/slw/slw.h
+++ b/slw/slw.h
@@ -86,7 +86,12 @@ class SLangWidget : public Entry {
void blank();
///< blank the whole row in a widget
-
+
+ void set_color(int col);
+ /// colors are from 1 to 7, +10 highlight, +20 reverse, +30 highlight and reverse
+
+ int color;
+
// bool putrow(CHAR *str, int y);
///< draw a whole row at given height
diff --git a/slw/slw_console.cpp b/slw/slw_console.cpp
index 9627548..584ea23 100644
--- a/slw/slw_console.cpp
+++ b/slw/slw_console.cpp
@@ -72,7 +72,7 @@ SLangConsole::~SLangConsole() { close(); }
bool SLangConsole::init() {
- // setenv("TERM","xterm-color",0);
+ setenv("TERM","xterm-color",0);
SLtt_get_terminfo();
if( -1 == SLkp_init() ) { // keyboard interface
@@ -100,9 +100,53 @@ bool SLangConsole::init() {
// SLtt_Use_Ansi_Colors = 0;
// SLtt_Term_Cannot_Scroll = 0;
+ // set sizes of the whole console
w = SLtt_Screen_Cols;
h = SLtt_Screen_Rows;
+ /* setup colors with the palette scheme:
+ n = normal;
+ n+10 = highlight;
+ n+20 = reverse normal;
+ n+30 = reverse highlight; */
+
+ // crazy casting for crazy slang
+ SLtt_set_color(1,NULL,(char *)"lightgray",(char *)"black");
+ SLtt_set_color(11,NULL,(char *)"white",(char *)"black");
+ SLtt_set_color(21,NULL,(char *)"black",(char *)"lightgray");
+ SLtt_set_color(31,NULL,(char *)"black",(char *)"white");
+
+ SLtt_set_color(2,NULL,(char *)"red",(char *)"black");
+ SLtt_set_color(12,NULL,(char *)"brightred",(char *)"black");
+ SLtt_set_color(22,NULL,(char *)"black",(char *)"red");
+ SLtt_set_color(32,NULL,(char *)"black",(char *)"brightred");
+
+ SLtt_set_color(3,NULL,(char *)"green",(char *)"black");
+ SLtt_set_color(13,NULL,(char *)"brightgreen",(char *)"black");
+ SLtt_set_color(23,NULL,(char *)"black",(char *)"green");
+ SLtt_set_color(33,NULL,(char *)"black",(char *)"brightgreen");
+
+ SLtt_set_color(4,NULL,(char *)"brown",(char *)"black");
+ SLtt_set_color(14,NULL,(char *)"yellow",(char *)"black");
+ SLtt_set_color(24,NULL,(char *)"black",(char *)"brown");
+ SLtt_set_color(34,NULL,(char *)"black",(char *)"yellow");
+
+ SLtt_set_color(5,NULL,(char *)"blue",(char *)"black");
+ SLtt_set_color(15,NULL,(char *)"brightblue",(char *)"black");
+ SLtt_set_color(25,NULL,(char *)"black",(char *)"blue");
+ SLtt_set_color(35,NULL,(char *)"black",(char *)"brightblue");
+
+ SLtt_set_color(6,NULL,(char *)"magenta",(char *)"black");
+ SLtt_set_color(16,NULL,(char *)"brightmagenta",(char *)"black");
+ SLtt_set_color(26,NULL,(char *)"black",(char *)"magenta");
+ SLtt_set_color(36,NULL,(char *)"black",(char *)"brightmagenta");
+
+ SLtt_set_color(7,NULL,(char *)"cyan",(char *)"black");
+ SLtt_set_color(17,NULL,(char *)"brightcyan",(char *)"black");
+ SLtt_set_color(27,NULL,(char *)"black",(char *)"cyan");
+ SLtt_set_color(37,NULL,(char *)"black",(char *)"brightcyan");
+
+
refresh();
@@ -201,8 +245,10 @@ bool SLangConsole::refresh() {
SLangWidget *wid;
wid = (SLangWidget*) widgets.begin();
while(wid) {
- wid->refresh();
- wid = (SLangWidget*) wid->next;
+
+ wid->refresh();
+ wid = (SLangWidget*) wid->next;
+
}
}