Mercurial > sdl-ios-xcode
comparison src/events/SDL_keyboard.c @ 2300:c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
author | Bob Pendleton <bob@pendleton.com> |
---|---|
date | Tue, 15 Jan 2008 22:37:17 +0000 |
parents | dbc6d1893869 |
children | d87417504c75 |
comparison
equal
deleted
inserted
replaced
2299:a7cbc25071b6 | 2300:c97ad1abe05b |
---|---|
35 static int SDL_num_keyboards; | 35 static int SDL_num_keyboards; |
36 static int SDL_current_keyboard; | 36 static int SDL_current_keyboard; |
37 static SDL_Keyboard **SDL_keyboards; | 37 static SDL_Keyboard **SDL_keyboards; |
38 | 38 |
39 /* Taken from SDL_iconv() */ | 39 /* Taken from SDL_iconv() */ |
40 static char * | 40 char * |
41 encodeUtf8(Uint32 ch, char *dst) | 41 SDL_Ucs4ToUtf8(Uint32 ch, char *dst) |
42 { | 42 { |
43 Uint8 *p = (Uint8 *) dst; | 43 Uint8 *p = (Uint8 *) dst; |
44 if (ch <= 0x7F) { | 44 if (ch <= 0x7F) { |
45 *p = (Uint8) ch; | 45 *p = (Uint8) ch; |
46 ++dst; | 46 ++dst; |
264 SDL_VideoDevice *_this = SDL_GetVideoDevice(); | 264 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
265 if (_this && _this->GetSpecialKeyName) { | 265 if (_this && _this->GetSpecialKeyName) { |
266 keyname = _this->GetSpecialKeyName(_this, layoutKey); | 266 keyname = _this->GetSpecialKeyName(_this, layoutKey); |
267 } | 267 } |
268 } else if ((layoutKey & SDL_KEY_CAN_BE_PHYSICAL_BIT) == 0) { | 268 } else if ((layoutKey & SDL_KEY_CAN_BE_PHYSICAL_BIT) == 0) { |
269 /* SDLK_INDEX(layoutKey) is the unicode code point of the character generated by the key */ | 269 /* SDLK_INDEX(layoutKey) is the unicode code point of the |
270 character generated by the key */ | |
270 static char buffer[9]; /* 6 (maximal UTF-8 char length) + 2 ([] for keypad) + 1 (null teminator) */ | 271 static char buffer[9]; /* 6 (maximal UTF-8 char length) + 2 ([] for keypad) + 1 (null teminator) */ |
271 char *bufferPtr = &buffer[1]; | 272 char *bufferPtr = &buffer[1]; |
272 Uint32 codepoint = SDLK_INDEX(layoutKey); | 273 Uint32 codepoint = SDLK_INDEX(layoutKey); |
273 | 274 |
274 /* Unaccented letter keys on latin keyboards are normally labeled in upper case (and probably on others like Greek or Cyrillic too, so if you happen to know for sure, please adapt this). */ | 275 /* Unaccented letter keys on latin keyboards are normally |
276 labeled in upper case (and probably on others like Greek or | |
277 Cyrillic too, so if you happen to know for sure, please | |
278 adapt this). */ | |
275 if (codepoint >= 'a' && codepoint <= 'z') { | 279 if (codepoint >= 'a' && codepoint <= 'z') { |
276 codepoint -= 32; | 280 codepoint -= 32; |
277 } | 281 } |
278 | 282 |
279 bufferPtr = encodeUtf8(codepoint, bufferPtr); | 283 bufferPtr = SDL_Ucs4ToUtf8(codepoint, bufferPtr); |
280 *bufferPtr = '\0'; | 284 *bufferPtr = '\0'; |
281 | 285 |
282 if ((layoutKey & SDL_KEY_KEYPAD_BIT) != 0) { | 286 if ((layoutKey & SDL_KEY_KEYPAD_BIT) != 0) { |
283 buffer[0] = '['; | 287 buffer[0] = '['; |
284 *bufferPtr++ = ']'; | 288 *bufferPtr++ = ']'; |