SDL2: readline.c uses SDL_TEXTINPUT unicode input text
This commit is contained in:
parent
501ce2a4ad
commit
aa73e76e67
@ -98,6 +98,11 @@ GFX2_GLOBAL dword Key_ANSI;
|
||||
|
||||
GFX2_GLOBAL dword Key_UNICODE;
|
||||
|
||||
/// from SDL_TextInputEvent
|
||||
#if defined(USE_SDL2)
|
||||
GFX2_GLOBAL char Key_Text[32];
|
||||
#endif
|
||||
|
||||
// Keyboard modifiers
|
||||
// (Name conflict with windows.h)
|
||||
#ifdef MOD_SHIFT
|
||||
|
||||
19
src/input.c
19
src/input.c
@ -892,6 +892,9 @@ int Get_input(int sleep_time)
|
||||
Key_ANSI = 0;
|
||||
Key_UNICODE = 0;
|
||||
Key = 0;
|
||||
#if defined(USE_SDL2)
|
||||
memset(Key_Text, 0, sizeof(Key_Text));
|
||||
#endif
|
||||
Mouse_moved=0;
|
||||
Input_new_mouse_X = Mouse_X;
|
||||
Input_new_mouse_Y = Mouse_Y;
|
||||
@ -944,8 +947,13 @@ int Get_input(int sleep_time)
|
||||
break;
|
||||
|
||||
#if defined(USE_SDL2)
|
||||
//case SDL_MOUSEWHEEL:
|
||||
// break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (event.wheel.y > 0)
|
||||
Key = KEY_MOUSEWHEELUP|Get_Key_modifiers();
|
||||
else if (event.wheel.y < 0)
|
||||
Key = KEY_MOUSEWHEELDOWN|Get_Key_modifiers();
|
||||
user_feedback_required = 1;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
@ -957,6 +965,13 @@ int Get_input(int sleep_time)
|
||||
Handle_key_release(event.key);
|
||||
break;
|
||||
|
||||
#if defined(USE_SDL2)
|
||||
case SDL_TEXTINPUT:
|
||||
memcpy(Key_Text, event.text.text, sizeof(Key_Text));
|
||||
user_feedback_required = 1;
|
||||
break;
|
||||
#endif
|
||||
|
||||
// Start of Joystik handling
|
||||
#ifdef USE_JOYSTICK
|
||||
|
||||
|
||||
@ -777,10 +777,77 @@ byte Readline_ex_unicode(word x_pos,word y_pos,char * str,word * str_unicode,byt
|
||||
goto affichage;
|
||||
}
|
||||
|
||||
} while(input_key==0);
|
||||
} while(input_key==0
|
||||
#if defined(USE_SDL2)
|
||||
&& Key_Text[0] == '\0'
|
||||
#endif
|
||||
);
|
||||
}
|
||||
Hide_cursor();
|
||||
|
||||
#if defined(USE_SDL2)
|
||||
if (Key_Text[0] != 0)
|
||||
{
|
||||
word unicode_text[32];
|
||||
int i;
|
||||
#if defined(ENABLE_FILENAMES_ICONV)
|
||||
char * input = Key_Text;
|
||||
size_t inbytesleft = strlen(Key_Text);
|
||||
char * output = (char *)unicode_text;
|
||||
size_t outbytesleft = sizeof(unicode_text) - 2;
|
||||
size_t r = iconv(cd_utf16, &input, &inbytesleft, &output, &outbytesleft);
|
||||
if (r != (size_t)-1)
|
||||
{
|
||||
output[1] = output[0] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning("Unicode conversion of input text failed");
|
||||
unicode_text[0] = 0;
|
||||
}
|
||||
#else
|
||||
int j;
|
||||
for (i = 0, j = 0; i < sizeof(Key_Text) && Key_Text[i] != '\0'; i++)
|
||||
if (Key_Text[i] < 128) unicode_text[j++] = Key_Text[i];
|
||||
unicode_text[j++] = 0;
|
||||
#endif
|
||||
for (i = 0; unicode_text[i] != 0 && size < max_size; i++)
|
||||
{
|
||||
// Si la touche était autorisée...
|
||||
byte is_authorized = Valid_character(unicode_text[i], input_type);
|
||||
if (is_authorized == 1 || (is_authorized == 2 && position == 0 && str[position] != '-'))
|
||||
{
|
||||
// ... alors on l'insère ...
|
||||
if (str_unicode != NULL)
|
||||
Insert_character_unicode(str_unicode,unicode_text[i],position/*,size*/);
|
||||
else
|
||||
Insert_character(str,unicode_text[i],position/*,size*/);
|
||||
// ce qui augmente la taille de la chaine
|
||||
size++;
|
||||
// et qui risque de déplacer le curseur vers la droite
|
||||
if (size<max_size)
|
||||
{
|
||||
position++;
|
||||
if (position-offset>=visible_size)
|
||||
offset++;
|
||||
else if (str_unicode != NULL)
|
||||
{
|
||||
if (display_string_unicode[position-offset]==RIGHT_TRIANGLE_CHARACTER)
|
||||
offset++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (display_string[position-offset]==RIGHT_TRIANGLE_CHARACTER)
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Enfin, on raffiche la chaine
|
||||
goto affichage;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
switch (input_key)
|
||||
{
|
||||
case KEY_DELETE : // Suppr.
|
||||
@ -888,6 +955,7 @@ byte Readline_ex_unicode(word x_pos,word y_pos,char * str,word * str_unicode,byt
|
||||
}
|
||||
break;
|
||||
default :
|
||||
#if !defined(USE_SDL2)
|
||||
if (size<max_size)
|
||||
{
|
||||
// Si la touche était autorisée...
|
||||
@ -922,6 +990,7 @@ byte Readline_ex_unicode(word x_pos,word y_pos,char * str,word * str_unicode,byt
|
||||
goto affichage;
|
||||
} // End du test d'autorisation de touche
|
||||
} // End du test de place libre
|
||||
#endif
|
||||
break;
|
||||
|
||||
affichage:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user