Larger OSK on larger windows; larger OSK font

On-screen keyboard (visible when the feature is enabled, while
using the "Text" and "Label" tools) now appears with larger
(48x48 pixel, vs 24x24 pixel) buttons, when Tux Paint's window
(or fullscreen) size is large enough to fit them with the
chosen layout.
(h/t Anat & Aviv, who suggested it to help with users of
eye-tracking systems)

Also, on-screen keyboard buttons use a slightly larger font
(16pt vs 12pt, previously seen on the small keyboard;
32pt on the large keyboard).
This commit is contained in:
Bill Kendrick 2020-08-25 22:00:43 -07:00
parent 1a21e1d56d
commit 61998e4d00
5 changed files with 168 additions and 34 deletions

BIN
data/images/ui/btn_hold.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View file

@ -45,6 +45,18 @@ $Id$
(relative to the eraser size; especially useful for the (relative to the eraser size; especially useful for the
smallest erasers). smallest erasers).
* On-screen keyboard (visible when the feature is enabled, while
using the "Text" and "Label" tools) now appears with larger
(48x48 pixel, vs 24x24 pixel) buttons, when Tux Paint's window
(or fullscreen) size is large enough to fit them with the
chosen layout.
(h/t Anat & Aviv, who suggested it to help with users of
eye-tracking systems)
* On-screen keyboard buttons use a slightly larger font
(16pt vs 12pt, previously seen on the small keyboard;
32pt on the large keyboard).
* Ports & Building * Ports & Building
---------------- ----------------
* Corrections for Haiku not opening saved files. * Corrections for Haiku not opening saved files.

View file

