News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

[Patch] SDL2, support for "SDL_StartTextInput()"

Started by Michael 'Cruzer', August 03, 2014, 02:46:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Michael 'Cruzer'

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.
Founder and Ex-Maintainer of pak192.comic. Provider of Simutrans Hosting rental service.

DrSuperGood

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.

Ters

I believe that is entirely up to the OS. It would likely be the same in Simutrans as in every other app.

Michael 'Cruzer'

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.)
Founder and Ex-Maintainer of pak192.comic. Provider of Simutrans Hosting rental service.

prissi


captain crunch

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 '?'

kierongreen

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?

Ters

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.

Michael 'Cruzer'

captain crunch, can you describe what's your setup? (OS, Simutrans Backend and Build, homebrew build or nightly server?)
Founder and Ex-Maintainer of pak192.comic. Provider of Simutrans Hosting rental service.