ref: 06dd83218590d383bba29acb6bbeaddc380bc6ae
parent: 8f5a4af76190c6dba1056d335073d98db23aabae
author: Simon Howard <fraggle@soulsphere.org>
date: Sat Jan 21 11:21:27 EST 2017
textscreen: Change most strings to UTF-8. If we are to accept arbitrary labels, window names etc., then it makes sense for these to be in UTF-8 format rather than strings in the code page extended ASCII format. This should make the API more interoperable with other data sources.
--- a/textscreen/txt_button.c
+++ b/textscreen/txt_button.c
@@ -21,6 +21,7 @@
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_main.h"
+#include "txt_utf8.h"
#include "txt_window.h"
static void TXT_ButtonSizeCalc(TXT_UNCAST_ARG(button))
@@ -27,7 +28,7 @@
{
TXT_CAST_ARG(txt_button_t, button);
- button->widget.w = strlen(button->label);
+ button->widget.w = TXT_UTF8_Strlen(button->label);
button->widget.h = 1;
}
@@ -41,9 +42,9 @@
TXT_SetWidgetBG(button);
- TXT_DrawString(button->label);
+ TXT_DrawUTF8String(button->label);
- for (i=strlen(button->label); i < w; ++i)
+ for (i = TXT_UTF8_Strlen(button->label); i < w; ++i)
{
TXT_DrawString(" ");
}
--- a/textscreen/txt_button.h
+++ b/textscreen/txt_button.h
@@ -41,7 +41,7 @@
/**
* Create a new button widget.
*
- * @param label The label to use on the new button.
+ * @param label The label to use on the new button (UTF-8 format).
* @return Pointer to the new button widget.
*/
@@ -51,7 +51,7 @@
* Create a new button widget, binding the "pressed" signal to a
* specified callback function.
*
- * @param label The label to use on the new button.
+ * @param label The label to use on the new button (UTF-8 format).
* @param func The callback function to invoke.
* @param user_data User-specified pointer to pass to the callback.
* @return Pointer to the new button widget.
@@ -64,7 +64,7 @@
* Change the label used on a button.
*
* @param button The button.
- * @param label The new label.
+ * @param label The new label (UTF-8 format).
*/
void TXT_SetButtonLabel(txt_button_t *button, char *label);
--- a/textscreen/txt_checkbox.c
+++ b/textscreen/txt_checkbox.c
@@ -21,6 +21,7 @@
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_main.h"
+#include "txt_utf8.h"
#include "txt_window.h"
static void TXT_CheckBoxSizeCalc(TXT_UNCAST_ARG(checkbox))
@@ -29,7 +30,7 @@
// Minimum width is the string length + right-side space for padding
- checkbox->widget.w = strlen(checkbox->label) + 5;
+ checkbox->widget.w = TXT_UTF8_Strlen(checkbox->label) + 5;
checkbox->widget.h = 1;
}
@@ -63,9 +64,9 @@
TXT_RestoreColors(&colors);
TXT_SetWidgetBG(checkbox);
- TXT_DrawString(checkbox->label);
+ TXT_DrawUTF8String(checkbox->label);
- for (i=strlen(checkbox->label); i < w-4; ++i)
+ for (i = TXT_UTF8_Strlen(checkbox->label); i < w-4; ++i)
{
TXT_DrawString(" ");
}
--- a/textscreen/txt_checkbox.h
+++ b/textscreen/txt_checkbox.h
@@ -49,7 +49,7 @@
/**
* Create a new checkbox.
*
- * @param label The label for the new checkbox.
+ * @param label The label for the new checkbox (UTF-8 format).
* @param variable Pointer to the variable containing this checkbox's
* value.
* @return Pointer to the new checkbox.
@@ -63,7 +63,7 @@
* An inverted checkbox displays the opposite of a normal checkbox;
* where it would be checked, it appears unchecked, and vice-versa.
*
- * @param label The label for the new checkbox.
+ * @param label The label for the new checkbox (UTF-8 format).
* @param variable Pointer to the variable containing this checkbox's
* value.
* @return Pointer to the new checkbox.
--- a/textscreen/txt_desktop.h
+++ b/textscreen/txt_desktop.h
@@ -36,7 +36,7 @@
/**
* Set the title displayed at the top of the screen.
*
- * @param title The title to display.
+ * @param title The title to display (UTF-8 format).
*/
void TXT_SetDesktopTitle(char *title);
--- a/textscreen/txt_dropdown.c
+++ b/textscreen/txt_dropdown.c
@@ -22,9 +22,10 @@
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_main.h"
+#include "txt_utf8.h"
#include "txt_window.h"
-typedef struct
+typedef struct
{
txt_window_t *window;
txt_dropdown_list_t *list;
@@ -196,7 +197,7 @@
for (i=0; i<list->num_values; ++i)
{
- int w = strlen(list->values[i]);
+ int w = TXT_UTF8_Strlen(list->values[i]);
if (w > result)
{
result = w;
@@ -238,9 +239,9 @@
// Draw the string and fill to the end with spaces
- TXT_DrawString(str);
+ TXT_DrawUTF8String(str);
- for (i=strlen(str); i<list->widget.w; ++i)
+ for (i = TXT_UTF8_Strlen(str); i < list->widget.w; ++i)
{
TXT_DrawString(" ");
}
--- a/textscreen/txt_dropdown.h
+++ b/textscreen/txt_dropdown.h
@@ -57,7 +57,7 @@
* @param variable Pointer to the variable containing the
* list's value.
* @param values Pointer to an array of strings containing
- * the labels to use for the list.
+ * the labels to use for the list (UTF-8 format).
* @param num_values The number of variables in the list.
*/
--- a/textscreen/txt_fileselect.h
+++ b/textscreen/txt_fileselect.h
@@ -56,7 +56,7 @@
* Create a new txt_fileselect_t widget.
*
* @param variable Pointer to a char * variable in which the selected
- * file should be stored.
+ * file should be stored (UTF-8 format).
* @param size Width of the file selector widget in characters.
* @param prompt Pointer to a string containing a prompt to display
* in the file selection window.
--- a/textscreen/txt_gui.c
+++ b/textscreen/txt_gui.c
@@ -92,7 +92,7 @@
TXT_BGColor(TXT_COLOR_GREY, 0);
TXT_DrawString(" ");
- TXT_DrawString(title);
+ TXT_DrawUTF8String(title);
}
void TXT_DrawShadow(int x, int y, int w, int h)
@@ -167,8 +167,8 @@
TXT_DrawString(" ");
}
- TXT_GotoXY(x + (w - strlen(title)) / 2, y + 1);
- TXT_DrawString(title);
+ TXT_GotoXY(x + (w - TXT_UTF8_Strlen(title)) / 2, y + 1);
+ TXT_DrawUTF8String(title);
}
// Draw the window's shadow.
--- a/textscreen/txt_inputbox.h
+++ b/textscreen/txt_inputbox.h
@@ -49,10 +49,11 @@
*
* @param value Pointer to a string variable that contains
* a pointer to the current value of the
- * input box. The value should be allocated
+ * input box. The value should be allocated
* dynamically; when the string is changed it
* will be freed and the variable set to point
- * to the new string value.
+ * to the new string value. String will be in
+ * UTF-8 format.
* @param size Width of the input box, in characters.
* @return Pointer to the new input box widget.
*/
--- a/textscreen/txt_label.c
+++ b/textscreen/txt_label.c
@@ -36,7 +36,7 @@
unsigned int x, y;
int origin_x, origin_y;
unsigned int align_indent = 0;
- unsigned int w;
+ unsigned int w, sw;
w = label->widget.w;
@@ -53,9 +53,9 @@
for (y=0; y<label->h; ++y)
{
- // Calculate the amount to indent this line due to the align
+ // Calculate the amount to indent this line due to the align
// setting
-
+ sw = TXT_UTF8_Strlen(label->lines[y]);
switch (label->widget.align)
{
case TXT_HORIZ_LEFT:
@@ -62,10 +62,10 @@
align_indent = 0;
break;
case TXT_HORIZ_CENTER:
- align_indent = (label->w - strlen(label->lines[y])) / 2;
+ align_indent = (label->w - sw) / 2;
break;
case TXT_HORIZ_RIGHT:
- align_indent = label->w - strlen(label->lines[y]);
+ align_indent = label->w - sw;
break;
}
@@ -83,7 +83,7 @@
// The string itself
TXT_DrawUTF8String(label->lines[y]);
- x += TXT_UTF8_Strlen(label->lines[y]);
+ x += sw;
// Gap at the end
--- a/textscreen/txt_label.h
+++ b/textscreen/txt_label.h
@@ -45,7 +45,7 @@
/**
* Create a new label widget.
*
- * @param label String to display in the widget.
+ * @param label String to display in the widget (UTF-8 format).
* @return Pointer to the new label widget.
*/
@@ -55,7 +55,7 @@
* Set the string displayed in a label widget.
*
* @param label The widget.
- * @param value The string to display.
+ * @param value The string to display (UTF-8 format).
*/
void TXT_SetLabel(txt_label_t *label, char *value);
--- a/textscreen/txt_main.h
+++ b/textscreen/txt_main.h
@@ -154,7 +154,7 @@
// keyboard (like that returned by TXT_INPUT_RAW), and the resulting string
// takes keyboard layout into consideration. For example,
// TXT_GetKeyDescription('q') on a French keyboard returns "A".
-// The contents of the filled buffer will be in UTF8 format, but will never
+// The contents of the filled buffer will be in UTF-8 format, but will never
// contain characters which can't be shown on the screen.
void TXT_GetKeyDescription(int key, char *buf, size_t buf_len);
--- a/textscreen/txt_radiobutton.c
+++ b/textscreen/txt_radiobutton.c
@@ -21,6 +21,7 @@
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_main.h"
+#include "txt_utf8.h"
#include "txt_window.h"
static void TXT_RadioButtonSizeCalc(TXT_UNCAST_ARG(radiobutton))
@@ -29,7 +30,7 @@
// Minimum width is the string length + right-side spaces for padding
- radiobutton->widget.w = strlen(radiobutton->label) + 5;
+ radiobutton->widget.w = TXT_UTF8_Strlen(radiobutton->label) + 5;
radiobutton->widget.h = 1;
}
@@ -64,9 +65,9 @@
TXT_RestoreColors(&colors);
TXT_SetWidgetBG(radiobutton);
- TXT_DrawString(radiobutton->label);
+ TXT_DrawUTF8String(radiobutton->label);
- for (i=strlen(radiobutton->label); i < w-5; ++i)
+ for (i=TXT_UTF8_Strlen(radiobutton->label); i < w-5; ++i)
{
TXT_DrawString(" ");
}
--- a/textscreen/txt_radiobutton.h
+++ b/textscreen/txt_radiobutton.h
@@ -54,7 +54,8 @@
/**
* Create a new radio button widget.
*
- * @param label The label to display next to the radio button.
+ * @param label The label to display next to the radio button
+ * (UTF-8 format).
* @param variable Pointer to the variable tracking whether this
* radio button is selected.
* @param value If the variable is equal to this value, the
@@ -68,7 +69,7 @@
* Set the label on a radio button.
*
* @param radiobutton The radio button.
- * @param value The new label.
+ * @param value The new label (UTF-8 format).
*/
void TXT_SetRadioButtonLabel(txt_radiobutton_t *radiobutton, char *value);
--- a/textscreen/txt_separator.c
+++ b/textscreen/txt_separator.c
@@ -19,6 +19,7 @@
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_main.h"
+#include "txt_utf8.h"
#include "txt_window.h"
static void TXT_SeparatorSizeCalc(TXT_UNCAST_ARG(separator))
@@ -29,7 +30,7 @@
{
// Minimum width is the string length + two spaces for padding
- separator->widget.w = strlen(separator->label) + 2;
+ separator->widget.w = TXT_UTF8_Strlen(separator->label) + 2;
}
else
{
@@ -53,7 +54,7 @@
// to overlap the window borders.
TXT_DrawSeparator(x-2, y, w + 4);
-
+
if (separator->label != NULL)
{
TXT_GotoXY(x, y);
@@ -60,7 +61,7 @@
TXT_FGColor(TXT_COLOR_BRIGHT_GREEN);
TXT_DrawString(" ");
- TXT_DrawString(separator->label);
+ TXT_DrawUTF8String(separator->label);
TXT_DrawString(" ");
}
}
--- a/textscreen/txt_separator.h
+++ b/textscreen/txt_separator.h
@@ -45,8 +45,8 @@
/**
* Create a new horizontal separator widget.
*
- * @param label Label to display on the separator. If this is
- * set to NULL, no label is displayed.
+ * @param label Label to display on the separator (UTF-8 format).
+ * If this is set to NULL, no label is displayed.
* @return The new separator widget.
*/
@@ -56,7 +56,7 @@
* Change the label on a separator.
*
* @param separator The separator.
- * @param label The new label.
+ * @param label The new label (UTF-8 format).
*/
void TXT_SetSeparatorLabel(txt_separator_t *separator, char *label);
--- a/textscreen/txt_spinctrl.c
+++ b/textscreen/txt_spinctrl.c
@@ -24,6 +24,7 @@
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_main.h"
+#include "txt_utf8.h"
#include "txt_window.h"
// Generate the format string to be used for displaying floats
@@ -143,6 +144,7 @@
unsigned int i;
unsigned int padding;
txt_saved_colors_t colors;
+ int bw;
int focused;
focused = spincontrol->widget.focused;
@@ -172,7 +174,8 @@
i = 0;
- padding = spincontrol->widget.w - strlen(spincontrol->buffer) - 4;
+ bw = TXT_UTF8_Strlen(spincontrol->buffer);
+ padding = spincontrol->widget.w - bw - 4;
while (i < padding)
{
@@ -180,8 +183,8 @@
++i;
}
- TXT_DrawString(spincontrol->buffer);
- i += strlen(spincontrol->buffer);
+ TXT_DrawUTF8String(spincontrol->buffer);
+ i += bw;
while (i < spincontrol->widget.w - 4)
{
@@ -203,7 +206,8 @@
static void AddCharacter(txt_spincontrol_t *spincontrol, int key)
{
- if (strlen(spincontrol->buffer) < SpinControlWidth(spincontrol))
+ if (TXT_UTF8_Strlen(spincontrol->buffer) < SpinControlWidth(spincontrol)
+ && strlen(spincontrol->buffer) < spincontrol->buffer_len - 2)
{
spincontrol->buffer[strlen(spincontrol->buffer) + 1] = '\0';
spincontrol->buffer[strlen(spincontrol->buffer)] = key;
@@ -212,7 +216,7 @@
static void Backspace(txt_spincontrol_t *spincontrol)
{
- if (strlen(spincontrol->buffer) > 0)
+ if (TXT_UTF8_Strlen(spincontrol->buffer) > 0)
{
spincontrol->buffer[strlen(spincontrol->buffer) - 1] = '\0';
}
--- a/textscreen/txt_window.h
+++ b/textscreen/txt_window.h
@@ -94,7 +94,8 @@
/**
* Open a new window.
*
- * @param title Title to display in the titlebar of the new window.
+ * @param title Title to display in the titlebar of the new window
+ * (UTF-8 format).
* @return Pointer to a new @ref txt_window_t structure
* representing the new window.
*/
@@ -191,8 +192,8 @@
/**
* Open a window displaying a message.
*
- * @param title Title of the window.
- * @param message The message to display in the window.
+ * @param title Title of the window (UTF-8 format).
+ * @param message The message to display in the window (UTF-8 format).
* @return The new window.
*/
--- a/textscreen/txt_window_action.c
+++ b/textscreen/txt_window_action.c
@@ -22,6 +22,7 @@
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_main.h"
+#include "txt_utf8.h"
#include "txt_window.h"
static void TXT_WindowActionSizeCalc(TXT_UNCAST_ARG(action))
@@ -34,7 +35,8 @@
// Width is label length, plus key description length, plus '='
// and two surrounding spaces.
- action->widget.w = strlen(action->label) + strlen(buf) + 3;
+ action->widget.w = TXT_UTF8_Strlen(action->label)
+ + TXT_UTF8_Strlen(buf) + 3;
action->widget.h = 1;
}
@@ -52,12 +54,12 @@
TXT_DrawString(" ");
TXT_FGColor(TXT_COLOR_BRIGHT_GREEN);
- TXT_DrawString(buf);
+ TXT_DrawUTF8String(buf);
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString("=");
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
- TXT_DrawString(action->label);
+ TXT_DrawUTF8String(action->label);
TXT_DrawString(" ");
}
--- a/textscreen/txt_window_action.h
+++ b/textscreen/txt_window_action.h
@@ -48,7 +48,7 @@
*
* @param key The keyboard key that triggers this action.
* @param label Label to display for this action in the tray
- * at the bottom of the window.
+ * at the bottom of the window (UTF-8 format).
* @return Pointer to the new window action widget.
*/