readline: Put cursor on clicked position

by default the cursor was always set at the end of the string.
Now it is where clicked.
see http://pulkomandy.tk/projects/GrafX2/ticket/103
This commit is contained in:
Thomas Bernard 2019-05-02 20:59:50 +02:00
parent 8614490026
commit 91c5d7833a
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -653,9 +653,17 @@ byte Readline_ex_unicode(word x_pos, word y_pos, char * str, word * str_unicode,
// Si on a commencé à editer par un clic-droit, on vide la chaine. // Si on a commencé à editer par un clic-droit, on vide la chaine.
if (Mouse_K==RIGHT_SIDE) if (Mouse_K==RIGHT_SIDE)
{
str[0]='\0'; str[0]='\0';
else if (input_type==INPUT_TYPE_INTEGER && str[0]!='\0') position = 0;
snprintf(str,10,"%d",atoi(str)); // On tasse la chaine à gauche }
else
{
int int_pos = ((Mouse_X-Window_pos_X)/Menu_factor_X - x_pos) >> 3;
position = (int_pos >= 0 && int_pos <= 255) ? (byte)int_pos : 255;
if (input_type==INPUT_TYPE_INTEGER && str[0]!='\0')
snprintf(str,10,"%d",atoi(str)); // align left
else if (input_type==INPUT_TYPE_DECIMAL) else if (input_type==INPUT_TYPE_DECIMAL)
{ {
// Nothing. The caller should have used Sprint_double, with min_positions // Nothing. The caller should have used Sprint_double, with min_positions
@ -665,6 +673,7 @@ byte Readline_ex_unicode(word x_pos, word y_pos, char * str, word * str_unicode,
{ {
// Nothing. The caller should have initialized a valid hexa number. // Nothing. The caller should have initialized a valid hexa number.
} }
}
#if defined(__ANDROID__) #if defined(__ANDROID__)
SDL_ANDROID_GetScreenKeyboardTextInput(str, max_size); SDL_ANDROID_GetScreenKeyboardTextInput(str, max_size);
@ -789,9 +798,11 @@ byte Readline_ex_unicode(word x_pos, word y_pos, char * str, word * str_unicode,
if (str_unicode != NULL) if (str_unicode != NULL)
{ {
size = Unicode_strlen(str_unicode); size = Unicode_strlen(str_unicode);
if (size > 255) size = 255; if (size > 255)
size = 255;
memcpy(initial_string_unicode, str_unicode, 2*(size+1)); memcpy(initial_string_unicode, str_unicode, 2*(size+1));
position =(byte)((size<max_size) ? size : size-1); if (position >= size)
position = (byte)((size<max_size) ? size : size-1);
if (position-offset>=visible_size) if (position-offset>=visible_size)
offset=position-visible_size+1; offset=position-visible_size+1;
// copy only part of the string if it is too long // copy only part of the string if it is too long
@ -805,8 +816,10 @@ byte Readline_ex_unicode(word x_pos, word y_pos, char * str, word * str_unicode,
} }
else else
{ {
size=strlen(str); size = strlen(str);
if (size > 255) size = 255; if (size > 255)
size = 255;
if (position >= size)
position = (byte)((size<max_size) ? size : size-1); position = (byte)((size<max_size) ? size : size-1);
if (position-offset>=visible_size) if (position-offset>=visible_size)
offset=position-visible_size+1; offset=position-visible_size+1;