summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2012-03-04 12:06:29 +0000
committerSimon Howard2012-03-04 12:06:29 +0000
commit003c82ce37610a66bc61b9380fda6fd74223473b (patch)
tree6e6a6bbc0f767ff938e2667d9a8b79d27fb2b87b
parent9ffd1cc4d4bbd2b2799cbd0bf927fc4f30aed63e (diff)
downloadchocolate-doom-003c82ce37610a66bc61b9380fda6fd74223473b.tar.gz
chocolate-doom-003c82ce37610a66bc61b9380fda6fd74223473b.tar.bz2
chocolate-doom-003c82ce37610a66bc61b9380fda6fd74223473b.zip
Remove some calls to TXT_FGColor by using the new TXT_SaveColors system
instead. Remove the unused "embedded color code" system from TXT_Puts. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 2508
-rw-r--r--textscreen/txt_button.c2
-rw-r--r--textscreen/txt_checkbox.c7
-rw-r--r--textscreen/txt_dropdown.c1
-rw-r--r--textscreen/txt_inputbox.c2
-rw-r--r--textscreen/txt_io.c94
-rw-r--r--textscreen/txt_radiobutton.c6
-rw-r--r--textscreen/txt_spinctrl.c10
7 files changed, 15 insertions, 107 deletions
diff --git a/textscreen/txt_button.c b/textscreen/txt_button.c
index 989bd4fc..c8e3fc77 100644
--- a/textscreen/txt_button.c
+++ b/textscreen/txt_button.c
@@ -46,8 +46,6 @@ static void TXT_ButtonDrawer(TXT_UNCAST_ARG(button))
w = button->widget.w;
- TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
-
TXT_SetWidgetBG(button);
TXT_DrawString(button->label);
diff --git a/textscreen/txt_checkbox.c b/textscreen/txt_checkbox.c
index f8fb00bb..3bd0a054 100644
--- a/textscreen/txt_checkbox.c
+++ b/textscreen/txt_checkbox.c
@@ -43,11 +43,13 @@ static void TXT_CheckBoxSizeCalc(TXT_UNCAST_ARG(checkbox))
static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox))
{
TXT_CAST_ARG(txt_checkbox_t, checkbox);
+ txt_saved_colors_t colors;
int i;
int w;
w = checkbox->widget.w;
+ TXT_SaveColors(&colors);
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString("(");
@@ -66,11 +68,10 @@ static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox))
TXT_DrawString(") ");
+ TXT_RestoreColors(&colors);
TXT_SetWidgetBG(checkbox);
- TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
-
TXT_DrawString(checkbox->label);
-
+
for (i=strlen(checkbox->label); i < w-5; ++i)
{
TXT_DrawString(" ");
diff --git a/textscreen/txt_dropdown.c b/textscreen/txt_dropdown.c
index 0856fb4e..d88716b5 100644
--- a/textscreen/txt_dropdown.c
+++ b/textscreen/txt_dropdown.c
@@ -215,7 +215,6 @@ static void TXT_DropdownListDrawer(TXT_UNCAST_ARG(list))
// Set bg/fg text colors.
TXT_SetWidgetBG(list);
- TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
// Select a string to draw from the list, if the current value is
// in range. Otherwise fall back to a default.
diff --git a/textscreen/txt_inputbox.c b/textscreen/txt_inputbox.c
index d5ad440a..0f2986cc 100644
--- a/textscreen/txt_inputbox.c
+++ b/textscreen/txt_inputbox.c
@@ -132,8 +132,6 @@ static void TXT_InputBoxDrawer(TXT_UNCAST_ARG(inputbox))
TXT_SetWidgetBG(inputbox);
}
- TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
-
if (!inputbox->editing)
{
// If not editing, use the current value from inputbox->value.
diff --git a/textscreen/txt_io.c b/textscreen/txt_io.c
index 08bb5ac9..f7c9a7a4 100644
--- a/textscreen/txt_io.c
+++ b/textscreen/txt_io.c
@@ -30,48 +30,10 @@
#include "txt_io.h"
#include "txt_main.h"
-static struct
-{
- txt_color_t color;
- const char *name;
-} colors[] = {
- {TXT_COLOR_BLACK, "black"},
- {TXT_COLOR_BLUE, "blue"},
- {TXT_COLOR_GREEN, "green"},
- {TXT_COLOR_CYAN, "cyan"},
- {TXT_COLOR_RED, "red"},
- {TXT_COLOR_MAGENTA, "magenta"},
- {TXT_COLOR_BROWN, "brown"},
- {TXT_COLOR_GREY, "grey"},
- {TXT_COLOR_DARK_GREY, "darkgrey"},
- {TXT_COLOR_BRIGHT_BLUE, "brightblue"},
- {TXT_COLOR_BRIGHT_GREEN, "brightgreen"},
- {TXT_COLOR_BRIGHT_CYAN, "brightcyan"},
- {TXT_COLOR_BRIGHT_RED, "brightred"},
- {TXT_COLOR_BRIGHT_MAGENTA, "brightmagenta"},
- {TXT_COLOR_YELLOW, "yellow"},
- {TXT_COLOR_BRIGHT_WHITE, "brightwhite"},
-};
-
static int cur_x = 0, cur_y = 0;
static txt_color_t fgcolor = TXT_COLOR_GREY;
static txt_color_t bgcolor = TXT_COLOR_BLACK;
-static int GetColorForName(char *s)
-{
- size_t i;
-
- for (i=0; i<sizeof(colors) / sizeof(*colors); ++i)
- {
- if (!strcmp(s, colors[i].name))
- {
- return colors[i].color;
- }
- }
-
- return -1;
-}
-
static void NewLine(unsigned char *screendata)
{
int i;
@@ -104,7 +66,7 @@ static void NewLine(unsigned char *screendata)
static void PutChar(unsigned char *screendata, int c)
{
unsigned char *p;
-
+
p = screendata + cur_y * TXT_SCREEN_W * 2 + cur_x * 2;
switch (c)
@@ -149,66 +111,14 @@ void TXT_PutChar(int c)
void TXT_Puts(const char *s)
{
- int previous_color = TXT_COLOR_BLACK;
unsigned char *screen;
const char *p;
- char colorname_buf[20];
- char *ending;
- int col;
screen = TXT_GetScreenData();
for (p=s; *p != '\0'; ++p)
{
- if (*p == '<')
- {
- ++p;
-
- if (*p == '<')
- {
- PutChar(screen, '<');
- }
- else
- {
- ending = strchr(p, '>');
-
- if (ending == NULL)
- {
- return;
- }
-
- strncpy(colorname_buf, p, 19);
- colorname_buf[ending-p] = '\0';
-
- if (!strcmp(colorname_buf, "/"))
- {
- // End of color block
-
- col = previous_color;
- }
- else
- {
- col = GetColorForName(colorname_buf);
-
- if (col < 0)
- {
- return;
- }
-
- // Save the color for the ending marker
-
- previous_color = fgcolor;
- }
-
- TXT_FGColor(col);
-
- p = ending;
- }
- }
- else
- {
- PutChar(screen, *p);
- }
+ PutChar(screen, *p);
}
PutChar(screen, '\n');
diff --git a/textscreen/txt_radiobutton.c b/textscreen/txt_radiobutton.c
index 3c3bb5dd..fa722c13 100644
--- a/textscreen/txt_radiobutton.c
+++ b/textscreen/txt_radiobutton.c
@@ -43,11 +43,13 @@ static void TXT_RadioButtonSizeCalc(TXT_UNCAST_ARG(radiobutton))
static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton))
{
TXT_CAST_ARG(txt_radiobutton_t, radiobutton);
+ txt_saved_colors_t colors;
int i;
int w;
w = radiobutton->widget.w;
+ TXT_SaveColors(&colors);
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString("(");
@@ -66,11 +68,11 @@ static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton))
TXT_DrawString(") ");
+ TXT_RestoreColors(&colors);
TXT_SetWidgetBG(radiobutton);
- TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
TXT_DrawString(radiobutton->label);
-
+
for (i=strlen(radiobutton->label); i < w-5; ++i)
{
TXT_DrawString(" ");
diff --git a/textscreen/txt_spinctrl.c b/textscreen/txt_spinctrl.c
index 0b77805f..1015ece5 100644
--- a/textscreen/txt_spinctrl.c
+++ b/textscreen/txt_spinctrl.c
@@ -152,13 +152,12 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol))
focused = spincontrol->widget.focused;
- TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
+ TXT_SaveColors(&colors);
+ TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString("\x1b ");
- TXT_SaveColors(&colors);
-
- TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
+ TXT_RestoreColors(&colors);
// Choose background color
@@ -175,7 +174,7 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol))
{
SetBuffer(spincontrol);
}
-
+
i = 0;
padding = spincontrol->widget.w - strlen(spincontrol->buffer) - 4;
@@ -196,6 +195,7 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol))
}
TXT_RestoreColors(&colors);
+ TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString(" \x1a");
}