@ -83,15 +83,27 @@ static void mtw(wchar_t * wtok, char *tok)
#define mbstowcs(wtok, tok, size) mtw(wtok, tok) #define mbstowcs(wtok, tok, size) mtw(wtok, tok)
#endif #endif
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Surface * button_up, struct osk_keyboard *osk_create(char * layout_name, SDL_Surface * canvas,
SDL_Surface * button_down, SDL_Surface * button_off, SDL_Surface * button_nav, SDL_Surface * LG_button_up, SDL_Surface * LG_button_down,
SDL_Surface * button_hold, SDL_Surface * oskdel, SDL_Surface * osktab, SDL_Surface * LG_button_off, SDL_Surface * LG_button_nav,
SDL_Surface * oskenter, SDL_Surface * oskcapslock, SDL_Surface * oskshift, SDL_Surface * LG_button_hold,
SDL_Surface * LG_oskdel, SDL_Surface * LG_osktab, SDL_Surface * LG_oskenter,
SDL_Surface * LG_oskcapslock, SDL_Surface * LG_oskshift,
SDL_Surface * SM_button_up, SDL_Surface * SM_button_down,
SDL_Surface * SM_button_off, SDL_Surface * SM_button_nav,
SDL_Surface * SM_button_hold,
SDL_Surface * SM_oskdel, SDL_Surface * SM_osktab, SDL_Surface * SM_oskenter,
SDL_Surface * SM_oskcapslock, SDL_Surface * SM_oskshift,
int disable_change) int disable_change)
{ {
SDL_Surface *surface; SDL_Surface * surface;
osk_layout *layout; SDL_Surface * button_up, * button_down;
on_screen_keyboard *keyboard; SDL_Surface * button_off, * button_nav;
SDL_Surface * button_hold;
SDL_Surface * oskdel, * osktab, * oskenter;
SDL_Surface * oskcapslock, * oskshift;
osk_layout * layout;
on_screen_keyboard * keyboard;
keyboard = malloc(sizeof(on_screen_keyboard)); keyboard = malloc(sizeof(on_screen_keyboard));
@ -115,6 +127,32 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Sur
printf("w %i, h %i\n", layout->width, layout->height); printf("w %i, h %i\n", layout->width, layout->height);
#endif #endif
if (layout->width * LG_button_up->w >= canvas->w * 0.9 ||
layout->height * LG_button_up->h >= canvas->h * 0.5) {
/* Full-size buttons too large, use small buttons */
button_up = SM_button_up;
button_down = SM_button_down;
button_off = SM_button_off;
button_nav = SM_button_nav;
button_hold = SM_button_hold;
oskdel = SM_oskdel;
osktab = SM_osktab;
oskenter = SM_oskenter;
oskcapslock = SM_oskcapslock;
oskshift = SM_oskshift;
} else {
button_up = LG_button_up;
button_down = LG_button_down;
button_off = LG_button_off;
button_nav = LG_button_nav;
button_hold = LG_button_hold;
oskdel = LG_oskdel;
osktab = LG_osktab;
oskenter = LG_oskenter;
oskcapslock = LG_oskcapslock;
oskshift = LG_oskshift;
}
surface = SDL_CreateRGBSurface(canvas->flags, surface = SDL_CreateRGBSurface(canvas->flags,
layout->width * button_up->w, layout->width * button_up->w,
layout->height * button_up->h, layout->height * button_up->h,
@ -126,6 +164,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Sur
return NULL; return NULL;
} }
// keyboard->name = layout_name; // keyboard->name = layout_name;
keyboard->canvas_ptr = canvas;
keyboard->layout = layout; keyboard->layout = layout;
keyboard->surface = surface; keyboard->surface = surface;
keyboard->rect.x = 0; keyboard->rect.x = 0;
@ -159,6 +198,27 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Sur
keyboard->kmdf.dead3 = NULL; keyboard->kmdf.dead3 = NULL;
keyboard->kmdf.dead4 = NULL; keyboard->kmdf.dead4 = NULL;
keyboard->LG_button_up = LG_button_up;
keyboard->LG_button_down = LG_button_down;
keyboard->LG_button_off = LG_button_off;
keyboard->LG_button_nav = LG_button_nav;
keyboard->LG_button_hold = LG_button_hold;
keyboard->LG_oskdel = LG_oskdel;
keyboard->LG_osktab = LG_osktab;
keyboard->LG_oskenter = LG_oskenter;
keyboard->LG_oskcapslock = LG_oskcapslock;
keyboard->LG_oskshift = LG_oskshift;
keyboard->SM_button_up = SM_button_up;
keyboard->SM_button_down = SM_button_down;
keyboard->SM_button_off = SM_button_off;
keyboard->SM_button_nav = SM_button_nav;
keyboard->SM_button_hold = SM_button_hold;
keyboard->SM_oskdel = SM_oskdel;
keyboard->SM_osktab = SM_osktab;
keyboard->SM_oskenter = SM_oskenter;
keyboard->SM_oskcapslock = SM_oskcapslock;
keyboard->SM_oskshift = SM_oskshift;
SDL_FillRect(surface, NULL, SDL_FillRect(surface, NULL,
SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, keyboard->layout->bgcolor.g, SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, keyboard->layout->bgcolor.g,
keyboard->layout->bgcolor.b)); keyboard->layout->bgcolor.b));
@ -1005,36 +1065,40 @@ static int is_blank_or_comment(char *line)
/* } */ /* } */
/* Fixme: Is it safe to supose that if a font is loaded at one size, it will be loaded at any size? */ /* FIXME: Is it safe to supose that if a font is loaded at one size, it will be loaded at any size? */
/* Fixme: sizes should be dynamically adapted to the button size */ /* FIXME: starting a layout with one font causes all other layouts be in that font */
/* Fixme: starting a layout with one font causes all other layouts be in that font */
static void keybd_prepare(on_screen_keyboard * keyboard) static void keybd_prepare(on_screen_keyboard * keyboard)
{ {
char *fontname; char *fontname;
int font_height;
/* Pick a height (e.g., 16pt for small (24x24), 32pt for large (48x48) buttons) */
font_height = ((keyboard->button_up->h * 2) / 3);
fontname = malloc(sizeof(char) * 255); fontname = malloc(sizeof(char) * 255);
if (keyboard->osk_fonty == NULL) if (keyboard->osk_fonty == NULL)
{ {
if (keyboard->layout->fontpath) if (keyboard->layout->fontpath)
{ {
/* First try if it is an absolute path */ /* First try if it is an absolute path */
keyboard->osk_fonty = TTF_OpenFont(keyboard->layout->fontpath, 12); keyboard->osk_fonty = TTF_OpenFont(keyboard->layout->fontpath, font_height);
if (keyboard->osk_fonty == NULL) if (keyboard->osk_fonty == NULL)
{ {
/* Now trying if it is relative to DATA_PREFIX/fonts/ */ /* Now trying if it is relative to DATA_PREFIX/fonts/ */
snprintf(fontname, 255, "%s/fonts/%s", DATA_PREFIX, keyboard->layout->fontpath); snprintf(fontname, 255, "%s/fonts/%s", DATA_PREFIX, keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, 12); keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
if (keyboard->osk_fonty == NULL) if (keyboard->osk_fonty == NULL)
{ {
/* Perhaps it is relative to DATA_PREFIX only? */ /* Perhaps it is relative to DATA_PREFIX only? */
snprintf(fontname, 255, "%s/%s", DATA_PREFIX, keyboard->layout->fontpath); snprintf(fontname, 255, "%s/%s", DATA_PREFIX, keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, 12); keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
if (keyboard->osk_fonty == NULL) if (keyboard->osk_fonty == NULL)
{ {
/* Or to DATA_PREFIX/fonts/locale/ ? */ /* Or to DATA_PREFIX/fonts/locale/ ? */
snprintf(fontname, 255, "%s/fonts/locale/%s", DATA_PREFIX, keyboard->layout->fontpath); snprintf(fontname, 255, "%s/fonts/locale/%s", DATA_PREFIX, keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, 12); keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
} }
} }
} }
@ -1044,7 +1108,7 @@ static void keybd_prepare(on_screen_keyboard * keyboard)
{ {
/* Going with the default */ /* Going with the default */
sprintf(fontname, "%s/fonts/FreeSansBold.ttf", DATA_PREFIX); sprintf(fontname, "%s/fonts/FreeSansBold.ttf", DATA_PREFIX);
keyboard->osk_fonty = TTF_OpenFont(fontname, 12); keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
} }
if (keyboard->osk_fonty == NULL) if (keyboard->osk_fonty == NULL)
@ -1687,9 +1751,20 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
new_keyboard = new_keyboard =
osk_create(name, keyboard->surface, keyboard->button_up, keyboard->button_down, keyboard->button_off, osk_create(name, keyboard->canvas_ptr,
keyboard->button_nav, keyboard->button_hold, keyboard->oskdel, keyboard->osktab, keyboard->LG_button_up, keyboard->LG_button_down,
keyboard->oskenter, keyboard->oskcapslock, keyboard->oskshift, keyboard->disable_change); keyboard->LG_button_off, keyboard->LG_button_nav,
keyboard->LG_button_hold,
keyboard->LG_oskdel, keyboard->LG_osktab,
keyboard->LG_oskenter, keyboard->LG_oskcapslock,
keyboard->LG_oskshift,
keyboard->SM_button_up, keyboard->SM_button_down,
keyboard->SM_button_off, keyboard->SM_button_nav,
keyboard->SM_button_hold,
keyboard->SM_oskdel, keyboard->SM_osktab,
keyboard->SM_oskenter, keyboard->SM_oskcapslock,
keyboard->SM_oskshift,
keyboard->disable_change);
free(aux_list_ptr); free(aux_list_ptr);

View file

@ -104,13 +104,15 @@ typedef struct osk_keyboard
{ {
char *name; /* The name of the keyboard */ char *name; /* The name of the keyboard */
char *keyboard_list; /* The names of the keyboards allowed from this one */ char *keyboard_list; /* The names of the keyboards allowed from this one */
SDL_Surface *surface; /* The surface containing the keyboard */ SDL_Surface *surface; /* The surface containing the current layout's keyboard */
SDL_Surface *button_up; /* The surfaces containing the buttons */ /* The surfaces containing the current layout's button backgrounds*/
SDL_Surface *button_up;
SDL_Surface *button_down; SDL_Surface *button_down;
SDL_Surface *button_off; SDL_Surface *button_off;
SDL_Surface *button_nav; SDL_Surface *button_nav;
SDL_Surface *button_hold; SDL_Surface *button_hold;
SDL_Surface *oskdel; /* The surfaces containing some symbols for the buttons, delete arrow */ /* The surfaces containing some symbols for the current layout's buttons */
SDL_Surface *oskdel; /* delete arrow */
SDL_Surface *osktab; /* Tab arrows */ SDL_Surface *osktab; /* Tab arrows */
SDL_Surface *oskenter; /* Return hook/arrow */ SDL_Surface *oskenter; /* Return hook/arrow */
SDL_Surface *oskcapslock; /* CapsLock */ SDL_Surface *oskcapslock; /* CapsLock */
@ -131,12 +133,41 @@ typedef struct osk_keyboard
int composed_type; /* 1 if the value stored in composed is yet the unicode value */ int composed_type; /* 1 if the value stored in composed is yet the unicode value */
osk_composenode *composing; /* The node in the middle of a compose sequence */ osk_composenode *composing; /* The node in the middle of a compose sequence */
osk_key *last_key_pressed; /* The last key pressed */ osk_key *last_key_pressed; /* The last key pressed */
SDL_Surface * canvas_ptr; /* Canvas drawing surface, for bpp and sizing needs when cycling through keyboard layouts */
/* Large and small buttons, to pass back to osk_create() when cycling through keyboard layouts */
SDL_Surface *LG_button_up;
SDL_Surface *LG_button_down;
SDL_Surface *LG_button_off;
SDL_Surface *LG_button_nav;
SDL_Surface *LG_button_hold;
SDL_Surface *LG_oskdel;
SDL_Surface *LG_osktab;
SDL_Surface *LG_oskenter;
SDL_Surface *LG_oskcapslock;
SDL_Surface *LG_oskshift;
SDL_Surface *SM_button_up;
SDL_Surface *SM_button_down;
SDL_Surface *SM_button_off;
SDL_Surface *SM_button_nav;
SDL_Surface *SM_button_hold;
SDL_Surface *SM_oskdel;
SDL_Surface *SM_osktab;
SDL_Surface *SM_oskenter;
SDL_Surface *SM_oskcapslock;
SDL_Surface *SM_oskshift;
} on_screen_keyboard; } on_screen_keyboard;
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Surface * button_up, struct osk_keyboard *osk_create(char * layout_name, SDL_Surface * canvas,
SDL_Surface * button_down, SDL_Surface * button_off, SDL_Surface * button_nav, SDL_Surface * LG_button_up, SDL_Surface * LG_button_down,
SDL_Surface * button_hold, SDL_Surface * oskdel, SDL_Surface * osktab, SDL_Surface * LG_button_off, SDL_Surface * LG_button_nav,
SDL_Surface * oskenter, SDL_Surface * oskcapslock, SDL_Surface * oskshift, SDL_Surface * LG_button_hold,
SDL_Surface * LG_oskdel, SDL_Surface * LG_osktab, SDL_Surface * LG_oskenter,
SDL_Surface * LG_oskcapslock, SDL_Surface * LG_oskshift,
SDL_Surface * SM_button_up, SDL_Surface * SM_button_down,
SDL_Surface * SM_button_off, SDL_Surface * SM_button_nav,
SDL_Surface * SM_button_hold,
SDL_Surface * SM_oskdel, SDL_Surface * SM_osktab, SDL_Surface * SM_oskenter,
SDL_Surface * SM_oskcapslock, SDL_Surface * SM_oskshift,
int disable_change); int disable_change);
struct osk_layout *osk_load_layout(char *layout_name); struct osk_layout *osk_load_layout(char *layout_name);

View file

@ -22,7 +22,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt) (See COPYING.txt)
June 14, 2002 - August 16, 2020 June 14, 2002 - August 25, 2020
*/ */
@ -1430,7 +1430,7 @@ static int text_undo[NUM_UNDO_BUFS];
static int have_to_rec_label_node; static int have_to_rec_label_node;
static int have_to_rec_label_node_back; static int have_to_rec_label_node_back;
static SDL_Surface *img_title, *img_title_credits, *img_title_tuxpaint; static SDL_Surface *img_title, *img_title_credits, *img_title_tuxpaint;
static SDL_Surface *img_btn_up, *img_btn_down, *img_btn_off; static SDL_Surface *img_btn_up, *img_btn_down, *img_btn_off, *img_btn_hold;
static SDL_Surface *img_btnsm_up, *img_btnsm_off, *img_btnsm_down, *img_btnsm_hold; static SDL_Surface *img_btnsm_up, *img_btnsm_off, *img_btnsm_down, *img_btnsm_hold;
static SDL_Surface *img_btn_nav, *img_btnsm_nav; static SDL_Surface *img_btn_nav, *img_btnsm_nav;
static SDL_Surface *img_prev, *img_next; static SDL_Surface *img_prev, *img_next;
@ -3132,15 +3132,29 @@ static void mainloop(void)
{ {
if (onscreen_keyboard_layout) if (onscreen_keyboard_layout)
kbd = kbd =
osk_create(onscreen_keyboard_layout, screen, img_btnsm_up, img_btnsm_down, osk_create(onscreen_keyboard_layout, screen,
img_btnsm_off, img_btnsm_nav, img_btnsm_hold, img_oskdel, img_btn_up, img_btn_down, img_btn_off,
img_osktab, img_oskenter, img_oskcapslock, img_oskshift, img_btn_nav, img_btn_hold,
img_oskdel, img_osktab, img_oskenter,
img_oskcapslock, img_oskshift,
img_btnsm_up, img_btnsm_down, img_btnsm_off,
img_btnsm_nav, img_btnsm_hold,
/* FIXME */
img_oskdel, img_osktab, img_oskenter,
img_oskcapslock, img_oskshift,
onscreen_keyboard_disable_change); onscreen_keyboard_disable_change);
else else
kbd = kbd =
osk_create(strdup("default.layout"), screen, img_btnsm_up, img_btnsm_down, osk_create(strdup("default.layout"), screen,
img_btnsm_off, img_btnsm_nav, img_btnsm_hold, img_oskdel, img_btn_up, img_btn_down, img_btn_off,
img_osktab, img_oskenter, img_oskcapslock, img_oskshift, img_btn_nav, img_btn_hold,
img_oskdel, img_osktab, img_oskenter,
img_oskcapslock, img_oskshift,
img_btnsm_up, img_btnsm_down, img_btnsm_off,
img_btnsm_nav, img_btnsm_hold,
/* FIXME */
img_oskdel, img_osktab, img_oskenter,
img_oskcapslock, img_oskshift,
onscreen_keyboard_disable_change); onscreen_keyboard_disable_change);
} }
if (kbd == NULL) if (kbd == NULL)
@ -12644,6 +12658,7 @@ static void cleanup(void)
free_surface(&img_btn_up); free_surface(&img_btn_up);
free_surface(&img_btn_down); free_surface(&img_btn_down);
free_surface(&img_btn_off); free_surface(&img_btn_off);
free_surface(&img_btn_hold);
free_surface(&img_btnsm_up); free_surface(&img_btnsm_up);
free_surface(&img_btnsm_off); free_surface(&img_btnsm_off);
@ -24355,6 +24370,7 @@ static void setup(void)
img_btn_up = loadimage(DATA_PREFIX "images/ui/btn_up.png"); img_btn_up = loadimage(DATA_PREFIX "images/ui/btn_up.png");
img_btn_down = loadimage(DATA_PREFIX "images/ui/btn_down.png"); img_btn_down = loadimage(DATA_PREFIX "images/ui/btn_down.png");
img_btn_off = loadimage(DATA_PREFIX "images/ui/btn_off.png"); img_btn_off = loadimage(DATA_PREFIX "images/ui/btn_off.png");
img_btn_hold = loadimage(DATA_PREFIX "images/ui/btn_hold.png");
img_btnsm_up = loadimage(DATA_PREFIX "images/ui/btnsm_up.png"); img_btnsm_up = loadimage(DATA_PREFIX "images/ui/btnsm_up.png");
img_btnsm_off = loadimage(DATA_PREFIX "images/ui/btnsm_off.png"); img_btnsm_off = loadimage(DATA_PREFIX "images/ui/btnsm_off.png");