Showing the letters/symbols that will be produced in the onscreen keyboard.

This commit is contained in:
Pere Pujal i Carabantes 2011-11-09 12:23:39 +00:00
parent 283ea30d47
commit 010f81cca3
7 changed files with 340 additions and 188 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -18,24 +18,24 @@ HEIGHT 5
# For the purpose of osk should be: # For the purpose of osk should be:
# KEY keycode width label_plain label_top label_altgr shiftcaps # KEY keycode width label_plain label_top label_altgr label_shift_altgr shiftcaps
# shiftcaps means if the value of the key should be shifted if capslock is active # shiftcaps means if the value of the key should be shifted if capslock is active
# #
KEY 49 1.0 ` ~ NULL 0 KEY 49 1.0 ` ~ ` ~ 0
KEY 10 1.0 1 ! ¡ 0 KEY 10 1.0 1 ! ¡ ¹ 0
KEY 11 1.0 2 @ ² 0 KEY 11 1.0 2 @ ² ˝ 0
KEY 12 1.0 3 # · 0 KEY 12 1.0 3 # · ³ 0
KEY 13 1.0 4 $ ¤ 0 KEY 13 1.0 4 $ ¤ £ 0
KEY 14 1.0 5 % € 0 KEY 14 1.0 5 % € ¸ 0
KEY 15 1.0 6 ^ ¼ 0 KEY 15 1.0 6 ^ ¼ ^ 0
KEY 16 1.0 7 & ½ 0 KEY 16 1.0 7 & ½ ̛ 0
KEY 17 1.0 8 * ¾ 0 KEY 17 1.0 8 * ¾ ˛ 0
KEY 18 1.0 9 ( 0 KEY 18 1.0 9 ( ˘ 0
KEY 19 1.0 0 ) 0 KEY 19 1.0 0 ) ° 0
KEY 20 1.0 - _ ¥ 0 KEY 20 1.0 - _ ¥ ̣ 0
KEY 21 1.0 = + × 0 KEY 21 1.0 = + × ÷ 0
KEY 22 2.0 Back NULL NULL 0 KEY 22 2.0 Back Back Back Back 0
@ -43,7 +43,7 @@ KEY 22 2.0 Back NULL NULL 0
NEWLINE NEWLINE
# Tab # Tab
KEY 23 1.5 |<->| NULL NULL 0 KEY 23 1.5 |<->| |<->| |<->| |<->| 0
# Some tests to see how fonts works # Some tests to see how fonts works
#KEY 38 1.0 耳 NULL NULL #KEY 38 1.0 耳 NULL NULL
@ -52,65 +52,66 @@ KEY 23 1.5 |<->| NULL NULL 0
#KEY 40 1.0 φ NULL NULL #KEY 40 1.0 φ NULL NULL
#KEY 38 1.0 𐎈 NULL NULL #KEY 38 1.0 𐎈 NULL NULL
KEY 38 1.0 a NULL á 1 KEY 38 1.0 a A á Á 1
KEY 56 1.0 b NULL NULL 1 KEY 56 1.0 b B b B 1
KEY 54 1.0 c NULL © 1 KEY 54 1.0 c C © ¢ 1
KEY 40 1.0 d NULL ð 1 KEY 40 1.0 d D ð Ð 1
KEY 26 1.0 e NULL é 1 KEY 26 1.0 e E é É 1
KEY 41 1.0 f NULL NULL 1 KEY 41 1.0 f F f F 1
KEY 42 1.0 g NULL NULL 1 KEY 42 1.0 g G g G 1
KEY 43 1.0 h NULL NULL 1 KEY 43 1.0 h H h H 1
KEY 31 1.0 i NULL í 1 KEY 31 1.0 i I í Í 1
KEY 44 1.0 j NULL NULL 1 KEY 44 1.0 j J j J 1
KEY 34 1.0 [ { « 0 KEY 34 1.0 [ { « 0
KEY 35 1.0 ] } » 0 KEY 35 1.0 ] } » 0
KEY 51 1.5 \ | ¬ 0 KEY 51 1.5 \ | ¬ ¦ 0
NEWLINE NEWLINE
# CAPSLOCK # CAPSLOCK
KEY 66 2.0 Caps NULL NULL 0 KEY 66 2.0 Caps Caps Caps Caps 0
KEY 45 1.0 k NULL œ 1 KEY 45 1.0 k K œ Œ 1
KEY 46 1.0 l NULL ø 1 KEY 46 1.0 l L ø Ø 1
KEY 58 1.0 m NULL µ 1 KEY 58 1.0 m M µ µ 1
KEY 57 1.0 n NULL ñ 1 KEY 57 1.0 n N ñ Ñ 1
KEY 32 1.0 o NULL ó 1 KEY 32 1.0 o O ó Ó 1
KEY 33 1.0 p NULL ö 1 KEY 33 1.0 p P ö Ö 1
KEY 24 1.0 q NULL ä 1 KEY 24 1.0 q Q ä Ä 1
KEY 27 1.0 r NULL ® 1 KEY 27 1.0 r R ® ® 1
KEY 39 1.0 s NULL ß 1 KEY 39 1.0 s S ß § 1
KEY 47 1.0 ; : ¶ 0 KEY 47 1.0 ; : ¶ ° 0
KEY 48 1.0 ´ ¨ ' 0 KEY 48 1.0 ´ ¨ ' " 0
# Return # Return
KEY 36 2.0 Enter NULL NULL 0 KEY 36 2.0 Enter Enter Enter Enter 0
NEWLINE NEWLINE
KEY 50 2.5 Shift NULL NULL 0 KEY 50 2.5 Shift Shift Shift Shift 0
KEY 28 1.0 t NULL þ 1 KEY 28 1.0 t T þ Þ 1
KEY 30 1.0 u NULL ú 1 KEY 30 1.0 u U ú Ú 1
KEY 55 1.0 v NULL NULL 1 KEY 55 1.0 v V v V 1
KEY 25 1.0 w NULL å 1 KEY 25 1.0 w W å Å 1
KEY 53 1.0 x NULL NULL 1 KEY 53 1.0 x X x X 1
KEY 29 1.0 y NULL ü 1 KEY 29 1.0 y Y ü Ü 1
KEY 52 1.0 z NULL æ 1 KEY 52 1.0 z Z æ Æ 1
KEY 59 1.0 , < ç 0 KEY 59 1.0 , < ç Ç 0
KEY 60 1.0 . > ˙ 0
KEY 61 1.0 / ? ¿ 0 KEY 60 1.0 . > ˙ ˇ 0
KEY 62 2.5 Shift NULL NULL 0 KEY 61 1.0 / ? ¿ ̉ 0
KEY 62 2.5 Shift Shift Shift Shift 0
NEWLINE NEWLINE
# Arrow to left will change to the previous keyboard # Arrow to left will change to the previous keyboard
KEY 2 1.0 <- NULL NULL 0 KEY 2 1.0 <- <- <- <- 0
# notfound a proper fontfor this symbol... # notfound a proper fontfor this symbol...
#KEY 2 1.0 ← NULL NULL 0 #KEY 2 1.0 ← NULL NULL 0
@ -119,19 +120,19 @@ KEY 2 1.0 <- NULL NULL 0
#KEY 0 1.0 NULL NULL NULL 0 #KEY 0 1.0 NULL NULL NULL 0
KEY 133 2.0 Cmp NULL NULL 0 KEY 133 2.0 Cmp Cmp Cmp Cmp 0
# The ALT or ALTGR keys are used in im to switch the input mode. # The ALT or ALTGR keys are used in im to switch the input mode.
KEY 64 2.0 Alt NULL NULL 0 KEY 64 2.0 Alt Alt Alt Alt 0
# Space # Space
KEY 65 7.0 SPACE NULL NULL 0 KEY 65 7.0 SPACE SPACE SPACE SPACE 0
KEY 108 2.0 AltGr NULL NULL 0 KEY 108 2.0 AltGr AltGr AltGr AltGr 0
# Arrow to right will change to the next keyboard # Arrow to right will change to the next keyboard
# Disabled for now... # Disabled for now...
KEY 1 1.0 -> NULL NULL 0 KEY 1 1.0 -> -> -> -> 0
# Not found a proper font for this symbol... # Not found a proper font for this symbol...
#KEY 1 1.0 → NULL NULL 0 #KEY 1 1.0 → NULL NULL 0

View file

@ -9,6 +9,7 @@
# 0 empty button # 0 empty button
# 1 next layout # 1 next layout
# 2 previous layout # 2 previous layout
# 3 TODO reset modstate
# ABC layout of 15 buttons wide and 5 rows height # ABC layout of 15 buttons wide and 5 rows height
@ -18,26 +19,26 @@ HEIGHT 5
# For the purpose of osk should be: # For the purpose of osk should be:
# KEY keycode width label_plain label_top label_altgr shiftcaps # KEY keycode width label_plain label_top label_altgr label_shift_altgr shiftcaps
# shiftcaps means if the value of the key should be shifted if capslock is active # shiftcaps means if the value of the key should be shifted if capslock is active
# #
KEY 49 1.0 ` ~ NULL 0 KEY 49 1.0 ` ~ ` ~ 0
KEY 10 1.0 1 ! ¡ 0 KEY 10 1.0 1 ! ¡ ¹ 0
KEY 11 1.0 2 @ ² 0 KEY 11 1.0 2 @ ² ˝ 0
KEY 12 1.0 3 # · 0 KEY 12 1.0 3 # · ³ 0
KEY 13 1.0 4 $ ¤ 0 KEY 13 1.0 4 $ ¤ £ 0
KEY 14 1.0 5 % € 0 KEY 14 1.0 5 % € ¸ 0
KEY 15 1.0 6 ^ ¼ 0 KEY 15 1.0 6 ^ ¼ ^ 0
KEY 16 1.0 7 & ½ 0 KEY 16 1.0 7 & ½ ̛ 0
KEY 17 1.0 8 * ¾ 0 KEY 17 1.0 8 * ¾ ˛ 0
KEY 18 1.0 9 ( 0 KEY 18 1.0 9 ( ˘ 0
KEY 19 1.0 0 ) 0 KEY 19 1.0 0 ) ° 0
KEY 20 1.0 - _ ¥ 0 KEY 20 1.0 - _ ¥ ̣ 0
KEY 21 1.0 = + × 0 KEY 21 1.0 = + × ÷ 0
KEY 22 2.0 Back NULL NULL 0 KEY 22 2.0 Back Back Back Back 0
NEWLINE NEWLINE
@ -45,92 +46,92 @@ NEWLINE
# Tab # Tab
KEY 23 1.5 |<->| NULL NULL 0 KEY 23 1.5 |<->| |<->| |<->| |<->| 0
KEY 24 1.0 q NULL ä 1 KEY 24 1.0 q Q ä Ä 1
KEY 25 1.0 w NULL å 1 KEY 25 1.0 w W å Å 1
KEY 26 1.0 e NULL é 1 KEY 26 1.0 e E é É 1
KEY 27 1.0 r NULL ® 1 KEY 27 1.0 r R ® ® 1
KEY 28 1.0 t NULL þ 1 KEY 28 1.0 t T þ Þ 1
KEY 29 1.0 y NULL ü 1 KEY 29 1.0 y Y ü Ü 1
KEY 30 1.0 u NULL ú 1 KEY 30 1.0 u U ú Ú 1
KEY 31 1.0 i NULL í 1 KEY 31 1.0 i I í Í 1
KEY 32 1.0 o NULL ó 1 KEY 32 1.0 o O ó Ó 1
KEY 33 1.0 p NULL ö 1 KEY 33 1.0 p P ö Ö 1
KEY 34 1.0 [ { « 0 KEY 34 1.0 [ { « 0
KEY 35 1.0 ] } » 0 KEY 35 1.0 ] } » 0
KEY 51 1.5 \ | ¬ 0 KEY 51 1.5 \ | ¬ ¦ 0
NEWLINE NEWLINE
# CAPSLOCK # CAPSLOCK
KEY 66 2.0 Caps NULL NULL 0 KEY 66 2.0 Caps Caps Caps Caps 0
KEY 38 1.0 a NULL á 1 KEY 38 1.0 a A á Á 1
KEY 39 1.0 s NULL ß 1 KEY 39 1.0 s S ß § 1
KEY 40 1.0 d NULL ð 1 KEY 40 1.0 d D ð Ð 1
KEY 41 1.0 f NULL NULL 1 KEY 41 1.0 f F f F 1
KEY 42 1.0 g NULL NULL 1 KEY 42 1.0 g G g G 1
KEY 43 1.0 h NULL NULL 1 KEY 43 1.0 h H h H 1
KEY 44 1.0 j NULL NULL 1 KEY 44 1.0 j J j J 1
KEY 45 1.0 k NULL œ 1 KEY 45 1.0 k K œ Œ 1
KEY 46 1.0 l NULL ø 1 KEY 46 1.0 l L ø Ø 1
KEY 47 1.0 ; : ¶ 0 KEY 47 1.0 ; : ¶ ° 0
KEY 48 1.0 ´ ¨ ' 0 KEY 48 1.0 ´ ¨ ' " 0
# Return # Return
KEY 36 2.0 Enter NULL NULL 0 KEY 36 2.0 Enter Enter Enter Enter 0
NEWLINE NEWLINE
KEY 50 2.5 Shift NULL NULL 0 KEY 50 2.5 Shift Shift Shift Shift 0
KEY 52 1.0 z NULL æ 1 KEY 52 1.0 z Z æ Æ 1
KEY 53 1.0 x NULL NULL 1 KEY 53 1.0 x X x X 1
KEY 54 1.0 c NULL © 1 KEY 54 1.0 c C © ¢ 1
KEY 55 1.0 v NULL NULL 1 KEY 55 1.0 v V v V 1
KEY 56 1.0 b NULL NULL 1 KEY 56 1.0 b B b B 1
KEY 57 1.0 n NULL ñ 1 KEY 57 1.0 n N ñ Ñ 1
KEY 58 1.0 m NULL µ 1 KEY 58 1.0 m M µ µ 1
KEY 59 1.0 , < ç 0 KEY 59 1.0 , < ç Ç 0
KEY 60 1.0 . > ˙ 0 KEY 60 1.0 . > ˙ ˇ 0
KEY 61 1.0 / ? ¿ 0 KEY 61 1.0 / ? ¿ ̉ 0
KEY 62 2.5 Shift NULL NULL 0 KEY 62 2.5 Shift Shift Shift Shift 0
NEWLINE NEWLINE
# Arrow to left will change to the previous keyboard # Arrow to left will change to the previous keyboard
KEY 2 1.0 <- NULL NULL 0 KEY 2 1.0 <- <- <- <- 0
# Empty button # Empty button
#KEY 0 1.0 NULL NULL NULL 0 #KEY 0 1.0 NULL NULL NULL NULL 0
KEY 133 2.0 Cmp NULL NULL 0 KEY 133 2.0 Cmp Cmp Cmp Cmp 0
# The ALT or ALTGR keys are used in im to switch the input mode. # The ALT or ALTGR keys are used in im to switch the input mode.
KEY 64 2.0 Alt NULL NULL 0 KEY 64 2.0 Alt Alt Alt Alt 0
# Space # Space
KEY 65 7.0 SPACE NULL NULL 0 KEY 65 7.0 SPACE SPACE SPACE SPACE 0
KEY 108 2.0 AltGr NULL NULL 0 KEY 108 2.0 AltGr AltGr AltGr AltGr 0
# Arrow to right will change to the next keyboard # Arrow to right will change to the next keyboard
KEY 1 1.0 -> NULL NULL 0 KEY 1 1.0 -> -> -> -> 0

