Skip to content

Commit

Permalink
#707 final fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nesbox committed Sep 2, 2018
1 parent 4d08ad0 commit 178007c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 7 additions & 1 deletion src/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions src/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 39 additions & 3 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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()
Expand All @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions src/tic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 178007c

Please sign in to comment.