Skip to content

Commit 178007c

Browse files
committed
#707 final fix
1 parent 4d08ad0 commit 178007c

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

src/code.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ static void processKeyboard(Code* code)
891891
{
892892
tic_mem* tic = code->tic;
893893

894-
if(tic->ram.input.keyboard.data == 0 || tic->ram.input.keyboard.text != 0) return;
894+
if(tic->ram.input.keyboard.data == 0) return;
895895

896896
switch(getClipboardEvent(0))
897897
{
@@ -1044,6 +1044,7 @@ static void textEditTick(Code* code)
10441044

10451045
processKeyboard(code);
10461046

1047+
if(!tic->api.key(tic, tic_key_ctrl) && !tic->api.key(tic, tic_key_alt))
10471048
{
10481049
char sym = tic->ram.input.keyboard.text;
10491050

src/music.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,9 @@ static void processTrackerKeyboard(Music* music)
750750
return;
751751
}
752752

753+
if(tic->api.key(tic, tic_key_ctrl) || tic->api.key(tic, tic_key_alt))
754+
return;
755+
753756
bool shift = tic->api.key(tic, tic_key_shift);
754757

755758
if(shift)
@@ -952,8 +955,11 @@ static void processPatternKeyboard(Music* music)
952955
tic_mem* tic = music->tic;
953956
s32 channel = music->tracker.col / CHANNEL_COLS;
954957

958+
if(tic->api.key(tic, tic_key_ctrl) || tic->api.key(tic, tic_key_alt))
959+
return;
960+
955961
if(keyWasPressed(tic_key_delete)) setChannelPatternValue(music, 0, channel);
956-
else if(keyWasPressed(tic_key_tab)) nextPattern(music);
962+
else if(keyWasPressed(tic_key_tab)) nextPattern(music);
957963
else if(keyWasPressed(tic_key_left)) patternColLeft(music);
958964
else if(keyWasPressed(tic_key_right)) patternColRight(music);
959965
else if(keyWasPressed(tic_key_down)

src/studio.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
#define FRAME_SIZE (TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32))
5353
#define POPUP_DUR (TIC_FRAMERATE*2)
5454

55-
#define KEYBOARD_HOLD 20
56-
#define KEYBOARD_PERIOD 3
57-
5855
#if defined(TIC80_PRO)
5956
#define TIC_EDITOR_BANKS (TIC_BANKS)
6057
#else

src/system.c

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,12 @@ static void processKeyboard()
404404

405405
platform.keyboard.state[tic_key_shift] = mod & KMOD_SHIFT;
406406
platform.keyboard.state[tic_key_ctrl] = mod & (KMOD_CTRL | KMOD_GUI);
407+
platform.keyboard.state[tic_key_alt] = mod & KMOD_LALT;
407408
platform.keyboard.state[tic_key_capslock] = mod & KMOD_CAPS;
409+
410+
// it's weird, but system sends CTRL when you press RALT
411+
if(mod & KMOD_RALT)
412+
platform.keyboard.state[tic_key_ctrl] = false;
408413
}
409414

410415
tic80_input* input = &tic->ram.input;
@@ -485,10 +490,14 @@ static void processTouchKeyboard()
485490
#include "kbdlayout.inl"
486491
};
487492

488-
tic80_input* input = &platform.studio->tic->ram.input;
493+
tic_mem* tic = platform.studio->tic;
494+
495+
tic80_input* input = &tic->ram.input;
489496

490497
s32 devices = SDL_GetNumTouchDevices();
491498

499+
enum {BufSize = COUNT_OF(input->keyboard.keys)};
500+
492501
for (s32 i = 0; i < devices; i++)
493502
{
494503
SDL_TouchID id = SDL_GetTouchDevice(i);
@@ -510,13 +519,37 @@ static void processTouchKeyboard()
510519
pt.x /= scale;
511520
pt.y /= scale;
512521

513-
for(s32 i = 0; i < COUNT_OF(input->keyboard.keys); i++)
522+
for(s32 i = 0; i < BufSize; i++)
514523
{
515524
tic_key* key = &input->keyboard.keys[i];
516525

517526
if(*key == tic_key_unknown)
518527
{
519528
*key = KbdLayout[pt.x / TIC_SPRITESIZE + pt.y / TIC_SPRITESIZE * Cols];
529+
if(input->keyboard.text == 0)
530+
{
531+
static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ ";
532+
static const char Shift[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ)!@#$%^&*(_+{}|:\"~<>? ";
533+
534+
enum{Count = sizeof Symbols};
535+
536+
for(s32 i = 0; i < TIC80_KEY_BUFFER; i++)
537+
{
538+
tic_key key = tic->ram.input.keyboard.keys[i];
539+
540+
if(key > 0 && key < Count && tic->api.keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD))
541+
{
542+
bool caps = tic->api.key(tic, tic_key_capslock);
543+
bool shift = tic->api.key(tic, tic_key_shift);
544+
545+
input->keyboard.text = caps
546+
? key >= tic_key_a && key <= tic_key_z
547+
? shift ? Symbols[key] : Shift[key]
548+
: shift ? Shift[key] : Symbols[key]
549+
: shift ? Shift[key] : Symbols[key];
550+
}
551+
}
552+
}
520553
break;
521554
}
522555
}
@@ -734,6 +767,9 @@ static void handleKeydown(SDL_Keycode keycode, bool down)
734767
break;
735768
}
736769
}
770+
771+
if(keycode == SDLK_AC_BACK)
772+
platform.keyboard.state[tic_key_escape] = down;
737773
}
738774

739775
static void pollEvent()
@@ -742,7 +778,7 @@ static void pollEvent()
742778
tic80_input* input = &tic->ram.input;
743779

744780
input->mouse.btns = 0;
745-
tic->ram.input.keyboard.text = 0;
781+
input->keyboard.text = 0;
746782

747783
SDL_Event event;
748784

src/tic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@
114114
#define SFX_NOTES {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"}
115115
#define TIC_FONT_CHARS 256
116116

117+
#define KEYBOARD_HOLD 20
118+
#define KEYBOARD_PERIOD 3
119+
117120
enum
118121
{
119122
NoteNone = 0,

0 commit comments

Comments
 (0)