The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Michael 'Cruzer' on August 03, 2014, 02:46:57 PM

Title: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: Michael 'Cruzer' on August 03, 2014, 02:46:57 PM
SDL2 offers SDL_StartTextInput() and SDL_StopTextInput(). These methods are used to handle stuff like on-display keyboards when there is no hardware keyboards are available. This is especially important on tablets and smartphone. My patch adds


/** 
* Shows the touch keyboard when using systems without a hardware keyboard.
* Will be ignored if there is an hardware keyboard available.
*/
void dr_start_textinput();


/**
* Hides the touch keyboard when using systems without a hardware keyboard.
* Will be ignored it there is no on-display keyboard shown.
*/

void dr_stop_textinput();






Which will do nothing (yet) on any other platform then SDL2. My patch also changes hasFocus method in gui_textinput.cc slightly to use these both methods:


/**
* Detect change of focus state and determine whether cursor should be displayed,
* and call the function that performs the actual display
* @author Knightly
*/
void gui_textinput_t::display_with_focus(scr_coord offset, bool has_focus)
{
   // check if focus state has changed
   if(  focus_recieved!=has_focus  ) {
      if(  has_focus  ) {
         // update reference time for cursor blinking if focus has just been received
         cursor_reference_time = dr_time();
           
            // screen keyboard support
            dr_start_textinput();
      }
        else {
            dr_stop_textinput();
        }
      focus_recieved = has_focus;
   }


   display_with_cursor( offset, has_focus, (has_focus  &&  ((dr_time()-cursor_reference_time)&512ul)==0) );
}





Full patch attached.
Title: Re: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: DrSuperGood on August 04, 2014, 02:42:14 AM
I assume that the keyboard will only show if there is no physical keyboard input device? I imagine it could get annoying otherwise on devices with a keyboard if it keeps popping up taking a large amount of screen space. There should also be an option to force usage of on screen keyboard as some people may want it even on a device with a wired keyboard.
Title: Re: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: Ters on August 04, 2014, 08:35:40 AM
I believe that is entirely up to the OS. It would likely be the same in Simutrans as in every other app.
Title: Re: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: Michael 'Cruzer' on August 06, 2014, 01:52:38 PM
Yes, Ters is right. SDL is just forwarding the information that there is some text input required. OS will handle it if there is a screen keyboard displayed. (And to my knowledge every OS handles it the way you expect it.)
Title: Re: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: prissi on August 11, 2014, 11:28:19 PM
Incorporated in r7292, thanks!
Title: Re: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: captain crunch on August 12, 2014, 05:23:06 PM
Sadly, this breaks keyboard input on Linux as it seemingly does not report the key code pressed.

Before, when I pressed the keys a,b,c,F1,ESC:

Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 97 'a'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 98 'b'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 99 'c'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 256 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 27 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'


After:

Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 256 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 27 '?'
Message: interaction_t::interactive_event(): Keyboard event with code 0 '?'
Title: Re: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: kierongreen on August 12, 2014, 05:57:06 PM
QuoteSadly, this breaks keyboard input on Linux as it seemingly does not report the key code pressed.
Keyboard input works here on Linux with SDL1 - was there a particular dialogue you tested this with or was it with SDL2 you were testing?
Title: Re: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: Ters on August 12, 2014, 06:11:56 PM
Considering the change is a no-op on anything but SDL2, I would assume captain crunch uses SDL2. I have certainly not noticed anything with SDL1 on Windows.
Title: Re: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: Michael 'Cruzer' on August 12, 2014, 06:24:47 PM
captain crunch, can you describe what's your setup? (OS, Simutrans Backend and Build, homebrew build or nightly server?)
Title: Re: [Patch] SDL2, support for "SDL_StartTextInput()"
Post by: captain crunch on August 12, 2014, 06:40:36 PM
3.14-2-amd64 x86_64 GNU/Linux
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@7293
BACKEND = sdl2