ref: 9ffd1cc4d4bbd2b2799cbd0bf927fc4f30aed63e
parent: 920ffea9b631e712ff0826911db01a76edbe7521
author: Simon Howard <[email protected]>
date: Thu Mar 1 15:26:56 EST 2012
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
--- a/textscreen/txt_checkbox.c
+++ b/textscreen/txt_checkbox.c
@@ -48,7 +48,6 @@
w = checkbox->widget.w;
- TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString("(");
--- a/textscreen/txt_gui.c
+++ b/textscreen/txt_gui.c
@@ -173,11 +173,12 @@
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,10 +227,13 @@
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;
@@ -236,8 +240,8 @@
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 @@
data += 2;
}
+
+ TXT_RestoreColors(&colors);
}
void TXT_DrawString(const char *s)
@@ -360,6 +366,7 @@
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 @@
return;
}
+ TXT_SaveColors(&colors);
TXT_FGColor(TXT_COLOR_BLACK);
TXT_BGColor(TXT_COLOR_GREY, 0);
@@ -402,10 +410,12 @@
}
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 @@
return;
}
+ TXT_SaveColors(&colors);
TXT_FGColor(TXT_COLOR_BLACK);
TXT_BGColor(TXT_COLOR_GREY, 0);
@@ -451,6 +462,7 @@
TXT_GotoXY(x, y + h - 1);
TXT_PutChar('\x19');
+ TXT_RestoreColors(&colors);
}
void TXT_InitClipArea(void)
--- 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);
@@ -38,7 +39,6 @@
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);
--- a/textscreen/txt_io.c
+++ b/textscreen/txt_io.c
@@ -238,6 +238,18 @@
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;
--- a/textscreen/txt_io.h
+++ b/textscreen/txt_io.h
@@ -29,6 +29,12 @@
#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);
@@ -35,6 +41,8 @@
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 */
--- a/textscreen/txt_label.c
+++ b/textscreen/txt_label.c
@@ -47,8 +47,14 @@
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 @@
// Default colors
- label->bgcolor = TXT_WINDOW_BACKGROUND;
- label->fgcolor = TXT_COLOR_BRIGHT_WHITE;
+ label->bgcolor = -1;
+ label->fgcolor = -1;
TXT_SetLabel(label, text);
--- a/textscreen/txt_label.h
+++ b/textscreen/txt_label.h
@@ -45,8 +45,8 @@
char *label;
char **lines;
unsigned int w, h;
- txt_color_t fgcolor;
- txt_color_t bgcolor;
+ int fgcolor;
+ int bgcolor;
};
/**
--- a/textscreen/txt_radiobutton.c
+++ b/textscreen/txt_radiobutton.c
@@ -48,7 +48,6 @@
w = radiobutton->widget.w;
- TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString("(");
--- a/textscreen/txt_separator.c
+++ b/textscreen/txt_separator.c
@@ -65,7 +65,6 @@
{
TXT_GotoXY(x, y);
- TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
TXT_FGColor(TXT_COLOR_BRIGHT_GREEN);
TXT_DrawString(" ");
TXT_DrawString(separator->label);
--- a/textscreen/txt_spinctrl.c
+++ b/textscreen/txt_spinctrl.c
@@ -147,15 +147,17 @@
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 @@
++i;
}
- TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
- TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
+ TXT_RestoreColors(&colors);
TXT_DrawString(" \x1a");
}
--- a/textscreen/txt_widget.c
+++ b/textscreen/txt_widget.c
@@ -162,14 +162,22 @@
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 @@
}
else
{
- TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
+ // Use normal window background.
}
}
--- 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 @@
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,
--- a/textscreen/txt_window_action.c
+++ b/textscreen/txt_window_action.c
@@ -55,10 +55,6 @@
{
TXT_BGColor(TXT_COLOR_BLACK, 0);
}
- else
- {
- TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
- }
TXT_DrawString(" ");
TXT_FGColor(TXT_COLOR_BRIGHT_GREEN);