Using PNGs as symbols in some onscreen keyboard keys.

This commit is contained in:
Pere Pujal i Carabantes 2014-03-31 13:50:23 +00:00
parent e6365974f6
commit 1dbe751b4e
10 changed files with 82 additions and 23 deletions

View file

@ -66,7 +66,7 @@ static void mtw(wchar_t * wtok, char * tok)
#define mbstowcs(wtok, tok, size) mtw(wtok, tok)
#endif
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *button_up, SDL_Surface *button_down, SDL_Surface *button_off, SDL_Surface *button_nav, SDL_Surface *button_hold, int disable_change)
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *button_up, SDL_Surface *button_down, SDL_Surface *button_off, SDL_Surface *button_nav, SDL_Surface *button_hold, SDL_Surface *oskdel, SDL_Surface *osktab, SDL_Surface *oskenter, SDL_Surface *oskcapslock, SDL_Surface *oskshift, int disable_change)
{
SDL_Surface *surface;
osk_layout *layout;
@ -116,6 +116,11 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surf
keyboard->button_off = button_off;
keyboard->button_nav = button_nav;
keyboard->button_hold = button_hold;
keyboard->oskdel = oskdel;
keyboard->osktab = osktab;
keyboard->oskenter = oskenter;
keyboard->oskcapslock = oskcapslock;
keyboard->oskshift = oskshift;
keyboard->composing = layout->composemap;
keyboard->composed = NULL;
keyboard->last_key_pressed = NULL;
@ -1281,7 +1286,32 @@ static void label_key(osk_key key, on_screen_keyboard *keyboard)
text = strdup(key.top_label);
}
if( strncmp("SPACE", text, 5) != 0 && strncmp("NULL", text, 4) != 0)
if( strncmp("DELETE", text, 6) == 0)
{
apply_surface(key.x, key.y, keyboard->oskdel, keyboard->surface, NULL);
}
else if( strncmp("TAB", text, 3) == 0)
{
apply_surface(key.x, key.y, keyboard->osktab, keyboard->surface, NULL);
}
else if( strncmp("ENTER", text, 5) == 0)
{
apply_surface(key.x, key.y, keyboard->oskenter, keyboard->surface, NULL);
}
else if( strncmp("CAPSLOCK", text, 8) == 0)
{
apply_surface(key.x, key.y, keyboard->oskcapslock, keyboard->surface, NULL);
}
else if( strncmp("SHIFT", text, 5) == 0)
{
apply_surface(key.x, key.y, keyboard->oskshift, keyboard->surface, NULL);
}
else if( strncmp("SPACE", text, 5) != 0 && strncmp("NULL", text, 4) != 0)
{
messager = TTF_RenderUTF8_Blended(osk_fonty, text, keyboard->layout->fgcolor);
@ -1643,7 +1673,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
}
new_keyboard = osk_create(name, keyboard->surface, keyboard->button_up, keyboard->button_down, keyboard->button_off, keyboard->button_nav, keyboard->button_hold, keyboard->disable_change);
new_keyboard = osk_create(name, keyboard->surface, keyboard->button_up, keyboard->button_down, keyboard->button_off, keyboard->button_nav, keyboard->button_hold, keyboard->oskdel, keyboard->osktab, keyboard->oskenter, keyboard->oskcapslock, keyboard->oskshift, keyboard->disable_change);
free(aux_list_ptr);

View file

@ -110,6 +110,11 @@ typedef struct osk_keyboard
SDL_Surface *button_off;
SDL_Surface *button_nav;
SDL_Surface *button_hold;
SDL_Surface *oskdel; /* The surfaces containing some symbols for the buttons, delete arrow */
SDL_Surface *osktab; /* Tab arrows */
SDL_Surface *oskenter; /* Return hook/arrow */
SDL_Surface *oskcapslock; /* CapsLock */
SDL_Surface *oskshift; /* Shift */
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 */
@ -127,7 +132,7 @@ typedef struct osk_keyboard
osk_key * last_key_pressed; /* The last key pressed */
} on_screen_keyboard;
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *button_up, SDL_Surface *button_down, SDL_Surface *button_off, SDL_Surface *button_nav, SDL_Surface *button_hold, int disable_change);
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *button_up, SDL_Surface *button_down, SDL_Surface *button_off, SDL_Surface *button_nav, SDL_Surface *button_hold, SDL_Surface *oskdel, SDL_Surface *osktab, SDL_Surface *oskenter, SDL_Surface *oskcapslock, SDL_Surface *oskshift, int disable_change);
struct osk_layout *osk_load_layout(char *layout_name);

View file

@ -1358,6 +1358,7 @@ static SDL_Surface *img_title_on, *img_title_off,
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 *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,
@ -3033,9 +3034,9 @@ static void mainloop(void)
if (kbd == NULL)
{
if (onscreen_keyboard_layout)
kbd = osk_create(onscreen_keyboard_layout, screen, img_btnsm_up, img_btnsm_down, img_btnsm_off, img_btnsm_nav, img_btnsm_hold, onscreen_keyboard_disable_change);
kbd = osk_create(onscreen_keyboard_layout, screen, img_btnsm_up, img_btnsm_down, img_btnsm_off, img_btnsm_nav, img_btnsm_hold, img_oskdel, img_osktab, img_oskenter, img_oskcapslock, img_oskshift, onscreen_keyboard_disable_change);
else
kbd = osk_create(strdup("default.layout"), screen, img_btnsm_up, img_btnsm_down, img_btnsm_off, img_btnsm_nav, img_btnsm_hold, onscreen_keyboard_disable_change);
kbd = osk_create(strdup("default.layout"), screen, img_btnsm_up, img_btnsm_down, img_btnsm_off, img_btnsm_nav, img_btnsm_hold, img_oskdel, img_osktab, img_oskenter, img_oskcapslock, img_oskshift, onscreen_keyboard_disable_change);
}
if (kbd == NULL)
printf("kbd = NULL\n");
@ -12199,6 +12200,15 @@ static void cleanup(void)
free(img_color_btns);
#endif
if (onscreen_keyboard)
{
free_surface(&img_oskdel);
free_surface(&img_osktab);
free_surface(&img_oskenter);
free_surface(&img_oskcapslock);
free_surface(&img_oskshift);
}
free_surface(&screen);
free_surface(&img_starter);
free_surface(&img_starter_bkgd);
@ -23143,6 +23153,15 @@ static void setup(void)
img_paintcan = loadimage(DATA_PREFIX "images/ui/paintcan.png");
#endif
if (onscreen_keyboard)
{
img_oskdel = loadimage(DATA_PREFIX "images/ui/osk_delete.png");
img_osktab = loadimage(DATA_PREFIX "images/ui/osk_tab.png");
img_oskenter = loadimage(DATA_PREFIX "images/ui/osk_enter.png");
img_oskcapslock = loadimage(DATA_PREFIX "images/ui/osk_capslock.png");
img_oskshift = loadimage(DATA_PREFIX "images/ui/osk_shift.png");
}
show_progress_bar(screen);