Enabled gui console support for sdl2 using SDL_TEXTINPUT event.

This commit is contained in:
Volker Ruppert 2017-01-13 21:37:06 +00:00
parent 877118954c
commit 5cd321dd02
4 changed files with 27 additions and 3 deletions

View File

@ -11,7 +11,7 @@ Changes after 2.6.8 release:
- GUI and display libraries
- Show the runtime configuration in the Bochs VGA window (gui console) instead
of console / xterm (rfb, sdl, vncsrv and X11 guis).
of console / xterm (rfb, sdl, sdl2, vncsrv and X11 guis).
- SDL2: Added get/set clipboard text support.
- CPU / CPUDB

View File

@ -1196,6 +1196,7 @@ char* bx_gui_c::bx_gets(char *s, int size)
int pos = 0, done = 0;
int cs_counter = 1, cs_visible = 0;
set_console_edit_mode(1);
keystr[1] = 0;
do {
handle_events();
@ -1234,6 +1235,7 @@ char* bx_gui_c::bx_gets(char *s, int size)
}
} while (!done);
console.tminfo.cs_start |= 0x20;
set_console_edit_mode(0);
return s;
}
#endif

View File

@ -135,6 +135,9 @@ public:
virtual void beep_off();
virtual void get_capabilities(Bit16u *xres, Bit16u *yres, Bit16u *bpp);
virtual void set_mouse_mode_absxy(bx_bool mode) {}
#if BX_USE_GUI_CONSOLE
virtual void set_console_edit_mode(bx_bool mode) {}
#endif
// The following function(s) are defined already, and your
// GUI code calls them

View File

@ -53,6 +53,7 @@ public:
#if BX_SHOW_IPS
virtual void show_ips(Bit32u ips_count);
#endif
virtual void set_console_edit_mode(bx_bool mode);
private:
void headerbar_click(int x);
};
@ -507,7 +508,7 @@ void bx_sdl2_gui_c::specific_init(int argc, char **argv, unsigned headerbar_y)
if (gui_ci) {
dialog_caps = BX_GUI_DLG_ALL;
} else {
// console.present = 1;
console.present = 1;
}
}
@ -879,7 +880,10 @@ void bx_sdl2_gui_c::handle_events(void)
case SDL_KEYDOWN:
if (console_running()) {
if ((sdl_event.key.keysym.sym & (1 << 30)) == 0) {
// TODO
Bit8u ascii = (Bit8u)sdl_event.key.keysym.sym;
if ((ascii == SDLK_RETURN) || (ascii == SDLK_BACKSPACE)) {
console_key_enq(ascii);
}
}
break;
}
@ -967,6 +971,12 @@ void bx_sdl2_gui_c::handle_events(void)
}
break;
case SDL_TEXTINPUT:
if (console_running()) {
console_key_enq(sdl_event.text.text[0]);
}
break;
case SDL_QUIT:
LOG_THIS setonoff(LOGLEV_PANIC, ACT_FATAL);
BX_PANIC(("User requested shutdown."));
@ -1463,6 +1473,15 @@ void bx_sdl2_gui_c::show_ips(Bit32u ips_count)
}
#endif
void bx_sdl2_gui_c::set_console_edit_mode(bx_bool mode)
{
if (mode) {
SDL_StartTextInput();
} else {
SDL_StopTextInput();
}
}
/// key mapping code for SDL2
typedef struct {