shithub: choc

Download patch

ref: cc87c97e4bae07238e9e1af8668944fd7805c133
parent: 8ee96dadb97afad79ce77eef6da94a67db6be62b
author: Simon Howard <fraggle@gmail.com>
date: Sun Oct 23 15:53:06 EDT 2011

Fix numeric keypad when entering values in text boxes (thanks Twelve).

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2463

--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,13 @@
      * Fix teleport behavior when emulating the alternate Final Doom
        executable (-gameversion final2) (thanks xttl).
 
+    libtextscreen:
+     * Input boxes stop editing and save when they lose their focus,
+       correcting a previous counterintuitive behavior (thanks
+       Twelve).
+     * The numeric keypad now works properly when entering text values
+       (thanks Twelve).
+
 1.6.0 (2011-05-17):
 
      * The instructions in the INSTALL file are now customized for
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -405,25 +405,6 @@
         case SDLK_CAPSLOCK:    return KEY_CAPSLOCK;
         case SDLK_SCROLLOCK:   return KEY_SCRLCK;
 
-        case SDLK_KP0:         return KEYP_0;
-        case SDLK_KP1:         return KEYP_1;
-        case SDLK_KP2:         return KEYP_2;
-        case SDLK_KP3:         return KEYP_3;
-        case SDLK_KP4:         return KEYP_4;
-        case SDLK_KP5:         return KEYP_5;
-        case SDLK_KP6:         return KEYP_6;
-        case SDLK_KP7:         return KEYP_7;
-        case SDLK_KP8:         return KEYP_8;
-        case SDLK_KP9:         return KEYP_9;
-
-        case SDLK_KP_PERIOD:   return KEYP_PERIOD;
-        case SDLK_KP_MULTIPLY: return KEYP_MULTIPLY;
-        case SDLK_KP_PLUS:     return KEYP_PLUS;
-        case SDLK_KP_MINUS:    return KEYP_MINUS;
-        case SDLK_KP_DIVIDE:   return KEYP_DIVIDE;
-        case SDLK_KP_EQUALS:   return KEYP_EQUALS;
-        case SDLK_KP_ENTER:    return KEYP_ENTER;
-
         case SDLK_HOME:        return KEY_HOME;
         case SDLK_INSERT:      return KEY_INS;
         case SDLK_END:         return KEY_END;
@@ -454,7 +435,34 @@
     }
     else
     {
-        return tolower(sym->sym);
+        // Keypad mapping is only done when we want a raw value:
+        // most of the time, the keypad should behave as it normally
+        // does.
+
+        switch (sym->sym)
+        {
+            case SDLK_KP0:         return KEYP_0;
+            case SDLK_KP1:         return KEYP_1;
+            case SDLK_KP2:         return KEYP_2;
+            case SDLK_KP3:         return KEYP_3;
+            case SDLK_KP4:         return KEYP_4;
+            case SDLK_KP5:         return KEYP_5;
+            case SDLK_KP6:         return KEYP_6;
+            case SDLK_KP7:         return KEYP_7;
+            case SDLK_KP8:         return KEYP_8;
+            case SDLK_KP9:         return KEYP_9;
+
+            case SDLK_KP_PERIOD:   return KEYP_PERIOD;
+            case SDLK_KP_MULTIPLY: return KEYP_MULTIPLY;
+            case SDLK_KP_PLUS:     return KEYP_PLUS;
+            case SDLK_KP_MINUS:    return KEYP_MINUS;
+            case SDLK_KP_DIVIDE:   return KEYP_DIVIDE;
+            case SDLK_KP_EQUALS:   return KEYP_EQUALS;
+            case SDLK_KP_ENTER:    return KEYP_ENTER;
+
+            default:
+                return tolower(sym->sym);
+        }
     }
 }