View file

@ -9,8 +9,11 @@
# 0 empty button # 0 empty button
# 1 next layout # 1 next layout
# 2 previous layout # 2 previous layout
# TODO 3 reset modstate
# ABC layout of 15 buttons wide and 5 rows height
# layout of 25 buttons wide and 1 row height
WIDTH 25 WIDTH 25
HEIGHT 1 HEIGHT 1
@ -18,42 +21,42 @@ HEIGHT 1
# For the purpose of osk should be: # For the purpose of osk should be:
# KEY keycode width label_plain label_top label_altgr shiftcaps # KEY keycode width label_plain label_top label_altgr label_altgr_top shiftcaps
# shiftcaps means if the value of the key should be shifted if capslock is active # shiftcaps means if the value of the key should be shifted if capslock is active
# #
# Arrow to left will change to the previous keyboard # Arrow to left will change to the previous keyboard
# Disabled for now...
KEY 2 1.5 <-- NULL NULL NULL 0
KEY 0 2.0 NULL NULL NULL 0
KEY 10 1.0 1 ! ¡ 0 KEY 2 1.5 <-- NULL NULL NULL NULL 0
KEY 11 1.0 2 @ ² 0 KEY 0 1.0 NULL NULL NULL NULL 0
KEY 12 1.0 3 # · 0
KEY 13 1.0 4 $ ¤ 0
KEY 14 1.0 5 % € 0
KEY 15 1.0 6 ^ ¼ 0
KEY 16 1.0 7 & ½ 0
KEY 17 1.0 8 * ¾ 0
KEY 18 1.0 9 ( 0
KEY 19 1.0 0 ) 0
KEY 0 1.0 NULL NULL NULL 0
KEY 20 1.0 - _ ¥ 0 KEY 10 1.0 1 ! ¡ ¹ 0
KEY 21 1.0 = + × 0 KEY 11 1.0 2 @ ² ˝ 0
KEY 0 2.0 NULL NULL NULL 0 KEY 12 1.0 3 # · ³ 0
KEY 13 1.0 4 $ ¤ £ 0
KEY 14 1.0 5 % € ¸ 0
KEY 15 1.0 6 ^ ¼ ^ 0
KEY 16 1.0 7 & ½ ̛ 0
KEY 17 1.0 8 * ¾ ˛ 0
KEY 18 1.0 9 ( ˘ 0
KEY 19 1.0 0 ) ° 0
KEY 0 1.0 NULL NULL NULL NULL 0
KEY 20 1.0 - _ ¥ ̣ 0
KEY 21 1.0 = + × ÷ 0
KEY 0 1.0 NULL NULL NULL NULL 0
KEY 22 2.0 Back NULL NULL 0 KEY 22 2.0 Back Back Back Back 0
# Return # Return
KEY 36 2.0 Enter NULL NULL 0 KEY 36 2.0 Enter Enter Enter Enter 0
KEY 1 1.5 --> NULL NULL NULL 0 KEY 1 1.5 --> NULL NULL NULL NULL 0

View file

@ -31,7 +31,7 @@ static struct osk_layout *load_layout(on_screen_keyboard *keyboard, char *layout
static void print_composemap(osk_composenode *composemap, char * sp); static void print_composemap(osk_composenode *composemap, char * sp);
#endif #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, 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, int disable_change)
{ {
SDL_Surface *surface; SDL_Surface *surface;
osk_layout *layout; osk_layout *layout;
@ -78,6 +78,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surf
keyboard->button_down = button_down; keyboard->button_down = button_down;
keyboard->button_off = button_off; keyboard->button_off = button_off;
keyboard->button_nav = button_nav; keyboard->button_nav = button_nav;
keyboard->button_hold = button_hold;
keyboard->composing = layout->composemap; keyboard->composing = layout->composemap;
keyboard->composed = NULL; keyboard->composed = NULL;
keyboard->last_key_pressed = NULL; keyboard->last_key_pressed = NULL;
@ -88,6 +89,13 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surf
set_key(NULL, &keyboard->keymodifiers.compose, 1); set_key(NULL, &keyboard->keymodifiers.compose, 1);
set_key(NULL, &keyboard->keymodifiers.dead, 1); set_key(NULL, &keyboard->keymodifiers.dead, 1);
keyboard->kmdf.shift = NULL;
keyboard->kmdf.altgr = NULL;
keyboard->kmdf.dead = NULL;
keyboard->kmdf.dead2 = NULL;
keyboard->kmdf.dead3 = NULL;
keyboard->kmdf.dead4 = NULL;
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, keyboard->layout->bgcolor.g, keyboard->layout->bgcolor.b)); SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, keyboard->layout->bgcolor.g, keyboard->layout->bgcolor.b));
keybd_prepare(keyboard); keybd_prepare(keyboard);
@ -213,7 +221,7 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
char *filename; char *filename;
char *line; char *line;
char *key, *fontpath; char *key, *fontpath;
wchar_t *plain_label, *top_label, *altgr_label; wchar_t *plain_label, *top_label, *altgr_label, *shift_altgr_label;
FILE * fi; FILE * fi;
key_number = line_number = 0; key_number = line_number = 0;
@ -269,6 +277,7 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
layout->keys[0][i].plain_label = NULL; layout->keys[0][i].plain_label = NULL;
layout->keys[ line_number][i].top_label=NULL; layout->keys[ line_number][i].top_label=NULL;
layout->keys[ line_number][i].altgr_label=NULL; layout->keys[ line_number][i].altgr_label=NULL;
layout->keys[ line_number][i].shift_altgr_label=NULL;
} }
layout->width = width; layout->width = width;
layout->height = height; layout->height = height;
@ -330,6 +339,7 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
layout->keys[ line_number][i].plain_label=NULL; layout->keys[ line_number][i].plain_label=NULL;
layout->keys[ line_number][i].top_label=NULL; layout->keys[ line_number][i].top_label=NULL;
layout->keys[ line_number][i].altgr_label=NULL; layout->keys[ line_number][i].altgr_label=NULL;
layout->keys[ line_number][i].shift_altgr_label=NULL;
} }
} }
@ -339,9 +349,10 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
plain_label = malloc(64); plain_label = malloc(64);
top_label = malloc(64); top_label = malloc(64);
altgr_label = malloc(64); altgr_label = malloc(64);
shift_altgr_label = malloc(64);
sscanf(line, sscanf(line,
"%s %i %i.%i %ls %ls %ls %i", "%s %i %i.%i %ls %ls %ls %ls %i",
key, key,
&keycode, &keycode,
&key_width, &key_width,
@ -349,13 +360,16 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
plain_label, plain_label,
top_label, top_label,
altgr_label, altgr_label,
shift_altgr_label,
&shiftcaps); &shiftcaps);
layout->keys[line_number][key_number].keycode = keycode; layout->keys[line_number][key_number].keycode = keycode;
layout->keys[line_number][key_number].width = (float)0.1 * key_width_decimal + key_width; layout->keys[line_number][key_number].width = (float)0.1 * key_width_decimal + key_width;
layout->keys[line_number][key_number].plain_label = plain_label; layout->keys[line_number][key_number].plain_label = plain_label;
layout->keys[line_number][key_number].top_label = top_label; layout->keys[line_number][key_number].top_label = top_label;
layout->keys[line_number][key_number].altgr_label = altgr_label; layout->keys[line_number][key_number].altgr_label = altgr_label;
layout->keys[line_number][key_number].shift_altgr_label = shift_altgr_label;
layout->keys[line_number][key_number].shiftcaps = shiftcaps; layout->keys[line_number][key_number].shiftcaps = shiftcaps;
layout->keys[line_number][key_number].stick = 0;
key_number ++; key_number ++;
} }
} }
@ -1052,7 +1066,7 @@ static void draw_keyboard(on_screen_keyboard *keyboard)
float key_width; float key_width;
key_width = keyboard->button_up->w; key_width = keyboard->button_up->w;
key_height = keyboard->button_up->h; key_height = keyboard->button_up->h;
printf("dkbd\n");
accumulated_height = 0; accumulated_height = 0;
for (j = 0; j < keyboard->layout->height; j++) for (j = 0; j < keyboard->layout->height; j++)
@ -1072,6 +1086,11 @@ static void draw_keyboard(on_screen_keyboard *keyboard)
} }
accumulated_height += key_height; accumulated_height += key_height;
} }
/* draw_key(keyboard->keymodifiers.shift, keyboard, 0); */
/* draw_key(keyboard->keymodifiers.altgr, keyboard, 0); */
/* draw_key(keyboard->keymodifiers.compose, keyboard, 0); */
/* draw_key(keyboard->keymodifiers.dead, keyboard, 0); */
} }
static void draw_key(osk_key key, on_screen_keyboard * keyboard, int hot) static void draw_key(osk_key key, on_screen_keyboard * keyboard, int hot)
@ -1087,7 +1106,13 @@ static void draw_key(osk_key key, on_screen_keyboard * keyboard, int hot)
if( strncmp("NULL", text, 4) != 0 && key.keycode != 0) if( strncmp("NULL", text, 4) != 0 && key.keycode != 0)
{ {
if (!hot) if (hot)
skey = stretch_surface(keyboard->button_down, key.width * keyboard->button_down->w);
else if (key.stick)
skey = stretch_surface(keyboard->button_hold, key.width * keyboard->button_hold->w);
else
{ {
if (key.keycode == 1 || key.keycode == 2) if (key.keycode == 1 || key.keycode == 2)
{ {
@ -1099,8 +1124,6 @@ static void draw_key(osk_key key, on_screen_keyboard * keyboard, int hot)
else else
skey = stretch_surface(keyboard->button_up, key.width * keyboard->button_up->w); skey = stretch_surface(keyboard->button_up, key.width * keyboard->button_up->w);
} }
else
skey = stretch_surface(keyboard->button_down, key.width * keyboard->button_down->w);
} }
else else
skey = stretch_surface(keyboard->button_off, key.width * keyboard->button_off->w); skey = stretch_surface(keyboard->button_off, key.width * keyboard->button_off->w);
@ -1118,14 +1141,72 @@ static void label_key(osk_key key, on_screen_keyboard *keyboard)
{ {
Uint16 *ustr; Uint16 *ustr;
SDL_Surface *messager; SDL_Surface *messager;
char *text; int modstate;
text = malloc(255); wchar_t *text;
snprintf(text, 6,"%ls", key.plain_label);
if( strncmp("SPACE", text, 5) != 0 && strncmp("NULL",text, 4) != 0) /* To remove a warning... */
text = NULL;
modstate = keyboard->modifiers;
/* FIXME There MUST be a simpler way to do this. Pere 2011/8/3 */
/* First the plain ones */
if (modstate == KMOD_NONE || (modstate == (KMOD_NONE | KMOD_LALT)))
text = wcsdup(key.plain_label);
else if (modstate == KMOD_SHIFT)
{ {
ustr = wcstou16(key.plain_label); text = wcsdup(key.top_label);
//messager = TTF_RenderUNICODE_Solid( }
else if (modstate == KMOD_RALT)
{
text = wcsdup(key.altgr_label);
}
else if (modstate == KMOD_CAPS)
{
if (key.shiftcaps)
text = wcsdup(key.top_label);
else
text = wcsdup(key.plain_label);
}
/* Now the combined ones */
else if (modstate & KMOD_RALT && modstate & KMOD_SHIFT)
{
if (modstate & KMOD_CAPS)
{
if (key.shiftcaps)
text = wcsdup(key.altgr_label);
else
text = wcsdup(key.shift_altgr_label);
}
else
{
text = wcsdup(key.shift_altgr_label);
}
}
else if (modstate & KMOD_RALT && modstate & KMOD_CAPS && !(modstate & KMOD_SHIFT))
{
if (key.shiftcaps)
text = wcsdup(key.shift_altgr_label);
else
text = wcsdup(key.altgr_label);
}
else if (modstate & KMOD_SHIFT && modstate & KMOD_CAPS)
{
if (key.shiftcaps)
text = wcsdup(key.plain_label);
else
text = wcsdup(key.top_label);
}
if( wcsncmp(L"SPACE", text, 5) != 0 && wcsncmp(L"NULL", text, 4) != 0)
{
ustr = wcstou16(text);
messager = TTF_RenderUNICODE_Blended(osk_fonty, ustr, keyboard->layout->fgcolor); messager = TTF_RenderUNICODE_Blended(osk_fonty, ustr, keyboard->layout->fgcolor);
free(ustr); free(ustr);
@ -1140,8 +1221,8 @@ static osk_key * find_key(on_screen_keyboard * keyboard, int x, int y)
{ {
int i, j; int i, j;
osk_key *key; osk_key *key;
key =malloc(sizeof(osk_key));
key = NULL;
for (j = 0; j <keyboard->layout->height; j++) for (j = 0; j <keyboard->layout->height; j++)
{ {
if (keyboard->layout->keys[j][0].y < y && if (keyboard->layout->keys[j][0].y < y &&
@ -1150,11 +1231,11 @@ static osk_key * find_key(on_screen_keyboard * keyboard, int x, int y)
if (keyboard->layout->keys[j][i].x < x && if (keyboard->layout->keys[j][i].x < x &&
keyboard->layout->keys[j][i].x + keyboard->layout->keys[j][i].width * keyboard->button_up->w > x) keyboard->layout->keys[j][i].x + keyboard->layout->keys[j][i].width * keyboard->button_up->w > x)
{ {
*key = keyboard->layout->keys[j][i]; key = &keyboard->layout->keys[j][i];
return key; return key;
} }
} }
free(key);
return NULL; return NULL;
} }
@ -1276,7 +1357,7 @@ static char * find_keysym(osk_key key, on_screen_keyboard *keyboard)
} }
/* We lose the SDL ModState by leaving and entering the tuxpaint window, so using a custom state */ /* We lose the SDL ModState by leaving and entering the tuxpaint window, so using a custom state */
static int handle_keymods(char * keysym, osk_key key, on_screen_keyboard *keyboard) static int handle_keymods(char * keysym, osk_key * key, on_screen_keyboard *keyboard)
{ {
SDLMod mod; SDLMod mod;
SDL_Event ev; SDL_Event ev;
@ -1287,16 +1368,16 @@ static int handle_keymods(char * keysym, osk_key key, on_screen_keyboard *keyboa
{ {
if (mod & KMOD_SHIFT) if (mod & KMOD_SHIFT)
{ {
draw_key(key, keyboard, 0);
keyboard->modifiers = mod & 0xFFF0; keyboard->modifiers = mod & 0xFFF0;
key->stick = 0;
keyboard->kmdf.shift->stick = 0;
} }
else else
{ {
draw_key(key, keyboard, 1);
keyboard->modifiers = mod | KMOD_SHIFT; keyboard->modifiers = mod | KMOD_SHIFT;
set_key(&key, &keyboard->keymodifiers.shift, 0); key->stick = 1;
keyboard->kmdf.shift = key;
} }
return 1; return 1;
} }
else if (strncmp("Alt_L", keysym, 5) == 0) else if (strncmp("Alt_L", keysym, 5) == 0)
@ -1317,12 +1398,15 @@ static int handle_keymods(char * keysym, osk_key key, on_screen_keyboard *keyboa
strncmp("ALT_R", keysym, 5) == 0) strncmp("ALT_R", keysym, 5) == 0)
{ {
if (mod & KMOD_RALT) if (mod & KMOD_RALT)
{
keyboard->modifiers = mod & 0xF0FF; keyboard->modifiers = mod & 0xF0FF;
keyboard->kmdf.altgr->stick = 0;
}
else else
{ {
keyboard->modifiers = mod | KMOD_RALT; keyboard->modifiers = mod | KMOD_RALT;
draw_key(key, keyboard, 1); key->stick = 1;
set_key(&key, &keyboard->keymodifiers.altgr, 0); keyboard->kmdf.altgr = key;
return 1; return 1;
} }
@ -1333,17 +1417,19 @@ static int handle_keymods(char * keysym, osk_key key, on_screen_keyboard *keyboa
{ {
if (mod & KMOD_CAPS) if (mod & KMOD_CAPS)
{ {
draw_key(key, keyboard, 0);
keyboard->modifiers = mod & 0x0FFF; keyboard->modifiers = mod & 0x0FFF;
key->stick = 0;
} }
else else
{ {
keyboard->modifiers = mod | KMOD_CAPS; keyboard->modifiers = mod | KMOD_CAPS;
draw_key(key, keyboard, 1); key->stick = 1;
} }
return 1; return 1;
} }
if (mod & KMOD_CAPS) if (mod & KMOD_CAPS)
{ {
keyboard->modifiers = KMOD_CAPS; keyboard->modifiers = KMOD_CAPS;
@ -1351,12 +1437,53 @@ static int handle_keymods(char * keysym, osk_key key, on_screen_keyboard *keyboa
else else
keyboard->modifiers = KMOD_NONE; keyboard->modifiers = KMOD_NONE;
draw_key(keyboard->keymodifiers.shift, keyboard, 0); if(keyboard->kmdf.shift)
draw_key(keyboard->keymodifiers.altgr, keyboard, 0); keyboard->kmdf.shift->stick = 0;
if(keyboard->kmdf.altgr)
keyboard->kmdf.altgr->stick = 0;
return 0; return 0;
} }
/* set_dead_sticks and clear_dead_sticks deals with the persistence of
the keys that are still affecting other key presses. */
static void set_dead_sticks(osk_key *key, on_screen_keyboard *keyboard)
{
key->stick= 1;
if(!keyboard->kmdf.dead)
keyboard->kmdf.dead = key;
else if(!keyboard->kmdf.dead2)
keyboard->kmdf.dead2 = key;
else if(!keyboard->kmdf.dead3)
keyboard->kmdf.dead3 = key;
else if(!keyboard->kmdf.dead4)
keyboard->kmdf.dead4 = key;
}
static void clear_dead_sticks(on_screen_keyboard *keyboard)
{
if(keyboard->kmdf.dead)
{
keyboard->kmdf.dead->stick = 0;
keyboard->kmdf.dead = NULL;
}
if(keyboard->kmdf.dead2)
{
keyboard->kmdf.dead2->stick = 0;
keyboard->kmdf.dead2 = NULL;
}
if(keyboard->kmdf.dead3)
{
keyboard->kmdf.dead3->stick = 0;
keyboard->kmdf.dead3 = NULL;
}
if(keyboard->kmdf.dead4)
{
keyboard->kmdf.dead4->stick = 0;
keyboard->kmdf.dead4 = NULL;
}
}
struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y) struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
{ {
int i; int i;
@ -1384,7 +1511,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
{ {
if (keyboard->disable_change) if (keyboard->disable_change)
{ {
free(key); // free(key);
return(keyboard); return(keyboard);
} }
@ -1435,20 +1562,20 @@ 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->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->disable_change);
free(aux_list_ptr); free(aux_list_ptr);
if (new_keyboard == NULL) if (new_keyboard == NULL)
{ {
free(key); // free(key);
return(keyboard); /* Don't break here, at least the old keyboard should work */ return(keyboard); /* Don't break here, at least the old keyboard should work */
} }
else else
{ {
free(new_keyboard->keyboard_list); free(new_keyboard->keyboard_list);
new_keyboard->keyboard_list = strdup(keyboard->keyboard_list); new_keyboard->keyboard_list = strdup(keyboard->keyboard_list);
free(key); // free(key);
osk_free(keyboard); osk_free(keyboard);
return(new_keyboard); return(new_keyboard);
} }
@ -1458,18 +1585,16 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
keysym = find_keysym(*key, keyboard); keysym = find_keysym(*key, keyboard);
if (!keysym) if (!keysym)
{ {
free(key);
return(keyboard); return(keyboard);
} }
if (handle_keymods(keysym, *key, keyboard)) draw_key(*key, keyboard, 1);
if (handle_keymods(keysym, key, keyboard))
{ {
free(key);
return(keyboard); /* no more processing is needed */ return(keyboard); /* no more processing is needed */
} }
draw_key(*key, keyboard, 1);
wkeysym = malloc(sizeof(wchar_t) * (strlen(keysym) + 1)); wkeysym = malloc(sizeof(wchar_t) * (strlen(keysym) + 1));
mbsrtowcs(wkeysym, (const char **) &keysym, mbsrtowcs(wkeysym, (const char **) &keysym,
@ -1480,7 +1605,6 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
get_composed_keysym(keyboard, keyboard->composing, wkeysym); get_composed_keysym(keyboard, keyboard->composing, wkeysym);
draw_key(keyboard->keymodifiers.compose, keyboard, 0);
if (keyboard->composed) if (keyboard->composed)
{ {
@ -1517,6 +1641,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
else else
event.key.keysym.unicode = keysym2unicode(mnemo2keysym(mnemo, keyboard), keyboard); event.key.keysym.unicode = keysym2unicode(mnemo2keysym(mnemo, keyboard), keyboard);
clear_dead_sticks(keyboard);
event.type = SDL_KEYDOWN; event.type = SDL_KEYDOWN;
SDL_PushEvent(&event); SDL_PushEvent(&event);
free(mnemo); free(mnemo);
@ -1528,12 +1653,14 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
printf("compose sequence resetted %d\n", (int)keyboard->composing); printf("compose sequence resetted %d\n", (int)keyboard->composing);
set_key(NULL, &keyboard->keymodifiers.compose, 0); set_key(NULL, &keyboard->keymodifiers.compose, 0);
keyboard->last_key_pressed = key; keyboard->last_key_pressed = key;
clear_dead_sticks(keyboard);
} }
else else
{ {
set_key(key, &keyboard->keymodifiers.compose, 0); set_key(key, &keyboard->keymodifiers.compose, 0);
printf("still composing %d\n", (int)keyboard->composing); printf("still composing %d\n", (int)keyboard->composing);
free(key); set_dead_sticks(key, keyboard);
/* Fixme: Would be nice if we can highlight next available-to-compose keys, but how? */
} }
} }
free(wkeysym); free(wkeysym);
@ -1549,10 +1676,10 @@ void osk_released(on_screen_keyboard *keyboard)
if (key) if (key)
{ {
draw_key(*key, keyboard, 0); draw_key(*key, keyboard, 0);
free(key); // free(key);
} }
keyboard->last_key_pressed = NULL; keyboard->last_key_pressed = NULL;
draw_keyboard(keyboard);
} }
@ -1612,6 +1739,9 @@ static void free_keys(osk_layout *layout)
free(layout->keys[j][i].top_label); free(layout->keys[j][i].top_label);
if (layout->keys[j][i].altgr_label) if (layout->keys[j][i].altgr_label)
free(layout->keys[j][i].altgr_label); free(layout->keys[j][i].altgr_label);
if (layout->keys[j][i].shift_altgr_label)
free(layout->keys[j][i].shift_altgr_label);
} }
free(layout->keys[j]); free(layout->keys[j]);
} }

View file

@ -44,7 +44,9 @@ typedef struct osk_key
wchar_t *plain_label; /* The text that will show the key */ wchar_t *plain_label; /* The text that will show the key */
wchar_t *top_label; /* The text that will show the key above the plain label. */ wchar_t *top_label; /* The text that will show the key above the plain label. */
wchar_t *altgr_label; /* The text that will show the key at the right of the plain label */ wchar_t *altgr_label; /* The text that will show the key at the right of the plain label */
wchar_t *shift_altgr_label; /* The text that will show the key when shift and altgr are activeted */
int shiftcaps; /* If the value of the key should be shifted when capslock is active */ int shiftcaps; /* If the value of the key should be shifted when capslock is active */
int stick; /* If the key currently affects the others */
} osk_key; } osk_key;
typedef struct osk_composenode typedef struct osk_composenode
@ -87,6 +89,17 @@ typedef struct osk_keymodifiers
osk_key dead; osk_key dead;
} osk_keymodifiers; } osk_keymodifiers;
typedef struct osk_kmdf
{
osk_key * shift;
osk_key * altgr;
osk_key * compose;
osk_key * dead;
osk_key * dead2;
osk_key * dead3;
osk_key * dead4;
} osk_kmdf;
typedef struct osk_keyboard typedef struct osk_keyboard
{ {
char * name; /* The name of the keyboard */ char * name; /* The name of the keyboard */
@ -96,11 +109,13 @@ typedef struct osk_keyboard
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;
int changed; /* If the surface has been modified (painted) */ int changed; /* If the surface has been modified (painted) */
SDL_Rect rect; /* The rectangle that has changed */ SDL_Rect rect; /* The rectangle that has changed */
int recreated; /* If the surface has been deleted and newly created */ int recreated; /* If the surface has been deleted and newly created */
int modifiers; /* The state of Alt, CTRL, Shift, CapsLock, AltGr keys */ int modifiers; /* The state of Alt, CTRL, Shift, CapsLock, AltGr keys */
osk_keymodifiers keymodifiers; /* A shortcurt to find the place of the pressed modifiers */ osk_keymodifiers keymodifiers; /* A shortcurt to find the place of the pressed modifiers */
osk_kmdf kmdf;
osk_layout *layout; /* The layout struct */ osk_layout *layout; /* The layout struct */
char *layout_name[256]; /* The layout name */ char *layout_name[256]; /* The layout name */
int disable_change; /* If true, stay with the first layout found */ int disable_change; /* If true, stay with the first layout found */
@ -112,7 +127,7 @@ typedef struct osk_keyboard
osk_key * last_key_pressed; /* The last key pressed */ osk_key * last_key_pressed; /* The last key pressed */
} on_screen_keyboard; } 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, 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, int disable_change);
struct osk_layout *osk_load_layout(char *layout_name); struct osk_layout *osk_load_layout(char *layout_name);

View file

@ -1293,7 +1293,7 @@ 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;
static SDL_Surface *img_btnsm_up, *img_btnsm_off, *img_btnsm_down; 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;
static SDL_Surface *img_mirror, *img_flip; static SDL_Surface *img_mirror, *img_flip;
@ -2992,9 +2992,9 @@ static void mainloop(void)
if (kbd == NULL) if (kbd == NULL)
{ {
if (onscreen_keyboard_layout) if (onscreen_keyboard_layout)
kbd = osk_create(onscreen_keyboard_layout, screen, img_btnsm_up, img_btnsm_down, img_btnsm_off, img_btnsm_nav, 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, onscreen_keyboard_disable_change);
else else
kbd = osk_create("default.layout", screen, img_btnsm_up, img_btnsm_down, img_btnsm_off, img_btnsm_nav, onscreen_keyboard_disable_change); kbd = osk_create("default.layout", screen, img_btnsm_up, img_btnsm_down, img_btnsm_off, img_btnsm_nav, img_btnsm_hold, onscreen_keyboard_disable_change);
} }
if (kbd == NULL) if (kbd == NULL)
printf("kbd = NULL\n"); printf("kbd = NULL\n");
@ -11964,6 +11964,7 @@ static void cleanup(void)
free_surface(&img_btnsm_up); free_surface(&img_btnsm_up);
free_surface(&img_btnsm_off); free_surface(&img_btnsm_off);
free_surface(&img_btnsm_down); free_surface(&img_btnsm_down);
free_surface(&img_btnsm_hold);
free_surface(&img_btn_nav); free_surface(&img_btn_nav);
free_surface(&img_btnsm_nav); free_surface(&img_btnsm_nav);
@ -22631,6 +22632,7 @@ static void setup(void)
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");
img_btnsm_down = loadimage(DATA_PREFIX "images/ui/btnsm_down.png"); img_btnsm_down = loadimage(DATA_PREFIX "images/ui/btnsm_down.png");
img_btnsm_hold = loadimage(DATA_PREFIX "images/ui/btnsm_hold.png");
img_btn_nav = loadimage(DATA_PREFIX "images/ui/btn_nav.png"); img_btn_nav = loadimage(DATA_PREFIX "images/ui/btn_nav.png");
img_btnsm_nav = loadimage(DATA_PREFIX "images/ui/btnsm_nav.png"); img_btnsm_nav = loadimage(DATA_PREFIX "images/ui/btnsm_nav.png");