More special keys.
authorTimo Korvola <tkorvola@iki.fi>
Sun, 4 Mar 2018 20:52:45 +0000 (22:52 +0200)
committerDavid Griffith <dave@661.org>
Sun, 11 Mar 2018 11:48:50 +0000 (04:48 -0700)
Esc clears the input line.  Page up/down are passed as cursor up/down
to the game (Beyond Zork needs them).  This resembles more and more
the curses version.

src/sdl/sf_frotz.h
src/sdl/sf_video.c

index ceae800d57c726f1ab4bea632f91b56865cbd1a0..50acf920a129d9d506bf2e5d6f4f7337c5fbeb86 100644 (file)
@@ -249,6 +249,8 @@ void sf_FinishProfile(void);
 // virtual keys
 #define VK_TAB 0x16
 #define VK_INS 0x17
+#define VK_PAGE_UP 0x18
+#define VK_PAGE_DOWN 0x19
 
 // for AIFF resampling
 
index d2a9dc17b64f6539ee34474474c1a9e31ac12646..c54ed1307b891b122a3adf50cfcf844b2d49ab80 100644 (file)
@@ -640,6 +640,8 @@ static zword goodzkey( SDL_Event *e, int allowed)
        case SDLK_LEFT:         return ZC_ARROW_LEFT;\r
        case SDLK_RIGHT:        return ZC_ARROW_RIGHT;\r
        case SDLK_TAB:          return (allowed ? VK_TAB : 0);\r
+       case SDLK_PAGEUP:       return (allowed ? VK_PAGE_UP : 0);\r
+       case SDLK_PAGEDOWN:     return (allowed ? VK_PAGE_DOWN : 0);\r
        case SDLK_KP0:          return ZC_NUMPAD_MIN+0;\r
        case SDLK_KP1:          return ZC_NUMPAD_MIN+1;\r
        case SDLK_KP2:          return ZC_NUMPAD_MIN+2;\r
@@ -815,7 +817,14 @@ zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued)
                         pos--;\r
                         sf_DrawInput(buf,pos,ptx,pty,width,true);\r
                     }\r
-                    break;\r
+                    continue;\r
+                case ZC_ESCAPE:         /* Delete whole line */\r
+                    pos = 0;\r
+                    buf[0] = '\0';\r
+                    searchpos = -1;\r
+                    gen_history_reset();\r
+                    sf_DrawInput(buf,pos,ptx,pty,width,true);\r
+                    continue;\r
                 case VK_TAB:\r
                     if (pos == (int)mywcslen(buf)) {\r
                         zchar extension[10], *s;\r
@@ -828,19 +837,19 @@ zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued)
                         buf[pos] = 0;\r
                         sf_DrawInput(buf,pos,ptx,pty,width,true);\r
                     }\r
-                    break;\r
+                    continue;\r
                 case ZC_ARROW_LEFT:\r
                     // Move the cursor left\r
                     if (pos > 0)\r
                         pos--;\r
                     sf_DrawInput(buf,pos,ptx,pty,width,true);\r
-                    break;\r
+                    continue;\r
                 case ZC_ARROW_RIGHT:\r
                     // Move the cursor right\r
                     if (pos < (int)mywcslen(buf))\r
                         pos++;\r
                     sf_DrawInput(buf,pos,ptx,pty,width,true);\r
-                    break;\r
+                    continue;\r
                 case ZC_ARROW_UP:\r
                 case ZC_ARROW_DOWN:\r
                     if (searchpos < 0)\r
@@ -851,21 +860,12 @@ zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued)
                         pos = mywcslen(buf);\r
                         sf_DrawInput(buf,pos,ptx,pty,width,true);\r
                     }\r
-                    break;\r
+                    continue;\r
+                /* Pass through as up/down arrows for Beyond Zork. */\r
+                case VK_PAGE_UP: c = ZC_ARROW_UP; break;\r
+                case VK_PAGE_DOWN: c = ZC_ARROW_DOWN; break;\r
                 default:\r
-                    if (is_terminator(c)) {\r
-                        // Terminate the current input\r
-                        m_exitPause = false;\r
-                        sf_DrawInput(buf,pos,ptx,pty,width,false);\r
-\r
-                        if ((c == ZC_SINGLE_CLICK) || (c == ZC_DOUBLE_CLICK)) {\r
-                            /* mouse_x = input.mousex+1;\r
-                               mouse_y = input.mousey+1;*/\r
-                        } else if (c == ZC_RETURN)\r
-                            gen_add_to_history(buf);\r
-                        //                     theWnd->SetLastInput(buf);\r
-                        return c;\r
-                    } else if (sf_IsValidChar(c) && mywcslen(buf) < max) {\r
+                    if (sf_IsValidChar(c) && mywcslen(buf) < max) {\r
                         // Add a valid character to the input line\r
                         // Get the width of the new input line\r
                         int len = os_string_width(buf);\r
@@ -880,8 +880,22 @@ zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued)
                             pos++;\r
                             sf_DrawInput(buf,pos,ptx,pty,width,true);\r
                         }\r
+                        continue;\r
                     }\r
                 }\r
+                if (is_terminator(c)) {\r
+                    // Terminate the current input\r
+                    m_exitPause = false;\r
+                    sf_DrawInput(buf,pos,ptx,pty,width,false);\r
+\r
+                    if ((c == ZC_SINGLE_CLICK) || (c == ZC_DOUBLE_CLICK)) {\r
+                        /*  mouse_x = input.mousex+1;\r
+                                                mouse_y = input.mousey+1;*/\r
+                    } else if (c == ZC_RETURN)\r
+                        gen_add_to_history(buf);\r
+                    //                      theWnd->SetLastInput(buf);\r
+                    return c;\r
+                }\r
             }\r
         }\r
         if ((timeout) && (sf_ticks() >= mytimeout)) {\r