diff options
author | Simon Howard | 2012-03-01 20:26:56 +0000 |
---|---|---|
committer | Simon Howard | 2012-03-01 20:26:56 +0000 |
commit | 9ffd1cc4d4bbd2b2799cbd0bf927fc4f30aed63e (patch) | |
tree | 06e5d3599db4c7bec3bcc032a241424d0bccc7e3 | |
parent | 920ffea9b631e712ff0826911db01a76edbe7521 (diff) | |
download | chocolate-doom-9ffd1cc4d4bbd2b2799cbd0bf927fc4f30aed63e.tar.gz chocolate-doom-9ffd1cc4d4bbd2b2799cbd0bf927fc4f30aed63e.tar.bz2 chocolate-doom-9ffd1cc4d4bbd2b2799cbd0bf927fc4f30aed63e.zip |
Rework the way that window background colors are set, and change the
background color of inactive windows to black, to give better contrast
when viewing many layered windows.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2507
-rw-r--r-- | textscreen/txt_checkbox.c | 1 | ||||
-rw-r--r-- | textscreen/txt_gui.c | 16 | ||||
-rw-r--r-- | textscreen/txt_gui.h | 6 | ||||
-rw-r--r-- | textscreen/txt_io.c | 12 | ||||
-rw-r--r-- | textscreen/txt_io.h | 8 | ||||
-rw-r--r-- | textscreen/txt_label.c | 14 | ||||
-rw-r--r-- | textscreen/txt_label.h | 4 | ||||
-rw-r--r-- | textscreen/txt_radiobutton.c | 1 | ||||
-rw-r--r-- | textscreen/txt_separator.c | 1 | ||||
-rw-r--r-- | textscreen/txt_spinctrl.c | 9 | ||||
-rw-r--r-- | textscreen/txt_widget.c | 12 | ||||
-rw-r--r-- | textscreen/txt_window.c | 14 | ||||
-rw-r--r-- | textscreen/txt_window_action.c | 4 |
13 files changed, 77 insertions, 25 deletions
diff --git a/textscreen/txt_checkbox.c b/textscreen/txt_checkbox.c index 8c3271cf..f8fb00bb 100644 --- a/textscreen/txt_checkbox.c +++ b/textscreen/txt_checkbox.c @@ -48,7 +48,6 @@ static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox)) w = checkbox->widget.w; - TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString("("); diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c index 30d43808..09ba87ef 100644 --- a/textscreen/txt_gui.c +++ b/textscreen/txt_gui.c @@ -173,11 +173,12 @@ void TXT_DrawShadow(int x, int y, int w, int h) void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h) { + txt_saved_colors_t colors; int x1, y1; int bx, by; + TXT_SaveColors(&colors); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); - TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); for (y1=y; y1<y+h; ++y1) { @@ -226,18 +227,21 @@ void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h) TXT_DrawShadow(x + 2, y + h, w, 1); TXT_DrawShadow(x + w, y + 1, 2, h); + + TXT_RestoreColors(&colors); } void TXT_DrawSeparator(int x, int y, int w) { + txt_saved_colors_t colors; unsigned char *data; int x1; int b; data = TXT_GetScreenData(); + TXT_SaveColors(&colors); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); - TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); if (!VALID_Y(y)) { @@ -268,6 +272,8 @@ void TXT_DrawSeparator(int x, int y, int w) data += 2; } + + TXT_RestoreColors(&colors); } void TXT_DrawString(const char *s) @@ -360,6 +366,7 @@ void TXT_DrawUTF8String(const char *s) void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range) { + txt_saved_colors_t colors; int x1; int cursor_x; @@ -368,6 +375,7 @@ void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range) return; } + TXT_SaveColors(&colors); TXT_FGColor(TXT_COLOR_BLACK); TXT_BGColor(TXT_COLOR_GREY, 0); @@ -402,10 +410,12 @@ void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range) } TXT_PutChar('\x1a'); + TXT_RestoreColors(&colors); } void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range) { + txt_saved_colors_t colors; int y1; int cursor_y; @@ -414,6 +424,7 @@ void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range) return; } + TXT_SaveColors(&colors); TXT_FGColor(TXT_COLOR_BLACK); TXT_BGColor(TXT_COLOR_GREY, 0); @@ -451,6 +462,7 @@ void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range) TXT_GotoXY(x, y + h - 1); TXT_PutChar('\x19'); + TXT_RestoreColors(&colors); } void TXT_InitClipArea(void) diff --git a/textscreen/txt_gui.h b/textscreen/txt_gui.h index 3aa6e629..e4504af8 100644 --- a/textscreen/txt_gui.h +++ b/textscreen/txt_gui.h @@ -27,8 +27,9 @@ #ifndef TXT_GUI_H #define TXT_GUI_H -#define TXT_WINDOW_BACKGROUND TXT_COLOR_BLUE -#define TXT_HOVER_BACKGROUND TXT_COLOR_CYAN +#define TXT_INACTIVE_WINDOW_BACKGROUND TXT_COLOR_BLACK +#define TXT_ACTIVE_WINDOW_BACKGROUND TXT_COLOR_BLUE +#define TXT_HOVER_BACKGROUND TXT_COLOR_CYAN void TXT_DrawDesktopBackground(const char *title); void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h); @@ -39,7 +40,6 @@ void TXT_DrawUTF8String(const char *s); void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range); void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range); - void TXT_InitClipArea(void); void TXT_PushClipArea(int x1, int x2, int y1, int y2); void TXT_PopClipArea(void); diff --git a/textscreen/txt_io.c b/textscreen/txt_io.c index 1ecc7bd6..08bb5ac9 100644 --- a/textscreen/txt_io.c +++ b/textscreen/txt_io.c @@ -238,6 +238,18 @@ void TXT_BGColor(int color, int blinking) bgcolor |= TXT_COLOR_BLINKING; } +void TXT_SaveColors(txt_saved_colors_t *save) +{ + save->bgcolor = bgcolor; + save->fgcolor = fgcolor; +} + +void TXT_RestoreColors(txt_saved_colors_t *save) +{ + bgcolor = save->bgcolor; + fgcolor = save->fgcolor; +} + void TXT_ClearScreen(void) { unsigned char *screen; diff --git a/textscreen/txt_io.h b/textscreen/txt_io.h index dc25aa93..004fa562 100644 --- a/textscreen/txt_io.h +++ b/textscreen/txt_io.h @@ -29,12 +29,20 @@ #include "txt_main.h" +typedef struct +{ + int bgcolor; + int fgcolor; +} txt_saved_colors_t; + void TXT_PutChar(int c); void TXT_Puts(const char *s); void TXT_GotoXY(int x, int y); void TXT_GetXY(int *x, int *y); void TXT_FGColor(txt_color_t color); void TXT_BGColor(int color, int blinking); +void TXT_SaveColors(txt_saved_colors_t *save); +void TXT_RestoreColors(txt_saved_colors_t *save); void TXT_ClearScreen(void); #endif /* #ifndef TXT_IO_H */ diff --git a/textscreen/txt_label.c b/textscreen/txt_label.c index c4238bf3..39ea0e16 100644 --- a/textscreen/txt_label.c +++ b/textscreen/txt_label.c @@ -47,8 +47,14 @@ static void TXT_LabelDrawer(TXT_UNCAST_ARG(label)) w = label->widget.w; - TXT_BGColor(label->bgcolor, 0); - TXT_FGColor(label->fgcolor); + if (label->bgcolor >= 0) + { + TXT_BGColor(label->bgcolor, 0); + } + if (label->fgcolor >= 0) + { + TXT_FGColor(label->fgcolor); + } TXT_GetXY(&origin_x, &origin_y); @@ -181,8 +187,8 @@ txt_label_t *TXT_NewLabel(char *text) // Default colors - label->bgcolor = TXT_WINDOW_BACKGROUND; - label->fgcolor = TXT_COLOR_BRIGHT_WHITE; + label->bgcolor = -1; + label->fgcolor = -1; TXT_SetLabel(label, text); diff --git a/textscreen/txt_label.h b/textscreen/txt_label.h index 16395c93..c0a20bf2 100644 --- a/textscreen/txt_label.h +++ b/textscreen/txt_label.h @@ -45,8 +45,8 @@ struct txt_label_s char *label; char **lines; unsigned int w, h; - txt_color_t fgcolor; - txt_color_t bgcolor; + int fgcolor; + int bgcolor; }; /** diff --git a/textscreen/txt_radiobutton.c b/textscreen/txt_radiobutton.c index 10f94ad3..3c3bb5dd 100644 --- a/textscreen/txt_radiobutton.c +++ b/textscreen/txt_radiobutton.c @@ -48,7 +48,6 @@ static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton)) w = radiobutton->widget.w; - TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString("("); diff --git a/textscreen/txt_separator.c b/textscreen/txt_separator.c index ce6e29ec..25d6f7bc 100644 --- a/textscreen/txt_separator.c +++ b/textscreen/txt_separator.c @@ -65,7 +65,6 @@ static void TXT_SeparatorDrawer(TXT_UNCAST_ARG(separator)) { TXT_GotoXY(x, y); - TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); TXT_FGColor(TXT_COLOR_BRIGHT_GREEN); TXT_DrawString(" "); TXT_DrawString(separator->label); diff --git a/textscreen/txt_spinctrl.c b/textscreen/txt_spinctrl.c index a4d20343..0b77805f 100644 --- a/textscreen/txt_spinctrl.c +++ b/textscreen/txt_spinctrl.c @@ -147,15 +147,17 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol)) TXT_CAST_ARG(txt_spincontrol_t, spincontrol); unsigned int i; unsigned int padding; + txt_saved_colors_t colors; int focused; focused = spincontrol->widget.focused; TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); - TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); TXT_DrawString("\x1b "); - + + TXT_SaveColors(&colors); + TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); // Choose background color @@ -193,8 +195,7 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol)) ++i; } - TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); - TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); + TXT_RestoreColors(&colors); TXT_DrawString(" \x1a"); } diff --git a/textscreen/txt_widget.c b/textscreen/txt_widget.c index 7d31ad68..e0303531 100644 --- a/textscreen/txt_widget.c +++ b/textscreen/txt_widget.c @@ -162,14 +162,22 @@ void TXT_CalcWidgetSize(TXT_UNCAST_ARG(widget)) void TXT_DrawWidget(TXT_UNCAST_ARG(widget)) { TXT_CAST_ARG(txt_widget_t, widget); + txt_saved_colors_t colors; + + // The drawing function might change the fg/bg colors, + // so make sure we restore them after it's done. + + TXT_SaveColors(&colors); // For convenience... TXT_GotoXY(widget->x, widget->y); // Call drawer method - + widget->widget_class->drawer(widget); + + TXT_RestoreColors(&colors); } void TXT_DestroyWidget(TXT_UNCAST_ARG(widget)) @@ -319,7 +327,7 @@ void TXT_SetWidgetBG(TXT_UNCAST_ARG(widget)) } else { - TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); + // Use normal window background. } } diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c index d33dd75b..b08ac658 100644 --- a/textscreen/txt_window.c +++ b/textscreen/txt_window.c @@ -26,6 +26,7 @@ #include "txt_desktop.h" #include "txt_gui.h" +#include "txt_io.h" #include "txt_main.h" #include "txt_separator.h" #include "txt_window.h" @@ -319,7 +320,18 @@ void TXT_DrawWindow(txt_window_t *window) txt_widget_t *widgets; TXT_LayoutWindow(window); - + + if (window->table.widget.focused) + { + TXT_BGColor(TXT_ACTIVE_WINDOW_BACKGROUND, 0); + } + else + { + TXT_BGColor(TXT_INACTIVE_WINDOW_BACKGROUND, 0); + } + + TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); + // Draw the window TXT_DrawWindowFrame(window->title, diff --git a/textscreen/txt_window_action.c b/textscreen/txt_window_action.c index cf5ac4a7..f195f06f 100644 --- a/textscreen/txt_window_action.c +++ b/textscreen/txt_window_action.c @@ -55,10 +55,6 @@ static void TXT_WindowActionDrawer(TXT_UNCAST_ARG(action)) { TXT_BGColor(TXT_COLOR_BLACK, 0); } - else - { - TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); - } TXT_DrawString(" "); TXT_FGColor(TXT_COLOR_BRIGHT_GREEN); |