mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-15 07:00:58 +00:00
improved SDL2 textinput handling
strdup() and free() aren't really the right tool if the size of the buffer is known anyway (and quite small, currently 32 chars) while at it, I renamed s and s_pos to str and str_pos for better readability
This commit is contained in:
parent
940d9f8a06
commit
b9f5d20e93
1 changed files with 10 additions and 11 deletions
|
@ -772,20 +772,19 @@ sysEvent_t Sys_GetEvent()
|
|||
static int previous_hat_state = SDL_HAT_CENTERED;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
static char* s = NULL;
|
||||
static size_t s_pos = 0;
|
||||
static char str[SDL_TEXTINPUTEVENT_TEXT_SIZE] = {0};
|
||||
static size_t str_pos = 0;
|
||||
|
||||
if( s )
|
||||
if( str_pos != 0 )
|
||||
{
|
||||
res.evType = SE_CHAR;
|
||||
res.evValue = s[s_pos];
|
||||
res.evValue = str[str_pos];
|
||||
|
||||
s_pos++;
|
||||
if( !s[s_pos] )
|
||||
++str_pos;
|
||||
if( !str[str_pos] )
|
||||
{
|
||||
free( s );
|
||||
s = NULL;
|
||||
s_pos = 0;
|
||||
memset( str, 0, sizeof( str ) );
|
||||
str_pos = 0;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -1012,12 +1011,12 @@ sysEvent_t Sys_GetEvent()
|
|||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
case SDL_TEXTINPUT:
|
||||
if( ev.text.text && *ev.text.text )
|
||||
if( ev.text.text[0] != '\0' )
|
||||
{
|
||||
if( !ev.text.text[1] )
|
||||
c = *ev.text.text;
|
||||
else
|
||||
s = strdup( ev.text.text );
|
||||
idStr::Copynz( str, ev.text.text, sizeof( str ) );
|
||||
}
|
||||
|
||||
return res_none;
|
||||
|
|
Loading…
Reference in a new issue