#707 added very dirty hack to support international keyboard input
This commit is contained in:
parent
a560894b42
commit
da86fe6fd8
42
src/studio.c
42
src/studio.c
|
@ -237,35 +237,31 @@ static struct
|
||||||
|
|
||||||
char getKeyboardText()
|
char getKeyboardText()
|
||||||
{
|
{
|
||||||
char text = getSystem()->getKeyboardText();
|
tic_mem* tic = impl.studio.tic;
|
||||||
|
|
||||||
if(text) return text;
|
static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ ";
|
||||||
|
static const char Shift[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ)!@#$%^&*(_+{}|:\"~<>? ";
|
||||||
|
|
||||||
tic_mem* tic = impl.studio.tic;
|
enum{Count = sizeof Symbols};
|
||||||
|
|
||||||
static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ ";
|
for(s32 i = 0; i < TIC80_KEY_BUFFER; i++)
|
||||||
static const char Shift[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ)!@#$%^&*(_+{}|:\"~<>? ";
|
{
|
||||||
|
tic_key key = tic->ram.input.keyboard.keys[i];
|
||||||
|
|
||||||
enum{Count = sizeof Symbols};
|
if(key > 0 && key < Count && tic->api.keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD))
|
||||||
|
{
|
||||||
|
bool caps = tic->api.key(tic, tic_key_capslock);
|
||||||
|
bool shift = tic->api.key(tic, tic_key_shift);
|
||||||
|
|
||||||
for(s32 i = 0; i < TIC80_KEY_BUFFER; i++)
|
return caps
|
||||||
{
|
? key >= tic_key_a && key <= tic_key_z
|
||||||
tic_key key = tic->ram.input.keyboard.keys[i];
|
? shift ? Symbols[key] : Shift[key]
|
||||||
|
: shift ? Shift[key] : Symbols[key]
|
||||||
|
: shift ? Shift[key] : Symbols[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(key > 0 && key < Count && tic->api.keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD))
|
return 0;
|
||||||
{
|
|
||||||
bool caps = tic->api.key(tic, tic_key_capslock);
|
|
||||||
bool shift = tic->api.key(tic, tic_key_shift);
|
|
||||||
|
|
||||||
return caps
|
|
||||||
? key >= tic_key_a && key <= tic_key_z
|
|
||||||
? shift ? Symbols[key] : Shift[key]
|
|
||||||
: shift ? Shift[key] : Symbols[key]
|
|
||||||
: shift ? Shift[key] : Symbols[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool keyWasPressed(tic_key key)
|
bool keyWasPressed(tic_key key)
|
||||||
|
|
114
src/system.c
114
src/system.c
|
@ -395,55 +395,97 @@ 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()
|
||||||
{
|
{
|
||||||
static const u32 KeyboardCodes[tic_keys_count] =
|
|
||||||
{
|
|
||||||
#include "keycodes.inl"
|
|
||||||
};
|
|
||||||
|
|
||||||
tic80_input* input = &platform.studio->tic->ram.input;
|
tic80_input* input = &platform.studio->tic->ram.input;
|
||||||
input->keyboard.data = 0;
|
input->keyboard.data = 0;
|
||||||
|
|
||||||
enum{BufSize = COUNT_OF(input->keyboard.keys)};
|
enum{BufSize = COUNT_OF(input->keyboard.keys)};
|
||||||
|
|
||||||
s32 c = 0;
|
SDL_Keymod mod = SDL_GetModState();
|
||||||
|
|
||||||
|
// TODO: the ugliest hack ever
|
||||||
|
// will try to remove it
|
||||||
|
if(mod & KMOD_RALT)
|
||||||
{
|
{
|
||||||
SDL_Keymod mod = SDL_GetModState();
|
static const struct {tic_keycode code; tic_keycode shift;} TextCodes[] =
|
||||||
if(mod & KMOD_SHIFT) input->keyboard.keys[c++] = tic_key_shift;
|
{
|
||||||
if(mod & (KMOD_CTRL | KMOD_GUI)) input->keyboard.keys[c++] = tic_key_ctrl;
|
['-'] = {tic_key_minus, tic_key_unknown},
|
||||||
if(mod & KMOD_ALT) input->keyboard.keys[c++] = tic_key_alt;
|
['='] = {tic_key_equals, tic_key_unknown},
|
||||||
if(mod & KMOD_CAPS) input->keyboard.keys[c++] = tic_key_capslock;
|
['['] = {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
|
||||||
const u8* keyboard = SDL_GetKeyboardState(NULL);
|
|
||||||
|
|
||||||
for(s32 i = 0; i < SDL_NUM_SCANCODES && c < BufSize; i++)
|
|
||||||
{
|
{
|
||||||
if(keyboard[i])
|
static const u32 KeyboardCodes[tic_keys_count] =
|
||||||
{
|
{
|
||||||
SDL_Keycode keycode = i == SDL_SCANCODE_AC_BACK
|
#include "keycodes.inl"
|
||||||
? SDLK_ESCAPE
|
};
|
||||||
: SDL_GetKeyFromScancode(i);
|
|
||||||
|
|
||||||
for(s32 k = 0; k < COUNT_OF(KeyboardCodes); k++)
|
s32 c = 0;
|
||||||
{
|
{
|
||||||
if(KeyboardCodes[k] == keycode)
|
if(mod & KMOD_SHIFT) input->keyboard.keys[c++] = tic_key_shift;
|
||||||
|
if(mod & KMOD_CTRL) input->keyboard.keys[c++] = tic_key_ctrl;
|
||||||
|
if(mod & KMOD_CAPS) input->keyboard.keys[c++] = tic_key_capslock;
|
||||||
|
}
|
||||||
|
|
||||||
|
const u8* keyboard = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
|
for(s32 i = 0; i < SDL_NUM_SCANCODES && c < BufSize; i++)
|
||||||
|
{
|
||||||
|
if(keyboard[i])
|
||||||
|
{
|
||||||
|
SDL_Keycode keycode = i == SDL_SCANCODE_AC_BACK
|
||||||
|
? SDLK_ESCAPE
|
||||||
|
: SDL_GetKeyFromScancode(i);
|
||||||
|
|
||||||
|
for(s32 k = 0; k < COUNT_OF(KeyboardCodes); k++)
|
||||||
{
|
{
|
||||||
input->keyboard.keys[c++] = k;
|
if(KeyboardCodes[k] == keycode)
|
||||||
break;
|
{
|
||||||
|
input->keyboard.keys[c++] = k;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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