ref: 003c82ce37610a66bc61b9380fda6fd74223473b
parent: 9ffd1cc4d4bbd2b2799cbd0bf927fc4f30aed63e
author: Simon Howard <fraggle@gmail.com>
date: Sun Mar 4 07:06:29 EST 2012
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
--- a/textscreen/txt_button.c
+++ b/textscreen/txt_button.c
@@ -46,8 +46,6 @@
w = button->widget.w;
- TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
-
TXT_SetWidgetBG(button);
TXT_DrawString(button->label);
--- a/textscreen/txt_checkbox.c
+++ b/textscreen/txt_checkbox.c
@@ -43,11 +43,13 @@
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 @@
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(" ");
--- a/textscreen/txt_dropdown.c
+++ b/textscreen/txt_dropdown.c
@@ -215,7 +215,6 @@
// 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.
--- a/textscreen/txt_inputbox.c
+++ b/textscreen/txt_inputbox.c
@@ -132,8 +132,6 @@
TXT_SetWidgetBG(inputbox);
}
- TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
-
if (!inputbox->editing)
{
// If not editing, use the current value from inputbox->value.
--- 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 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_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');
--- a/textscreen/txt_radiobutton.c
+++ b/textscreen/txt_radiobutton.c
@@ -43,11 +43,13 @@
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 @@
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(" ");
--- a/textscreen/txt_spinctrl.c
+++ b/textscreen/txt_spinctrl.c
@@ -152,14 +152,13 @@
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_RestoreColors(&colors);
- TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
-
// Choose background color
if (focused && spincontrol->editing)
@@ -175,7 +174,7 @@
{
SetBuffer(spincontrol);
}
-
+
i = 0;
padding = spincontrol->widget.w - strlen(spincontrol->buffer) - 4;
@@ -196,6 +195,7 @@
}
TXT_RestoreColors(&colors);
+ TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString(" \x1a");
}