diff --git a/src/code.c b/src/code.c index 75d968bca..72917b8d2 100644 --- a/src/code.c +++ b/src/code.c @@ -891,7 +891,7 @@ static void processKeyboard(Code* code) { tic_mem* tic = code->tic; - if(tic->ram.input.keyboard.data == 0 || tic->ram.input.keyboard.text != 0) return; + if(tic->ram.input.keyboard.data == 0) return; switch(getClipboardEvent(0)) { @@ -1044,6 +1044,7 @@ static void textEditTick(Code* code) processKeyboard(code); + if(!tic->api.key(tic, tic_key_ctrl) && !tic->api.key(tic, tic_key_alt)) { char sym = tic->ram.input.keyboard.text; diff --git a/src/music.c b/src/music.c index 4084909bb..d8a7b81bc 100644 --- a/src/music.c +++ b/src/music.c @@ -750,6 +750,9 @@ static void processTrackerKeyboard(Music* music) return; } + if(tic->api.key(tic, tic_key_ctrl) || tic->api.key(tic, tic_key_alt)) + return; + bool shift = tic->api.key(tic, tic_key_shift); if(shift) @@ -952,8 +955,11 @@ static void processPatternKeyboard(Music* music) tic_mem* tic = music->tic; s32 channel = music->tracker.col / CHANNEL_COLS; + if(tic->api.key(tic, tic_key_ctrl) || tic->api.key(tic, tic_key_alt)) + return; + if(keyWasPressed(tic_key_delete)) setChannelPatternValue(music, 0, channel); - else if(keyWasPressed(tic_key_tab)) nextPattern(music); + else if(keyWasPressed(tic_key_tab)) nextPattern(music); else if(keyWasPressed(tic_key_left)) patternColLeft(music); else if(keyWasPressed(tic_key_right)) patternColRight(music); else if(keyWasPressed(tic_key_down) diff --git a/src/studio.c b/src/studio.c index 46da74223..92465214b 100644 --- a/src/studio.c +++ b/src/studio.c @@ -52,9 +52,6 @@ #define FRAME_SIZE (TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)) #define POPUP_DUR (TIC_FRAMERATE*2) -#define KEYBOARD_HOLD 20 -#define KEYBOARD_PERIOD 3 - #if defined(TIC80_PRO) #define TIC_EDITOR_BANKS (TIC_BANKS) #else diff --git a/src/system.c b/src/system.c index 98f2d5d8a..829780ca8 100644 --- a/src/system.c +++ b/src/system.c @@ -404,7 +404,12 @@ static void processKeyboard() platform.keyboard.state[tic_key_shift] = mod & KMOD_SHIFT; platform.keyboard.state[tic_key_ctrl] = mod & (KMOD_CTRL | KMOD_GUI); + platform.keyboard.state[tic_key_alt] = mod & KMOD_LALT; platform.keyboard.state[tic_key_capslock] = mod & KMOD_CAPS; + + // it's weird, but system sends CTRL when you press RALT + if(mod & KMOD_RALT) + platform.keyboard.state[tic_key_ctrl] = false; } tic80_input* input = &tic->ram.input; @@ -485,10 +490,14 @@ static void processTouchKeyboard() #include "kbdlayout.inl" }; - tic80_input* input = &platform.studio->tic->ram.input; + tic_mem* tic = platform.studio->tic; + + tic80_input* input = &tic->ram.input; s32 devices = SDL_GetNumTouchDevices(); + enum {BufSize = COUNT_OF(input->keyboard.keys)}; + for (s32 i = 0; i < devices; i++) { SDL_TouchID id = SDL_GetTouchDevice(i); @@ -510,13 +519,37 @@ static void processTouchKeyboard() pt.x /= scale; pt.y /= scale; - for(s32 i = 0; i < COUNT_OF(input->keyboard.keys); i++) + for(s32 i = 0; i < BufSize; i++) { tic_key* key = &input->keyboard.keys[i]; if(*key == tic_key_unknown) { *key = KbdLayout[pt.x / TIC_SPRITESIZE + pt.y / TIC_SPRITESIZE * Cols]; + if(input->keyboard.text == 0) + { + static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ "; + static const char Shift[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ)!@#$%^&*(_+{}|:\"~<>? "; + + enum{Count = sizeof Symbols}; + + for(s32 i = 0; i < TIC80_KEY_BUFFER; i++) + { + tic_key key = tic->ram.input.keyboard.keys[i]; + + 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); + + input->keyboard.text = caps + ? key >= tic_key_a && key <= tic_key_z + ? shift ? Symbols[key] : Shift[key] + : shift ? Shift[key] : Symbols[key] + : shift ? Shift[key] : Symbols[key]; + } + } + } break; } } @@ -734,6 +767,9 @@ static void handleKeydown(SDL_Keycode keycode, bool down) break; } } + + if(keycode == SDLK_AC_BACK) + platform.keyboard.state[tic_key_escape] = down; } static void pollEvent() @@ -742,7 +778,7 @@ static void pollEvent() tic80_input* input = &tic->ram.input; input->mouse.btns = 0; - tic->ram.input.keyboard.text = 0; + input->keyboard.text = 0; SDL_Event event; diff --git a/src/tic.h b/src/tic.h index dfd9eb15d..065813da3 100644 --- a/src/tic.h +++ b/src/tic.h @@ -114,6 +114,9 @@ #define SFX_NOTES {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"} #define TIC_FONT_CHARS 256 +#define KEYBOARD_HOLD 20 +#define KEYBOARD_PERIOD 3 + enum { NoteNone = 0,