improve Print_in_window_limited(), add Print_in_window_limited_unicode()

This commit is contained in:
Thomas Bernard 2019-02-01 12:23:37 +01:00
parent e3bf51f753
commit ad1c38e2ca
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
2 changed files with 23 additions and 6 deletions

View File

@ -954,15 +954,31 @@ void Print_char_in_window(short x_pos, short y_pos, unsigned int c,byte text_col
///Draws a char in a window, checking for bounds
void Print_in_window_limited(short x,short y,const char * str,byte size,byte text_color,byte background_color)
{
char display_string[256];
strncpy(display_string, str, size);
display_string[size]='\0';
if (strlen(str) > size)
{
display_string[size-1]=ELLIPSIS_CHARACTER;
}
char * display_string = strdup(str);
display_string[size-1] = ELLIPSIS_CHARACTER;
display_string[size] = '\0';
Print_in_window(x, y, display_string, text_color, background_color);
free(display_string);
}
else
Print_in_window(x, y, str, text_color, background_color);
}
///Draws a char in a window, checking for bounds
void Print_in_window_limited_unicode(short x, short y, const word * str, byte size, byte text_color, byte background_color)
{
if (Unicode_strlen(str) > size)
{
word * display_string = Unicode_strdup(str);
display_string[size-1] = (byte)ELLIPSIS_CHARACTER;
display_string[size] = 0;
Print_in_window_unicode(x, y, display_string, text_color, background_color);
free(display_string);
}
else
Print_in_window_unicode(x, y, str, text_color, background_color);
}
/// Draws a string in a window with underscore

View File

@ -70,6 +70,7 @@ void Print_in_window_underscore(short x,short y,const char * str,byte text_color
void Print_in_window(short x,short y,const char * str,byte text_color,byte background_color);
void Print_in_window_unicode(short x,short y,const word * str,byte text_color,byte background_color);
void Print_in_window_limited(short x,short y,const char * str,byte size,byte text_color,byte background_color);
void Print_in_window_limited_unicode(short x, short y, const word * str, byte size, byte text_color, byte background_color);
void Print_char_in_window(short x_pos,short y_pos, unsigned int c,byte text_color,byte background_color);
void Print_in_menu(const char * str, short position);
void Print_coordinates(void);