no message
This commit is contained in:
parent
c2077356ad
commit
e9dc8d9cde
111
src/system.c
111
src/system.c
|
@ -65,8 +65,6 @@ static struct
|
|||
GPU_Image* down;
|
||||
} texture;
|
||||
|
||||
u8 text;
|
||||
|
||||
} keyboard;
|
||||
|
||||
u32 touchCounter;
|
||||
|
@ -396,90 +394,30 @@ static void processMouse()
|
|||
}
|
||||
}
|
||||
|
||||
static void appendKeycode(tic_keycode code)
|
||||
{
|
||||
tic80_input* input = &platform.studio->tic->ram.input;
|
||||
|
||||
enum{BufSize = COUNT_OF(input->keyboard.keys)};
|
||||
|
||||
for(s32 i = 0; i < BufSize; i++)
|
||||
{
|
||||
if(input->keyboard.keys[i] == tic_key_unknown)
|
||||
{
|
||||
input->keyboard.keys[i] = code;
|
||||
return;
|
||||
}
|
||||
else if(input->keyboard.keys[i] == code) return;
|
||||
}
|
||||
}
|
||||
|
||||
static void processKeyboard()
|
||||
{
|
||||
tic80_input* input = &platform.studio->tic->ram.input;
|
||||
input->keyboard.data = 0;
|
||||
|
||||
SDL_Keymod mod = SDL_GetModState();
|
||||
|
||||
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},
|
||||
};
|
||||
|
||||
if(platform.keyboard.text && platform.keyboard.text < COUNT_OF(TextCodes))
|
||||
{
|
||||
appendKeycode(TextCodes[platform.keyboard.text].code);
|
||||
appendKeycode(TextCodes[platform.keyboard.text].shift);
|
||||
platform.keyboard.text = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const u8* keyboard = SDL_GetKeyboardState(NULL);
|
||||
|
||||
if(mod & KMOD_SHIFT) appendKeycode(tic_key_shift);
|
||||
if(mod & (KMOD_CTRL | KMOD_GUI)) appendKeycode(tic_key_ctrl);
|
||||
if(mod & KMOD_CAPS) appendKeycode(tic_key_capslock);
|
||||
|
||||
static const SDL_Keycode KeyboardCodes[tic_keys_count] =
|
||||
static const u32 KeyboardCodes[tic_keys_count] =
|
||||
{
|
||||
#include "keycodes.inl"
|
||||
};
|
||||
|
||||
for(s32 i = 0; i < SDL_NUM_SCANCODES; i++)
|
||||
tic80_input* input = &platform.studio->tic->ram.input;
|
||||
input->keyboard.data = 0;
|
||||
|
||||
const u8* keyboard = SDL_GetKeyboardState(NULL);
|
||||
|
||||
enum{BufSize = COUNT_OF(input->keyboard.keys)};
|
||||
|
||||
s32 c = 0;
|
||||
{
|
||||
SDL_Keymod mod = SDL_GetModState();
|
||||
if(mod & KMOD_RSHIFT) input->keyboard.keys[c++] = tic_key_shift;
|
||||
if(mod & (KMOD_RCTRL | KMOD_GUI)) input->keyboard.keys[c++] = tic_key_ctrl;
|
||||
if(mod & KMOD_RALT) input->keyboard.keys[c++] = tic_key_alt;
|
||||
if(mod & KMOD_CAPS) input->keyboard.keys[c++] = tic_key_capslock;
|
||||
}
|
||||
|
||||
for(s32 i = 0; i < SDL_NUM_SCANCODES && c < BufSize; i++)
|
||||
{
|
||||
if(keyboard[i])
|
||||
{
|
||||
|
@ -491,7 +429,7 @@ static void processKeyboard()
|
|||
{
|
||||
if(KeyboardCodes[k] == keycode)
|
||||
{
|
||||
appendKeycode(k);
|
||||
input->keyboard.keys[c++] = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -862,17 +800,6 @@ static void pollEvent()
|
|||
case SDL_WINDOWEVENT_FOCUS_GAINED: platform.studio->updateProject(); break;
|
||||
}
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
{
|
||||
const char* symbol = event.text.text;
|
||||
if(strlen(symbol) == 1)
|
||||
platform.keyboard.text = *symbol;
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if(event.key.keysym.sym == SDLK_RALT)
|
||||
platform.keyboard.text = 0;
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
platform.studio->exit();
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue