1 #include "wchar.h" 2 #include "stdio.h" 3 #include "SDL.h" 4 #include "SDL_ttf.h" 5 /* after file:///usr/share/doc/libsdl1.2-dev/docs/html/sdlkey.html 6 7 Table 8-2. SDL modifier definitions 8 9 SDL Modifier Meaning 10 KMOD_NONE No modifiers applicable 11 KMOD_NUM Numlock is down 12 KMOD_CAPS Capslock is down 13 KMOD_LCTRL Left Control is down 14 KMOD_RCTRL Right Control is down 15 KMOD_RSHIFT Right Shift is down 16 KMOD_LSHIFT Left Shift is down 17 KMOD_RALT Right Alt is down 18 KMOD_LALT Left Alt is down 19 KMOD_CTRL A Control key is down 20 KMOD_SHIFT A Shift key is down 21 KMOD_ALT An Alt key is down 22 23 */ 24 25 26 27 typedef struct osk_keymap 28 { 29 int keycode; 30 int disable_caps; /* If caps lock should affect this key */ 31 char *plain; /* The default Xkeysym for the keycode */ 32 char *caps; /* If CapsLock or Shift + key */ 33 char *altgr; /* If AltGr + key */ 34 char *shiftaltgr; /* If AltGr + Shift + key */ 35 } osk_keymap; 36 37 typedef struct osk_key 38 { 39 int keycode; /* The code associated to this key. If 0, then it is an empty key. */ 40 int row; 41 int x; 42 int y; 43 float width; /* The width in buttons */ 44 char *plain_label; /* The text that will show the key */ 45 char *top_label; /* The text that will show the key above the plain label. */ 46 char *altgr_label; /* The text that will show the key at the right of the plain label */ 47 char *shift_altgr_label; /* The text that will show the key when shift and altgr are activated */ 48 int shiftcaps; /* If the value of the key should be shifted when capslock is active */ 49 int stick; /* If the key currently affects the others */ 50 } osk_key; 51 52 typedef struct osk_composenode 53 { 54 wchar_t *keysym; 55 wchar_t *result; 56 int size; /* How many childs are there. */ 57 struct osk_composenode **childs; 58 // struct osk_composenode **parent; 59 } osk_composenode; 60 61 typedef struct keysymdefs 62 { 63 char *mnemo; 64 int keysym; 65 int unicode; 66 } keysymdefs; 67 68 typedef struct osk_layout 69 { 70 char *name; 71 int *rows; 72 int width; 73 int height; 74 char *fontpath; 75 osk_key **keys; 76 osk_keymap *keymap; 77 osk_composenode *composemap; 78 keysymdefs *keysymdefs; 79 unsigned int sizeofkeysymdefs; 80 SDL_Color bgcolor; 81 SDL_Color fgcolor; 82 } osk_layout; 83 84 typedef struct osk_keymodifiers 85 { 86 osk_key shift; 87 osk_key altgr; 88 osk_key compose; 89 osk_key dead; 90 } osk_keymodifiers; 91 92 typedef struct osk_kmdf 93 { 94 osk_key *shift; 95 osk_key *altgr; 96 osk_key *compose; 97 osk_key *dead; 98 osk_key *dead2; 99 osk_key *dead3; 100 osk_key *dead4; 101 } osk_kmdf; 102 103 typedef struct osk_keyboard 104 { 105 char *name; /* The name of the keyboard */ 106 char *keyboard_list; /* The names of the keyboards allowed from this one */ 107 SDL_Surface *surface; /* The surface containing the current layout's keyboard */ 108 /* The surfaces containing the current layout's button backgrounds*/ 109 SDL_Surface *button_up; 110 SDL_Surface *button_down; 111 SDL_Surface *button_off; 112 SDL_Surface *button_nav; 113 SDL_Surface *button_hold; 114 /* The surfaces containing some symbols for the current layout's buttons */ 115 SDL_Surface *oskdel; /* delete arrow */ 116 SDL_Surface *osktab; /* Tab arrows */ 117 SDL_Surface *oskenter; /* Return hook/arrow */ 118 SDL_Surface *oskcapslock; /* CapsLock */ 119 SDL_Surface *oskshift; /* Shift */ 120 int changed; /* If the surface has been modified (painted) */ 121 SDL_Rect rect; /* The rectangle that has changed */ 122 int recreated; /* If the surface has been deleted and newly created */ 123 int modifiers; /* The state of Alt, CTRL, Shift, CapsLock, AltGr keys */ 124 osk_keymodifiers keymodifiers; /* A shortcurt to find the place of the pressed modifiers */ 125 osk_kmdf kmdf; 126 osk_layout *layout; /* The layout struct */ 127 char *layout_name[256]; /* The layout name */ 128 TTF_Font *osk_fonty; /* Font */ 129 int disable_change; /* If true, stay with the first layout found */ 130 wchar_t *key[256]; /* The text of the key */ 131 int keycode; /* The unicode code corresponding to the key */ 132 wchar_t *composed; /* The unicode char found after a sequence of key presses */ 133 int composed_type; /* 1 if the value stored in composed is yet the unicode value */ 134 osk_composenode *composing; /* The node in the middle of a compose sequence */ 135 osk_key *last_key_pressed; /* The last key pressed */ 136 SDL_Surface * canvas_ptr; /* Canvas drawing surface, for bpp and sizing needs when cycling through keyboard layouts */ 137 /* Large and small buttons, to pass back to osk_create() when cycling through keyboard layouts */ 138 SDL_Surface *LG_button_up; 139 SDL_Surface *LG_button_down; 140 SDL_Surface *LG_button_off; 141 SDL_Surface *LG_button_nav; 142 SDL_Surface *LG_button_hold; 143 SDL_Surface *LG_oskdel; 144 SDL_Surface *LG_osktab; 145 SDL_Surface *LG_oskenter; 146 SDL_Surface *LG_oskcapslock; 147 SDL_Surface *LG_oskshift; 148 SDL_Surface *SM_button_up; 149 SDL_Surface *SM_button_down; 150 SDL_Surface *SM_button_off; 151 SDL_Surface *SM_button_nav; 152 SDL_Surface *SM_button_hold; 153 SDL_Surface *SM_oskdel; 154 SDL_Surface *SM_osktab; 155 SDL_Surface *SM_oskenter; 156 SDL_Surface *SM_oskcapslock; 157 SDL_Surface *SM_oskshift; 158 } on_screen_keyboard; 159 160 struct osk_keyboard *osk_create(char * layout_name, SDL_Surface * canvas, 161 SDL_Surface * LG_button_up, SDL_Surface * LG_button_down, 162 SDL_Surface * LG_button_off, SDL_Surface * LG_button_nav, 163 SDL_Surface * LG_button_hold, 164 SDL_Surface * LG_oskdel, SDL_Surface * LG_osktab, SDL_Surface * LG_oskenter, 165 SDL_Surface * LG_oskcapslock, SDL_Surface * LG_oskshift, 166 SDL_Surface * SM_button_up, SDL_Surface * SM_button_down, 167 SDL_Surface * SM_button_off, SDL_Surface * SM_button_nav, 168 SDL_Surface * SM_button_hold, 169 SDL_Surface * SM_oskdel, SDL_Surface * SM_osktab, SDL_Surface * SM_oskenter, 170 SDL_Surface * SM_oskcapslock, SDL_Surface * SM_oskshift, 171 int disable_change); 172 173 struct osk_layout *osk_load_layout(char *layout_name); 174 175 void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h, char *layout_buttons, char *layout_labels, 176 char *layout_keycodes); 177 void osk_reset(on_screen_keyboard * osk); 178 struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y); 179 void osk_released(on_screen_keyboard * osk); 180 void osk_hover(on_screen_keyboard * keyboard, int x, int y); 181 void osk_free(on_screen_keyboard * osk); 182 void osk_change_layout(on_screen_keyboard * osk); 183