|
| 1 | +/* |
| 2 | + Simple DirectMedia Layer |
| 3 | + Copyright (C) 1997-2023 Sam Lantinga <[email protected]> |
| 4 | +
|
| 5 | + This software is provided 'as-is', without any express or implied |
| 6 | + warranty. In no event will the authors be held liable for any damages |
| 7 | + arising from the use of this software. |
| 8 | +
|
| 9 | + Permission is granted to anyone to use this software for any purpose, |
| 10 | + including commercial applications, and to alter it and redistribute it |
| 11 | + freely, subject to the following restrictions: |
| 12 | +
|
| 13 | + 1. The origin of this software must not be misrepresented; you must not |
| 14 | + claim that you wrote the original software. If you use this software |
| 15 | + in a product, an acknowledgment in the product documentation would be |
| 16 | + appreciated but is not required. |
| 17 | + 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | + misrepresented as being the original software. |
| 19 | + 3. This notice may not be removed or altered from any source distribution. |
| 20 | +*/ |
| 21 | +#include "SDL_ogckeyboard.h" |
| 22 | +#include "../../events/SDL_keyboard_c.h" |
| 23 | + |
| 24 | +#if defined(SDL_VIDEO_DRIVER_OGC) && defined(__wii__) |
| 25 | +#include <gctypes.h> |
| 26 | +#include <wiikeyboard/keyboard.h> |
| 27 | + |
| 28 | +void OGC_PumpKeyboardEvents(_THIS) { |
| 29 | + keyboard_event ke; |
| 30 | + |
| 31 | + s32 res = KEYBOARD_GetEvent(&ke); |
| 32 | + if (res && (ke.type == KEYBOARD_RELEASED || ke.type == KEYBOARD_PRESSED)) { |
| 33 | + SDL_SendKeyboardKey((ke.type == KEYBOARD_PRESSED) ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)ke.keycode); |
| 34 | + |
| 35 | + if (ke.type == KEYBOARD_PRESSED) { |
| 36 | + const Uint16 symbol = ke.symbol; |
| 37 | + char utf8[4] = {'\0'}; |
| 38 | + |
| 39 | + /* ignore private symbols, used by wiikeyboard for special keys */ |
| 40 | + if ((symbol >= 0xE000 && symbol <= 0xF8FF) || symbol == 0xFFFF) |
| 41 | + return; |
| 42 | + |
| 43 | + /* convert UCS-2 to UTF-8 */ |
| 44 | + if (symbol < 0x80) { |
| 45 | + utf8[0] = symbol; |
| 46 | + } else if (symbol < 0x800) { |
| 47 | + utf8[0] = 0xC0 | (symbol >> 6); |
| 48 | + utf8[1] = 0x80 | (symbol & 0x3F); |
| 49 | + } else { |
| 50 | + utf8[0] = 0xE0 | (symbol >> 12); |
| 51 | + utf8[1] = 0x80 | ((symbol >> 6) & 0x3F); |
| 52 | + utf8[2] = 0x80 | (symbol & 0x3F); |
| 53 | + } |
| 54 | + |
| 55 | + SDL_SendKeyboardText(utf8); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | +#endif |
0 commit comments