shithub: choc

Download patch

ref: 7ad4a11afac4b45bd556831ec49e320e2d77fdbe
parent: 148e9e53aab6e3db92eae3cf84f979ef5f8b6da9
author: Simon Howard <fraggle@soulsphere.org>
date: Sat Jan 21 12:15:00 EST 2017

textscreen: Make UTF8 the rule, not the exception.

Rename TXT_DrawString() to TXT_DrawCodePageString() and rename
TXT_DrawUTF8String() to TXT_DrawString(). It's better to just assume
everything is UTF8 and deal with the exceptions, as this is less likely
to cause bugs. There is only a small handful of places where we want to
draw a specific character from the native code page.

--- a/src/setup/txt_joyaxis.c
+++ b/src/setup/txt_joyaxis.c
@@ -459,7 +459,7 @@
     TXT_SetWidgetBG(joystick_axis);
     TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
 
-    TXT_DrawUTF8String(buf);
+    TXT_DrawString(buf);
 
     for (i = TXT_UTF8_Strlen(buf); i < joystick_axis->widget.w; ++i)
     {
--- a/src/setup/txt_joybinput.c
+++ b/src/setup/txt_joybinput.c
@@ -265,7 +265,7 @@
     TXT_SetWidgetBG(joystick_input);
     TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
 
-    TXT_DrawUTF8String(buf);
+    TXT_DrawString(buf);
 
     for (i = TXT_UTF8_Strlen(buf); i < JOYSTICK_INPUT_WIDTH; ++i)
     {
--- a/src/setup/txt_keyinput.c
+++ b/src/setup/txt_keyinput.c
@@ -115,7 +115,7 @@
     TXT_SetWidgetBG(key_input);
     TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
 
-    TXT_DrawUTF8String(buf);
+    TXT_DrawString(buf);
 
     for (i = TXT_UTF8_Strlen(buf); i < KEY_INPUT_WIDTH; ++i)
     {
--- a/src/setup/txt_mouseinput.c
+++ b/src/setup/txt_mouseinput.c
@@ -107,7 +107,7 @@
     TXT_SetWidgetBG(mouse_input);
     TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
     
-    TXT_DrawUTF8String(buf);
+    TXT_DrawString(buf);
     
     for (i = TXT_UTF8_Strlen(buf); i < MOUSE_INPUT_WIDTH; ++i)
     {
--- a/textscreen/txt_button.c
+++ b/textscreen/txt_button.c
@@ -42,7 +42,7 @@
 
     TXT_SetWidgetBG(button);
 
-    TXT_DrawUTF8String(button->label);
+    TXT_DrawString(button->label);
 
     for (i = TXT_UTF8_Strlen(button->label); i < w; ++i)
     {
--- a/textscreen/txt_checkbox.c
+++ b/textscreen/txt_checkbox.c
@@ -51,7 +51,7 @@
 
     if ((*checkbox->variable != 0) ^ checkbox->inverted)
     {
-        TXT_DrawString("\x07");
+        TXT_DrawCodePageString("\x07");
     }
     else
     {
@@ -64,7 +64,7 @@
 
     TXT_RestoreColors(&colors);
     TXT_SetWidgetBG(checkbox);
-    TXT_DrawUTF8String(checkbox->label);
+    TXT_DrawString(checkbox->label);
 
     for (i = TXT_UTF8_Strlen(checkbox->label); i < w-4; ++i)
     {
--- a/textscreen/txt_dropdown.c
+++ b/textscreen/txt_dropdown.c
@@ -239,7 +239,7 @@
 
     // Draw the string and fill to the end with spaces
 
-    TXT_DrawUTF8String(str);
+    TXT_DrawString(str);
 
     for (i = TXT_UTF8_Strlen(str); i < list->widget.w; ++i)
     {
--- a/textscreen/txt_fileselect.c
+++ b/textscreen/txt_fileselect.c
@@ -595,7 +595,7 @@
     fileselect->inputbox->widget.h = fileselect->widget.h;
 
     // Triple bar symbol gives a distinguishing look to the file selector.
-    TXT_DrawString("\xf0 ");
+    TXT_DrawCodePageString("\xf0 ");
     TXT_BGColor(TXT_COLOR_BLACK, 0);
     TXT_DrawWidget(fileselect->inputbox);
 }
--- a/textscreen/txt_gui.c
+++ b/textscreen/txt_gui.c
@@ -92,7 +92,7 @@
     TXT_BGColor(TXT_COLOR_GREY, 0);
 
     TXT_DrawString(" ");
-    TXT_DrawUTF8String(title);
+    TXT_DrawString(title);
 }
 
 void TXT_DrawShadow(int x, int y, int w, int h)
@@ -168,7 +168,7 @@
         }
     
         TXT_GotoXY(x + (w - TXT_UTF8_Strlen(title)) / 2, y + 1);
-        TXT_DrawUTF8String(title);
+        TXT_DrawString(title);
     }
 
     // Draw the window's shadow.
@@ -224,7 +224,9 @@
     TXT_RestoreColors(&colors);
 }
 
-void TXT_DrawString(const char *s)
+// Alternative to TXT_DrawString() where the argument is a "code page
+// string" - characters are in native code page format and not UTF-8.
+void TXT_DrawCodePageString(const char *s)
 {
     int x, y;
     int x1;
@@ -278,7 +280,7 @@
     }
 }
 
-void TXT_DrawUTF8String(const char *s)
+void TXT_DrawString(const char *s)
 {
     int x, y;
     int x1;
--- a/textscreen/txt_gui.h
+++ b/textscreen/txt_gui.h
@@ -25,8 +25,8 @@
 void TXT_DrawDesktopBackground(const char *title);
 void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h);
 void TXT_DrawSeparator(int x, int y, int w);
+void TXT_DrawCodePageString(const char *s);
 void TXT_DrawString(const char *s);
-void TXT_DrawUTF8String(const char *s);
 int TXT_CanDrawCharacter(unsigned int c);
 
 void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range);
--- a/textscreen/txt_inputbox.c
+++ b/textscreen/txt_inputbox.c
@@ -147,8 +147,8 @@
 
     if (TXT_UTF8_Strlen(inputbox->buffer) > w - 1)
     {
-        TXT_DrawString("\xae");
-        TXT_DrawUTF8String(
+        TXT_DrawCodePageString("\xae");
+        TXT_DrawString(
             TXT_UTF8_SkipChars(inputbox->buffer,
                                TXT_UTF8_Strlen(inputbox->buffer) - w + 2));
         chars = w - 1;
@@ -155,7 +155,7 @@
     }
     else
     {
-        TXT_DrawUTF8String(inputbox->buffer);
+        TXT_DrawString(inputbox->buffer);
         chars = TXT_UTF8_Strlen(inputbox->buffer);
     }
 
--- a/textscreen/txt_label.c
+++ b/textscreen/txt_label.c
@@ -82,7 +82,7 @@
 
         // The string itself
 
-        TXT_DrawUTF8String(label->lines[y]);
+        TXT_DrawString(label->lines[y]);
         x += sw;
 
         // Gap at the end
--- a/textscreen/txt_radiobutton.c
+++ b/textscreen/txt_radiobutton.c
@@ -51,7 +51,7 @@
 
     if (*radiobutton->variable == radiobutton->value)
     {
-        TXT_DrawString("\x07");
+        TXT_DrawCodePageString("\x07");
     }
     else
     {
@@ -65,7 +65,7 @@
     TXT_RestoreColors(&colors);
     TXT_SetWidgetBG(radiobutton);
 
-    TXT_DrawUTF8String(radiobutton->label);
+    TXT_DrawString(radiobutton->label);
 
     for (i=TXT_UTF8_Strlen(radiobutton->label); i < w-5; ++i)
     {
--- a/textscreen/txt_separator.c
+++ b/textscreen/txt_separator.c
@@ -61,7 +61,7 @@
 
         TXT_FGColor(TXT_COLOR_BRIGHT_GREEN);
         TXT_DrawString(" ");
-        TXT_DrawUTF8String(separator->label);
+        TXT_DrawString(separator->label);
         TXT_DrawString(" ");
     }
 }
--- a/textscreen/txt_spinctrl.c
+++ b/textscreen/txt_spinctrl.c
@@ -152,7 +152,7 @@
     TXT_SaveColors(&colors);
 
     TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
-    TXT_DrawString("\x1b ");
+    TXT_DrawCodePageString("\x1b ");
 
     TXT_RestoreColors(&colors);
 
@@ -183,7 +183,7 @@
         ++i;
     }
 
-    TXT_DrawUTF8String(spincontrol->buffer);
+    TXT_DrawString(spincontrol->buffer);
     i += bw;
 
     while (i < spincontrol->widget.w - 4)
@@ -194,7 +194,7 @@
 
     TXT_RestoreColors(&colors);
     TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
-    TXT_DrawString(" \x1a");
+    TXT_DrawCodePageString(" \x1a");
 }
 
 static void TXT_SpinControlDestructor(TXT_UNCAST_ARG(spincontrol))
--- a/textscreen/txt_window_action.c
+++ b/textscreen/txt_window_action.c
@@ -54,12 +54,12 @@
 
     TXT_DrawString(" ");
     TXT_FGColor(TXT_COLOR_BRIGHT_GREEN);
-    TXT_DrawUTF8String(buf);
+    TXT_DrawString(buf);
     TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
     TXT_DrawString("=");
 
     TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
-    TXT_DrawUTF8String(action->label);
+    TXT_DrawString(action->label);
     TXT_DrawString(" ");
 }