Removed remaining SDL_mixer includes
[neverball] / ball / st_name.c
index 7e54a31..7b57d73 100644 (file)
  */
 
 #include <string.h>
+#include <ctype.h>
 
 #include "gui.h"
 #include "util.h"
 #include "audio.h"
 #include "config.h"
 #include "game.h"
+#include "text.h"
 
 #include "st_name.h"
 #include "st_shared.h"
@@ -50,14 +52,12 @@ static int name_id;
 
 static int name_action(int i)
 {
-    size_t l = strlen(player);
-
     audio_play(AUD_MENU, 1.0f);
 
     switch (i)
     {
     case NAME_OK:
-        if (l == 0)
+        if (strlen(player) == 0)
            return 1;
 
         config_set_s(CONFIG_PLAYER, player);
@@ -67,22 +67,18 @@ static int name_action(int i)
     case NAME_CANCEL:
         return goto_state(cancel_state);
 
+    case GUI_CL:
+        gui_keyboard_lock();
+        break;
+
     case GUI_BS:
-        if (l > 0)
-        {
-            player[l - 1] = '\0';
+        if (text_del_char(player))
             gui_set_label(name_id, player);
-        }
         break;
 
     default:
-        if (l < MAXNAM - 1)
-        {
-            player[l + 0] = (char) i;
-            player[l + 1] = '\0';
-
+        if (text_add_char(i, player, MAXNAM, 17))
             gui_set_label(name_id, player);
-        }
     }
     return 1;
 }
@@ -126,7 +122,7 @@ static void name_leave(int id)
 
 static int name_keybd(int c, int d)
 {
-    if (d && (c & 0xFF80) == 0)
+    if (d)
     {
         gui_focus(enter_id);
 
@@ -143,7 +139,13 @@ static int name_buttn(int b, int d)
     if (d)
     {
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
-            return name_action(gui_token(gui_click()));
+        {
+            int c = gui_token(gui_click());
+
+            /* Ugh.  This is such a hack. */
+
+            return name_action(isupper(c) ? gui_keyboard_char(c) : c);
+        }
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
             name_action(NAME_CANCEL);
     }