From 79bc5b2df454e799a7608bb35d5886c6ca74f1dd Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Fri, 20 Dec 2024 12:32:41 -0800 Subject: [PATCH] WIP Adding "Paste" button to On Screen Keyboard Appears, but does not yet actually invoke a paste event. Does not have an icon. --- docs/CHANGES.txt | 2 +- osk/abc.h_layout | 6 +++++- osk/qwerty.h_layout | 6 +++++- src/onscreen_keyboard.c | 24 +++++++++++++++++++----- src/onscreen_keyboard.h | 10 +++++++++- src/tuxpaint.c | 17 +++++++++++------ 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index ef79b4530..ef8b5b62a 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -13,7 +13,7 @@ https://tuxpaint.org/ into Tux Paint. If text goes beyond the right of the canvas, a new line is created. If text goes beyond the bottom of the canvas, the text is truncated there. - - TODO: Add a "paste" button to the On Screen Keyboards + - WIP: Add a "paste" button to the On Screen Keyboards - TODO: Improve word-wrapping (word-based, not character) - TODO: Mention the feature in documentation Closes https://sourceforge.net/p/tuxpaint/feature-requests/95/ diff --git a/osk/abc.h_layout b/osk/abc.h_layout index b498fd122..dfef72e99 100644 --- a/osk/abc.h_layout +++ b/osk/abc.h_layout @@ -131,10 +131,14 @@ KEY 133 2.0 Cmp Cmp Cmp Cmp 0 KEY 64 2.0 Alt Alt Alt Alt 0 # Space -KEY 65 7.0 SPACE SPACE SPACE SPACE 0 +KEY 65 5.0 SPACE SPACE SPACE SPACE 0 +# AltGr KEY 108 2.0 AltGr AltGr AltGr AltGr 0 +# Paste +KEY 143 2.0 Paste Paste Paste 0 + # Arrow to right will change to the next keyboard # Disabled for now... KEY 1 1.0 -> -> -> -> 0 diff --git a/osk/qwerty.h_layout b/osk/qwerty.h_layout index 6f939263b..a21eea3e5 100644 --- a/osk/qwerty.h_layout +++ b/osk/qwerty.h_layout @@ -126,10 +126,14 @@ KEY 133 2.0 Cmp Cmp Cmp Cmp 0 KEY 64 2.0 Alt Alt Alt Alt 0 # Space -KEY 65 7.0 SPACE SPACE SPACE SPACE 0 +KEY 65 5.0 SPACE SPACE SPACE SPACE 0 +# AltGr KEY 108 2.0 AltGr AltGr AltGr AltGr 0 +# Paste +KEY 143 2.0 Paste Paste Paste 0 + # Arrow to right will change to the next keyboard KEY 1 1.0 -> -> -> -> 0 diff --git a/src/onscreen_keyboard.c b/src/onscreen_keyboard.c index 99eee759b..20871b507 100644 --- a/src/onscreen_keyboard.c +++ b/src/onscreen_keyboard.c @@ -1,7 +1,7 @@ /* onscreen_keyboard.c - Copyright (c) 2011-2023 + Copyright (c) 2011-2024 https://tuxpaint.org/ This program is free software; you can redistribute it and/or modify @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - Last modified: March 23, 2023 + Last modified: December 19, 2024 */ #include "debug.h" @@ -90,14 +90,15 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *BLANK_oskdel, SDL_Surface *BLANK_osktab, SDL_Surface *BLANK_oskenter, - SDL_Surface *BLANK_oskcapslock, SDL_Surface *BLANK_oskshift, int disable_change) + SDL_Surface *BLANK_oskcapslock, SDL_Surface *BLANK_oskshift, + SDL_Surface *BLANK_oskpaste, int disable_change) { SDL_Surface *surface; SDL_Surface *button_up, *button_down; SDL_Surface *button_off, *button_nav; SDL_Surface *button_hold; SDL_Surface *oskdel, *osktab, *oskenter; - SDL_Surface *oskcapslock, *oskshift; + SDL_Surface *oskcapslock, *oskshift, *oskpaste; osk_layout *layout; on_screen_keyboard *keyboard; int layout_avail_width, layout_avail_height; @@ -171,6 +172,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, oskenter = zoomSurface(BLANK_oskenter, scale_w, scale_h, 1); oskcapslock = zoomSurface(BLANK_oskcapslock, scale_w, scale_h, 1); oskshift = zoomSurface(BLANK_oskshift, scale_w, scale_h, 1); + oskpaste = zoomSurface(BLANK_oskpaste, scale_w, scale_h, 1); } else { @@ -184,6 +186,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, oskenter = SDL_DisplayFormatAlpha(BLANK_oskenter); oskcapslock = SDL_DisplayFormatAlpha(BLANK_oskcapslock); oskshift = SDL_DisplayFormatAlpha(BLANK_oskshift); + oskpaste = SDL_DisplayFormatAlpha(BLANK_oskpaste); } surface = SDL_CreateRGBSurface(canvas->flags, @@ -214,6 +217,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, keyboard->oskenter = oskenter; keyboard->oskcapslock = oskcapslock; keyboard->oskshift = oskshift; + keyboard->oskpaste = oskpaste; keyboard->composing = layout->composemap; keyboard->composed = NULL; keyboard->last_key_pressed = NULL; @@ -241,6 +245,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, keyboard->BLANK_oskenter = BLANK_oskenter; keyboard->BLANK_oskcapslock = BLANK_oskcapslock; keyboard->BLANK_oskshift = BLANK_oskshift; + keyboard->BLANK_oskpaste = BLANK_oskpaste; SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, @@ -1444,6 +1449,11 @@ static void label_key(osk_key key, on_screen_keyboard *keyboard) apply_surface(key.x, key.y, keyboard->oskshift, keyboard->surface, NULL); } + else if (strncmp("PASTE", text, 5) == 0) + { + apply_surface(key.x, key.y, keyboard->oskpaste, keyboard->surface, NULL); + } + else if (strncmp("SPACE", text, 5) != 0 && strncmp("NULL", text, 4) != 0) { messager = TTF_RenderUTF8_Blended(keyboard->osk_fonty, text, keyboard->layout->fgcolor); @@ -1469,6 +1479,7 @@ static osk_key *find_key(on_screen_keyboard *keyboard, int x, int y) keyboard->layout->keys[j][i].x + keyboard->layout->keys[j][i].width * keyboard->button_up->w > x) { key = &keyboard->layout->keys[j][i]; +printf("find_key() -> key.keycode = %d\n", key->keycode); return key; } } @@ -1590,6 +1601,8 @@ static char *find_keysym(osk_key key, on_screen_keyboard *keyboard) keysym = keysyms.caps; } +printf("find_keysym() -> keysym = %s\n", keysym); // XF86Paste + return (keysym); } @@ -1811,7 +1824,8 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard *keyboard, int x, int y) keyboard->BLANK_button_hold, keyboard->BLANK_oskdel, keyboard->BLANK_osktab, keyboard->BLANK_oskenter, keyboard->BLANK_oskcapslock, - keyboard->BLANK_oskshift, keyboard->disable_change); + keyboard->BLANK_oskshift, keyboard->BLANK_oskshift, + keyboard->disable_change); free(aux_list_ptr); diff --git a/src/onscreen_keyboard.h b/src/onscreen_keyboard.h index dd88b8d1b..01f772ee1 100644 --- a/src/onscreen_keyboard.h +++ b/src/onscreen_keyboard.h @@ -1,3 +1,8 @@ +/* + Header for Tux Paint's on-screen keyboard. + Last modified: 2024-12-20 +*/ + #include "wchar.h" #include "stdio.h" #include "SDL.h" @@ -117,6 +122,7 @@ typedef struct osk_keyboard SDL_Surface *oskenter; /* Return hook/arrow */ SDL_Surface *oskcapslock; /* CapsLock */ SDL_Surface *oskshift; /* Shift */ + SDL_Surface *oskpaste; /* paste */ int changed; /* If the surface has been modified (painted) */ SDL_Rect rect; /* The rectangle that has changed */ int recreated; /* If the surface has been deleted and newly created */ @@ -145,6 +151,7 @@ typedef struct osk_keyboard SDL_Surface *BLANK_oskenter; SDL_Surface *BLANK_oskcapslock; SDL_Surface *BLANK_oskshift; + SDL_Surface *BLANK_oskpaste; } on_screen_keyboard; struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, @@ -156,7 +163,8 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Surface * BLANK_oskdel, SDL_Surface * BLANK_osktab, SDL_Surface * BLANK_oskenter, - SDL_Surface * BLANK_oskcapslock, SDL_Surface * BLANK_oskshift, int disable_change); + SDL_Surface * BLANK_oskcapslock, SDL_Surface * BLANK_oskshift, + SDL_Surface * BLANK_oskpaste, int disable_change); struct osk_layout *osk_load_layout(char *layout_name); diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 10b189e1f..39498264e 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -1700,7 +1700,7 @@ static SDL_Surface *img_title_on, *img_title_off, *img_title_large_on, *img_titl static SDL_Surface *img_title_names[NUM_TITLES]; static SDL_Surface *img_tools[NUM_TOOLS], *img_tool_names[NUM_TOOLS]; -static SDL_Surface *img_oskdel, *img_osktab, *img_oskenter, *img_oskcapslock, *img_oskshift; +static SDL_Surface *img_oskdel, *img_osktab, *img_oskenter, *img_oskcapslock, *img_oskshift, *img_oskpaste; static SDL_Surface *thumbnail(SDL_Surface * src, int max_x, int max_y, int keep_aspect); static SDL_Surface *thumbnail2(SDL_Surface * src, int max_x, int max_y, int keep_aspect, int keep_alpha); @@ -2823,7 +2823,6 @@ static void mainloop(void) /* handle_keymouse_buttons will move one button at a time */ handle_keymouse_buttons(key, &whicht, &whichc, real_r_tools); - if ((key == SDLK_ESCAPE || key == SDLK_AC_BACK) && !disable_quit) { magic_switchout(canvas); @@ -3718,14 +3717,16 @@ static void mainloop(void) img_btn_up, img_btn_down, img_btn_off, img_btn_nav, img_btn_hold, img_oskdel, img_osktab, img_oskenter, - img_oskcapslock, img_oskshift, onscreen_keyboard_disable_change); + img_oskcapslock, img_oskshift, img_oskpaste, + onscreen_keyboard_disable_change); else kbd = osk_create(strdup("default.layout"), canvas, img_btn_up, img_btn_down, img_btn_off, img_btn_nav, img_btn_hold, img_oskdel, img_osktab, img_oskenter, - img_oskcapslock, img_oskshift, onscreen_keyboard_disable_change); + img_oskcapslock, img_oskshift, img_oskpaste, + onscreen_keyboard_disable_change); } if (kbd == NULL) @@ -15552,6 +15553,7 @@ static void cleanup(void) free_surface(&img_oskenter); free_surface(&img_oskcapslock); free_surface(&img_oskshift); + free_surface(&img_oskpaste); if (kbd) osk_free(kbd); @@ -30525,6 +30527,7 @@ static void setup(void) img_oskenter = loadimagerb(DATA_PREFIX "images/ui/osk_enter.png"); img_oskcapslock = loadimagerb(DATA_PREFIX "images/ui/osk_capslock.png"); img_oskshift = loadimagerb(DATA_PREFIX "images/ui/osk_shift.png"); + img_oskpaste = loadimagerb(DATA_PREFIX "images/ui/osk_shift.png"); // FIXME if (onscreen_keyboard_layout) { @@ -30537,7 +30540,8 @@ static void setup(void) img_btn_up, img_btn_down, img_btn_off, img_btn_nav, img_btn_hold, img_oskdel, img_osktab, img_oskenter, - img_oskcapslock, img_oskshift, onscreen_keyboard_disable_change); + img_oskcapslock, img_oskshift, img_oskpaste, + onscreen_keyboard_disable_change); } else { @@ -30546,7 +30550,8 @@ static void setup(void) img_btn_up, img_btn_down, img_btn_off, img_btn_nav, img_btn_hold, img_oskdel, img_osktab, img_oskenter, - img_oskcapslock, img_oskshift, onscreen_keyboard_disable_change); + img_oskcapslock, img_oskshift, img_oskpaste, + onscreen_keyboard_disable_change); } }