1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#include "wchar.h"
#include "stdio.h"
#include "SDL.h"
#include "SDL_ttf.h"
/* after file:///usr/share/doc/libsdl1.2-dev/docs/html/sdlkey.html
Table 8-2. SDL modifier definitions
SDL Modifier Meaning
KMOD_NONE No modifiers applicable
KMOD_NUM Numlock is down
KMOD_CAPS Capslock is down
KMOD_LCTRL Left Control is down
KMOD_RCTRL Right Control is down
KMOD_RSHIFT Right Shift is down
KMOD_LSHIFT Left Shift is down
KMOD_RALT Right Alt is down
KMOD_LALT Left Alt is down
KMOD_CTRL A Control key is down
KMOD_SHIFT A Shift key is down
KMOD_ALT An Alt key is down
*/
typedef struct osk_keymap
{
int keycode;
int disable_caps; /* If caps lock should affect this key */
char * plain; /* The default Xkeysym for the keycode */
char * caps; /* If CapsLock or Shift + key */
char * altgr; /* If AltGr + key */
char * shiftaltgr; /* If AltGr + Shift + key */
} osk_keymap;
typedef struct osk_key
{
int keycode; /* The code associated to this key. If 0, then it is an empty key. */
int row;
int x;
int y;
float width; /* The width in buttons */
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 *altgr_label; /* The text that will show the key at the right of the plain label */
int shiftcaps; /* If the value of the key should be shifted when capslock is active */
} osk_key;
typedef struct osk_composenode
{
wchar_t * keysym;
wchar_t * result;
int size; /* How many childs are there. */
struct osk_composenode ** childs;
// struct osk_composenode **parent;
} osk_composenode;
typedef struct keysymdefs
{
char * mnemo;
int keysym;
int unicode;
} keysymdefs;
typedef struct osk_layout
{
char *name;
int *rows;
int width;
int height;
char * fontpath;
osk_key **keys;
osk_keymap *keymap;
osk_composenode * composemap;
keysymdefs * keysymdefs;
uint sizeofkeysymdefs;
SDL_Color bgcolor;
SDL_Color fgcolor;
} osk_layout;
typedef struct osk_keymodifiers
{
osk_key shift;
osk_key altgr;
osk_key compose;
osk_key dead;
} osk_keymodifiers;
typedef struct osk_keyboard
{
char * name; /* The name of the keyboard */
char * keyboard_list; /* The names of the keyboards allowed from this one */
SDL_Surface *surface; /* The surface containing the keyboard */
SDL_Surface *button_up; /* The surfaces containing the buttons */
SDL_Surface *button_down;
SDL_Surface *button_off;
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 */
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_layout *layout; /* The layout struct */
char *layout_name[256]; /* The layout name */
int disable_change; /* If true, stay with the first layout found */
wchar_t * key[256]; /* The text of the key */
int keycode; /* The unicode code corresponding to the key */
wchar_t * composed; /* The unicode char found after a sequence of key presses */
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_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, int disable_change);
struct osk_layout *osk_load_layout(char *layout_name);
void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h, char * layout_buttons, char *layout_labels, char *layout_keycodes);
void osk_reset(on_screen_keyboard *osk);
struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y);
void osk_released(on_screen_keyboard *osk);
void osk_hover(on_screen_keyboard *keyboard, int x, int y);
void osk_free(on_screen_keyboard *osk);
void osk_change_layout(on_screen_keyboard *osk);
|