From 7ad4a11afac4b45bd556831ec49e320e2d77fdbe Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 21 Jan 2017 17:15:00 +0000 Subject: [PATCH] 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. --- src/setup/txt_joyaxis.c | 2 +- src/setup/txt_joybinput.c | 2 +- src/setup/txt_keyinput.c | 2 +- src/setup/txt_mouseinput.c | 2 +- textscreen/txt_button.c | 2 +- textscreen/txt_checkbox.c | 4 ++-- textscreen/txt_dropdown.c | 2 +- textscreen/txt_fileselect.c | 2 +- textscreen/txt_gui.c | 10 ++++++---- textscreen/txt_gui.h | 2 +- textscreen/txt_inputbox.c | 6 +++--- textscreen/txt_label.c | 2 +- textscreen/txt_radiobutton.c | 4 ++-- textscreen/txt_separator.c | 2 +- textscreen/txt_spinctrl.c | 6 +++--- textscreen/txt_window_action.c | 4 ++-- 16 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/setup/txt_joyaxis.c b/src/setup/txt_joyaxis.c index c08768d7..3e2119d4 100644 --- a/src/setup/txt_joyaxis.c +++ b/src/setup/txt_joyaxis.c @@ -459,7 +459,7 @@ static void TXT_JoystickAxisDrawer(TXT_UNCAST_ARG(joystick_axis)) 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) { diff --git a/src/setup/txt_joybinput.c b/src/setup/txt_joybinput.c index ca23e4f0..967118d0 100644 --- a/src/setup/txt_joybinput.c +++ b/src/setup/txt_joybinput.c @@ -265,7 +265,7 @@ static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input)) 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) { diff --git a/src/setup/txt_keyinput.c b/src/setup/txt_keyinput.c index c2d54552..6c3b3591 100644 --- a/src/setup/txt_keyinput.c +++ b/src/setup/txt_keyinput.c @@ -115,7 +115,7 @@ static void TXT_KeyInputDrawer(TXT_UNCAST_ARG(key_input)) 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) { diff --git a/src/setup/txt_mouseinput.c b/src/setup/txt_mouseinput.c index b3891b52..21f73072 100644 --- a/src/setup/txt_mouseinput.c +++ b/src/setup/txt_mouseinput.c @@ -107,7 +107,7 @@ static void TXT_MouseInputDrawer(TXT_UNCAST_ARG(mouse_input)) 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) { diff --git a/textscreen/txt_button.c b/textscreen/txt_button.c index 793352f6..8865e1a4 100644 --- a/textscreen/txt_button.c +++ b/textscreen/txt_button.c @@ -42,7 +42,7 @@ static void TXT_ButtonDrawer(TXT_UNCAST_ARG(button)) TXT_SetWidgetBG(button); - TXT_DrawUTF8String(button->label); + TXT_DrawString(button->label); for (i = TXT_UTF8_Strlen(button->label); i < w; ++i) { diff --git a/textscreen/txt_checkbox.c b/textscreen/txt_checkbox.c index 57256d93..8610c719 100644 --- a/textscreen/txt_checkbox.c +++ b/textscreen/txt_checkbox.c @@ -51,7 +51,7 @@ static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox)) if ((*checkbox->variable != 0) ^ checkbox->inverted) { - TXT_DrawString("\x07"); + TXT_DrawCodePageString("\x07"); } else { @@ -64,7 +64,7 @@ static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox)) 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) { diff --git a/textscreen/txt_dropdown.c b/textscreen/txt_dropdown.c index a342b70a..5d72bf71 100644 --- a/textscreen/txt_dropdown.c +++ b/textscreen/txt_dropdown.c @@ -239,7 +239,7 @@ static void TXT_DropdownListDrawer(TXT_UNCAST_ARG(list)) // 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) { diff --git a/textscreen/txt_fileselect.c b/textscreen/txt_fileselect.c index c9740725..fd3c488f 100644 --- a/textscreen/txt_fileselect.c +++ b/textscreen/txt_fileselect.c @@ -595,7 +595,7 @@ static void TXT_FileSelectDrawer(TXT_UNCAST_ARG(fileselect)) 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); } diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c index 567e2794..a80bd850 100644 --- a/textscreen/txt_gui.c +++ b/textscreen/txt_gui.c @@ -92,7 +92,7 @@ void TXT_DrawDesktopBackground(const char *title) 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 @@ void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h) } 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 @@ void TXT_DrawSeparator(int x, int y, int w) 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 @@ static void PutUnicodeChar(unsigned int c) } } -void TXT_DrawUTF8String(const char *s) +void TXT_DrawString(const char *s) { int x, y; int x1; diff --git a/textscreen/txt_gui.h b/textscreen/txt_gui.h index f745ddd2..85920922 100644 --- 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); diff --git a/textscreen/txt_inputbox.c b/textscreen/txt_inputbox.c index 923bda9c..08054115 100644 --- a/textscreen/txt_inputbox.c +++ b/textscreen/txt_inputbox.c @@ -147,15 +147,15 @@ static void TXT_InputBoxDrawer(TXT_UNCAST_ARG(inputbox)) 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; } else { - TXT_DrawUTF8String(inputbox->buffer); + TXT_DrawString(inputbox->buffer); chars = TXT_UTF8_Strlen(inputbox->buffer); } diff --git a/textscreen/txt_label.c b/textscreen/txt_label.c index 25975585..e1f845cb 100644 --- a/textscreen/txt_label.c +++ b/textscreen/txt_label.c @@ -82,7 +82,7 @@ static void TXT_LabelDrawer(TXT_UNCAST_ARG(label)) // The string itself - TXT_DrawUTF8String(label->lines[y]); + TXT_DrawString(label->lines[y]); x += sw; // Gap at the end diff --git a/textscreen/txt_radiobutton.c b/textscreen/txt_radiobutton.c index aaeaa515..e165ff2c 100644 --- a/textscreen/txt_radiobutton.c +++ b/textscreen/txt_radiobutton.c @@ -51,7 +51,7 @@ static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton)) if (*radiobutton->variable == radiobutton->value) { - TXT_DrawString("\x07"); + TXT_DrawCodePageString("\x07"); } else { @@ -65,7 +65,7 @@ static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton)) 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) { diff --git a/textscreen/txt_separator.c b/textscreen/txt_separator.c index a8a2c5f4..d5b9562e 100644 --- a/textscreen/txt_separator.c +++ b/textscreen/txt_separator.c @@ -61,7 +61,7 @@ static void TXT_SeparatorDrawer(TXT_UNCAST_ARG(separator)) TXT_FGColor(TXT_COLOR_BRIGHT_GREEN); TXT_DrawString(" "); - TXT_DrawUTF8String(separator->label); + TXT_DrawString(separator->label); TXT_DrawString(" "); } } diff --git a/textscreen/txt_spinctrl.c b/textscreen/txt_spinctrl.c index 04838ec1..465e4e4a 100644 --- a/textscreen/txt_spinctrl.c +++ b/textscreen/txt_spinctrl.c @@ -152,7 +152,7 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol)) TXT_SaveColors(&colors); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); - TXT_DrawString("\x1b "); + TXT_DrawCodePageString("\x1b "); TXT_RestoreColors(&colors); @@ -183,7 +183,7 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol)) ++i; } - TXT_DrawUTF8String(spincontrol->buffer); + TXT_DrawString(spincontrol->buffer); i += bw; while (i < spincontrol->widget.w - 4) @@ -194,7 +194,7 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol)) TXT_RestoreColors(&colors); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); - TXT_DrawString(" \x1a"); + TXT_DrawCodePageString(" \x1a"); } static void TXT_SpinControlDestructor(TXT_UNCAST_ARG(spincontrol)) diff --git a/textscreen/txt_window_action.c b/textscreen/txt_window_action.c index 750c43eb..eca0119e 100644 --- a/textscreen/txt_window_action.c +++ b/textscreen/txt_window_action.c @@ -54,12 +54,12 @@ static void TXT_WindowActionDrawer(TXT_UNCAST_ARG(action)) 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(" "); }