From 5a23a0a6a0062bf21a41b510457af2a729c09ea5 Mon Sep 17 00:00:00 2001 From: Timo Korvola Date: Tue, 27 Mar 2018 01:57:47 +0300 Subject: [PATCH] Try to use text input where appropriate. 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 | 2 +- src/sdl/sf_osfdlg.c | 10 +++++----- src/sdl/sf_resource.c | 2 +- src/sdl/sf_util.c | 2 +- src/sdl/sf_video.c | 43 ++++++++++++++++++++++--------------------- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/sdl/sf_frotz.h b/src/sdl/sf_frotz.h index dc404b5..727ff68 100644 --- a/src/sdl/sf_frotz.h +++ b/src/sdl/sf_frotz.h @@ -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, diff --git a/src/sdl/sf_osfdlg.c b/src/sdl/sf_osfdlg.c index 3f25f12..7c38f82 100644 --- a/src/sdl/sf_osfdlg.c +++ b/src/sdl/sf_osfdlg.c @@ -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; diff --git a/src/sdl/sf_resource.c b/src/sdl/sf_resource.c index 2ea3ec7..ec6a107 100644 --- a/src/sdl/sf_resource.c +++ b/src/sdl/sf_resource.c @@ -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); } } } diff --git a/src/sdl/sf_util.c b/src/sdl/sf_util.c index 41fd783..9e19662 100644 --- a/src/sdl/sf_util.c +++ b/src/sdl/sf_util.c @@ -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(); diff --git a/src/sdl/sf_video.c b/src/sdl/sf_video.c index 562198d..25d4b04 100644 --- a/src/sdl/sf_video.c +++ b/src/sdl/sf_video.c @@ -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); -- 2.34.1