#707 added very dirty hack to support international keyboard input
This commit is contained in:
parent
a560894b42
commit
da86fe6fd8
|
@ -237,10 +237,6 @@ static struct
|
||||||
|
|
||||||
char getKeyboardText()
|
char getKeyboardText()
|
||||||
{
|
{
|
||||||
char text = getSystem()->getKeyboardText();
|
|
||||||
|
|
||||||
if(text) return text;
|
|
||||||
|
|
||||||
tic_mem* tic = impl.studio.tic;
|
tic_mem* tic = impl.studio.tic;
|
||||||
|
|
||||||
static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ ";
|
static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ ";
|
||||||
|
|
78
src/system.c
78
src/system.c
|
@ -395,33 +395,74 @@ static void processMouse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ugly hack, but I didn't find a better solution
|
|
||||||
// will try to fix it later
|
|
||||||
static char getKeyboardText()
|
|
||||||
{
|
|
||||||
char text = platform.keyboard.text;
|
|
||||||
platform.keyboard.text = 0;
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void processKeyboard()
|
static void processKeyboard()
|
||||||
|
{
|
||||||
|
tic80_input* input = &platform.studio->tic->ram.input;
|
||||||
|
input->keyboard.data = 0;
|
||||||
|
|
||||||
|
enum{BufSize = COUNT_OF(input->keyboard.keys)};
|
||||||
|
|
||||||
|
SDL_Keymod mod = SDL_GetModState();
|
||||||
|
|
||||||
|
// TODO: the ugliest hack ever
|
||||||
|
// will try to remove it
|
||||||
|
if(mod & KMOD_RALT)
|
||||||
|
{
|
||||||
|
static const struct {tic_keycode code; tic_keycode shift;} TextCodes[] =
|
||||||
|
{
|
||||||
|
['-'] = {tic_key_minus, tic_key_unknown},
|
||||||
|
['='] = {tic_key_equals, tic_key_unknown},
|
||||||
|
['['] = {tic_key_leftbracket, tic_key_unknown},
|
||||||
|
[']'] = {tic_key_rightbracket, tic_key_unknown},
|
||||||
|
['\\'] = {tic_key_backslash, tic_key_unknown},
|
||||||
|
[';'] = {tic_key_semicolon, tic_key_unknown},
|
||||||
|
['\''] = {tic_key_apostrophe, tic_key_unknown},
|
||||||
|
['`'] = {tic_key_grave, tic_key_unknown},
|
||||||
|
[','] = {tic_key_comma, tic_key_unknown},
|
||||||
|
['.'] = {tic_key_period, tic_key_unknown},
|
||||||
|
['/'] = {tic_key_slash, tic_key_unknown},
|
||||||
|
[')'] = {tic_key_0, tic_key_shift},
|
||||||
|
['!'] = {tic_key_1, tic_key_shift},
|
||||||
|
['@'] = {tic_key_2, tic_key_shift},
|
||||||
|
['#'] = {tic_key_3, tic_key_shift},
|
||||||
|
['$'] = {tic_key_4, tic_key_shift},
|
||||||
|
['%'] = {tic_key_5, tic_key_shift},
|
||||||
|
['^'] = {tic_key_6, tic_key_shift},
|
||||||
|
['&'] = {tic_key_7, tic_key_shift},
|
||||||
|
['*'] = {tic_key_8, tic_key_shift},
|
||||||
|
['('] = {tic_key_9, tic_key_shift},
|
||||||
|
['_'] = {tic_key_minus, tic_key_shift},
|
||||||
|
['+'] = {tic_key_equals, tic_key_shift},
|
||||||
|
['{'] = {tic_key_leftbracket, tic_key_shift},
|
||||||
|
['}'] = {tic_key_rightbracket, tic_key_shift},
|
||||||
|
['|'] = {tic_key_backslash, tic_key_shift},
|
||||||
|
[':'] = {tic_key_semicolon, tic_key_shift},
|
||||||
|
['"'] = {tic_key_apostrophe, tic_key_shift},
|
||||||
|
['~'] = {tic_key_grave, tic_key_shift},
|
||||||
|
['<'] = {tic_key_comma, tic_key_shift},
|
||||||
|
['>'] = {tic_key_period, tic_key_shift},
|
||||||
|
['?'] = {tic_key_slash, tic_key_shift},
|
||||||
|
};
|
||||||
|
|
||||||
|
u8 text = platform.keyboard.text;
|
||||||
|
|
||||||
|
if(text && text < COUNT_OF(TextCodes))
|
||||||
|
{
|
||||||
|
input->keyboard.keys[0] = TextCodes[text].code;
|
||||||
|
input->keyboard.keys[1] = TextCodes[text].shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
static const u32 KeyboardCodes[tic_keys_count] =
|
static const u32 KeyboardCodes[tic_keys_count] =
|
||||||
{
|
{
|
||||||
#include "keycodes.inl"
|
#include "keycodes.inl"
|
||||||
};
|
};
|
||||||
|
|
||||||
tic80_input* input = &platform.studio->tic->ram.input;
|
|
||||||
input->keyboard.data = 0;
|
|
||||||
|
|
||||||
enum{BufSize = COUNT_OF(input->keyboard.keys)};
|
|
||||||
|
|
||||||
s32 c = 0;
|
s32 c = 0;
|
||||||
{
|
{
|
||||||
SDL_Keymod mod = SDL_GetModState();
|
|
||||||
if(mod & KMOD_SHIFT) input->keyboard.keys[c++] = tic_key_shift;
|
if(mod & KMOD_SHIFT) input->keyboard.keys[c++] = tic_key_shift;
|
||||||
if(mod & (KMOD_CTRL | KMOD_GUI)) input->keyboard.keys[c++] = tic_key_ctrl;
|
if(mod & KMOD_CTRL) input->keyboard.keys[c++] = tic_key_ctrl;
|
||||||
if(mod & KMOD_ALT) input->keyboard.keys[c++] = tic_key_alt;
|
|
||||||
if(mod & KMOD_CAPS) input->keyboard.keys[c++] = tic_key_capslock;
|
if(mod & KMOD_CAPS) input->keyboard.keys[c++] = tic_key_capslock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,6 +487,7 @@ static void processKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(__EMSCRIPTEN__) && !defined(__MACOSX__)
|
#if !defined(__EMSCRIPTEN__) && !defined(__MACOSX__)
|
||||||
|
|
||||||
|
@ -756,6 +798,7 @@ static void pollEvent()
|
||||||
|
|
||||||
{
|
{
|
||||||
input->mouse.btns = 0;
|
input->mouse.btns = 0;
|
||||||
|
platform.keyboard.text = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
@ -1311,7 +1354,6 @@ static System systemInterface =
|
||||||
.preseed = preseed,
|
.preseed = preseed,
|
||||||
.poll = pollEvent,
|
.poll = pollEvent,
|
||||||
.updateConfig = updateConfig,
|
.updateConfig = updateConfig,
|
||||||
.getKeyboardText = getKeyboardText,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void gpuTick()
|
static void gpuTick()
|
||||||
|
|
|
@ -29,8 +29,6 @@ typedef struct
|
||||||
|
|
||||||
void (*updateConfig)();
|
void (*updateConfig)();
|
||||||
|
|
||||||
char (*getKeyboardText)();
|
|
||||||
|
|
||||||
} System;
|
} System;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
Loading…
Reference in New Issue