Try to use text input where appropriate.
authorTimo Korvola <tkorvola@iki.fi>
Mon, 26 Mar 2018 22:57:47 +0000 (01:57 +0300)
committerTimo Korvola <tkorvola@iki.fi>
Wed, 28 Mar 2018 16:40:31 +0000 (19:40 +0300)
os_read_key uses text input because it may be called from Z-code,
which expects to be able to read characters.  More prompts etc.
do not use text input.

src/sdl/sf_frotz.h
src/sdl/sf_osfdlg.c
src/sdl/sf_resource.c
src/sdl/sf_util.c
src/sdl/sf_video.c

index dc404b5733e5342115f5a0519f942177e44fdc0a..727ff68868ad462baa1b00d8d4fdc5babdda470c 100644 (file)
@@ -218,7 +218,7 @@ ulong * sf_savearea( int x, int y, int w, int h);
 void sf_restoreareaandfree( ulong *s);
 #define SF_NOTIMP (-9999)
 
-zword sf_read_key( int timeout, int cursor, int allowed);
+zword sf_read_key( int timeout, bool cursor, bool allowed, bool text);
 
 int sf_user_fdialog( bool exist, const char *def, const char *filt, const char *title, char **res);
 extern int (*sf_osdialog)( bool ex, const char *def, const char *filt, const char *tit, char **res,
index 3f25f12ed3a04bb934d4ca5b931c8a787d1be154..7c38f82da81ba94c66ac112c7d94e9686fb88685 100644 (file)
@@ -235,9 +235,9 @@ STATIC zword Zselect( int x, int y);
 STATIC zword yesnoover( int xc, int yc);
 STATIC zword Zentry( int x, int y);
 
-STATIC zword inputkey()
+STATIC zword inputkey(bool text)
   {
-  zword c = sf_read_key(0,0,1);
+  zword c = sf_read_key(0, false, true, text);
   if (c == ZC_SINGLE_CLICK)
     {
     switch (mouse_button)
@@ -357,7 +357,7 @@ STATIC int myosdialog( bool existing, const char *def, const char *filt, const c
   for (;;)
     {
     if (pushed) { c = pushed; pushed = 0;}
-    else c = inputkey();
+    else c = inputkey(false);
     if (c == ZC_SINGLE_CLICK) c = checkmouse(0);
     if (c == VK_INS) c = Zentry(0,-1);
     if (c == ZC_ARROW_LEFT) goleft();
@@ -813,7 +813,7 @@ zword sf_yesnooverlay( int xc, int yc, char *t, int saverest)
   addbutton(xc+SPC,yc+SPC,BUTTW,HTEXT,"No",Zcanc);
   for (;;)
     {
-    c = inputkey();
+    c = inputkey(false);
     if (c == 'n' || c == 'N') c = ZC_ESCAPE;
     if (c == 'y' || c == 'Y') c = ZC_RETURN;
     if (c == ZC_SINGLE_CLICK) c = checkmouse(nsav);
@@ -866,7 +866,7 @@ STATIC zword Zentry( int x, int y)
   showfilename(pos);
   for (;;)
     {
-    c = inputkey();
+    c = inputkey(true);
     if (c == ZC_SINGLE_CLICK)
        {
        pushed = c;
index 2ea3ec777b97d20c2cc1f15ac316db6c36ef1927..ec6a10775f358c4b86e3cb30d039d9631f41a9d7 100644 (file)
@@ -391,7 +391,7 @@ void os_restart_game(int stage)
                {
                sf_fillrect(0,0,0,10000,10000);
                os_draw_picture(1,1,1);
-               os_read_key(0,0);
+               sf_read_key(0, false, false, false);
                }
        }
   }
index 41fd783b70736a933e22859b060f855b7e6a80b5..9e19662b839d8ef7bab9085f4ece90d00e7168de 100644 (file)
@@ -74,7 +74,7 @@ void os_reset_screen(void)
 
        while (*hit)
                os_display_char((*hit++));
-       os_read_key(0,1);
+        sf_read_key(0, true, false, false);
        }
 
   sf_cleanup_all();
index 562198d120045249d3b48697741bc4bf2036b21b..25d4b04142007a105e6ffa1dccda4b13f6673a73 100644 (file)
@@ -680,7 +680,7 @@ static zword goodzkey( SDL_Event *e, int allowed)
     }
 }
 
-zword sf_read_key( int timeout, int cursor, int allowed)
+zword sf_read_key( int timeout, bool cursor, bool allowed, bool text)
   {
   SDL_Event event;
   zword inch = 0;
@@ -695,24 +695,25 @@ zword sf_read_key( int timeout, int cursor, int allowed)
   if (timeout) mytimeout = sf_ticks() + m_timerinterval*timeout;
 //     InputTimer timer(timeout);
 //     FrotzWnd::Input input;
-  while (true)
-    {
-               // Get the next input
-    while (SDL_PollEvent(&event)) 
-       {
-//if (event.type == SDL_QUIT) printf("got SDL_QUIT\n");
-       if ((inch = goodzkey(&event,allowed))) 
-               break;
-       }
-    if (inch) break;
-    if ((timeout) && (sf_ticks() >= mytimeout))
-       {
-       inch = ZC_TIME_OUT;
-       break;
-       }
-    sf_checksound();
-    sf_sleep(10);
-    }
+  if (text)
+      SDL_StartTextInput();
+  while (true) {
+      // Get the next input
+      while (SDL_PollEvent(&event)) {
+//          if (event.type == SDL_QUIT) printf("got SDL_QUIT\n");
+          if ((inch = goodzkey(&event,allowed)))
+              break;
+      }
+      if (inch) break;
+      if ((timeout) && (sf_ticks() >= mytimeout)) {
+          inch = ZC_TIME_OUT;
+          break;
+      }
+      sf_checksound();
+      sf_sleep(10);
+  }
+  if (text)
+      SDL_StopTextInput();
 
   if (cursor)
        sf_drawcursor(false);
@@ -730,7 +731,7 @@ zword sf_read_key( int timeout, int cursor, int allowed)
  */
 zchar os_read_key(int timeout, int cursor)
   {
-  return sf_read_key(timeout,cursor,0);
+  return sf_read_key(timeout, cursor, false, true);
   }
 
 
@@ -1036,7 +1037,7 @@ void os_more_prompt(void)
 //     sf_flushdisplay();
 
                // Wait for a key press
-       os_read_key(0,1);
+       sf_read_key(0, true, false, false);
                // Remove the [More] prompt
        sf_fillrect(ts->back,x,y,ts->cx-x,h);
 //     sf_drawcursor(false);