reverted ugly keyboard handling

This commit is contained in:
nesbox 2018-09-04 23:22:59 +03:00
parent ae2f23a1d5
commit 559a8bb920
9 changed files with 51 additions and 67 deletions

View File

@ -110,17 +110,10 @@ typedef struct
typedef u8 tic_key;
typedef struct
typedef union
{
union
{
tic_key keys[TIC80_KEY_BUFFER];
u32 data;
};
s8 text;
u8 temp[3];
tic_key keys[TIC80_KEY_BUFFER];
u32 data;
} tic80_keyboard;
typedef struct
@ -128,6 +121,7 @@ typedef struct
tic80_gamepads gamepads;
tic80_mouse mouse;
tic80_keyboard keyboard;
} tic80_input;
TIC80_API tic80* tic80_create(s32 samplerate);

View File

@ -1046,7 +1046,7 @@ static void textEditTick(Code* code)
if(!tic->api.key(tic, tic_key_ctrl) && !tic->api.key(tic, tic_key_alt))
{
char sym = tic->ram.input.keyboard.text;
char sym = getKeyboardText();
if(sym)
{
@ -1113,8 +1113,6 @@ static char* downStrStr(const char* start, const char* from, const char* substr)
static void textFindTick(Code* code)
{
tic_mem* tic = code->tic;
if(keyWasPressed(tic_key_return)) setCodeMode(code, TEXT_EDIT_MODE);
else if(keyWasPressed(tic_key_up)
|| keyWasPressed(tic_key_down)
@ -1139,7 +1137,7 @@ static void textFindTick(Code* code)
}
}
char sym = tic->ram.input.keyboard.text;
char sym = getKeyboardText();
if(sym)
{
@ -1197,7 +1195,7 @@ static void textGoToTick(Code* code)
}
}
char sym = tic->ram.input.keyboard.text;
char sym = getKeyboardText();
if(sym)
{
@ -1267,8 +1265,6 @@ static void drawOutlineBar(Code* code, s32 x, s32 y)
static void textOutlineTick(Code* code)
{
tic_mem* tic = code->tic;
if(keyWasPressed(tic_key_up))
{
if(code->outline.index > 0)
@ -1299,7 +1295,7 @@ static void textOutlineTick(Code* code)
}
}
char sym = tic->ram.input.keyboard.text;
char sym = getKeyboardText();
if(sym)
{

View File

@ -2850,7 +2850,7 @@ static void tick(Console* console)
console->cursor.delay = CONSOLE_CURSOR_DELAY;
}
char sym = tic->ram.input.keyboard.text;
char sym = getKeyboardText();
if(sym)
{

View File

@ -890,7 +890,7 @@ static void processTrackerKeyboard(Music* music)
{
s32 octave = -1;
char sym = tic->ram.input.keyboard.text;
char sym = getKeyboardText();
if(sym >= '1' && sym <= '8') octave = sym - '1';
@ -907,7 +907,7 @@ static void processTrackerKeyboard(Music* music)
{
s32 val = -1;
char sym = tic->ram.input.keyboard.text;
char sym = getKeyboardText();
if (sym >= '0' && sym <= '9') val = sym - '0';
@ -932,7 +932,7 @@ static void processTrackerKeyboard(Music* music)
{
s32 val = -1;
char sym = tic->ram.input.keyboard.text;
char sym = getKeyboardText();
if(sym >= '0' && sym <= '9') val = sym - '0';
if(sym >= 'a' && sym <= 'f') val = sym - 'a' + 10;
@ -969,7 +969,7 @@ static void processPatternKeyboard(Music* music)
{
s32 val = -1;
char sym = tic->ram.input.keyboard.text;
char sym = getKeyboardText();
if(sym >= '0' && sym <= '9') val = sym - '0';

View File

@ -231,6 +231,36 @@ static struct
.argv = NULL,
};
char getKeyboardText()
{
tic_mem* tic = impl.studio.tic;
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);
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)
{
tic_mem* tic = impl.studio.tic;

View File

@ -157,6 +157,7 @@ tic_tiles* getBankTiles();
tic_palette* getBankPalette();
tic_map* getBankMap();
char getKeyboardText();
bool keyWasPressed(tic_key key);
bool anyKeyWasPressed();

View File

@ -67,11 +67,6 @@ static struct
bool state[tic_keys_count];
struct
{
bool state[tic_keys_count];
} touch;
} keyboard;
u32 touchCounter;
@ -424,33 +419,8 @@ static void processKeyboard()
enum{BufSize = COUNT_OF(input->keyboard.keys)};
for(s32 i = 0, c = 0; i < COUNT_OF(platform.keyboard.state) && c < BufSize; i++)
if(platform.keyboard.state[i] || platform.keyboard.touch.state[i])
if(platform.keyboard.state[i])
input->keyboard.keys[c++] = i;
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];
}
}
}
}
#if !defined(__EMSCRIPTEN__) && !defined(__MACOSX__)
@ -778,7 +748,6 @@ static void pollEvent()
tic80_input* input = &tic->ram.input;
input->mouse.btns = 0;
input->keyboard.text = 0;
SDL_Event event;
@ -829,7 +798,9 @@ static void pollEvent()
updateGamepadParts();
}
break;
case SDL_WINDOWEVENT_FOCUS_GAINED: platform.studio->updateProject(); break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
platform.studio->updateProject();
break;
}
break;
case SDL_KEYDOWN:
@ -838,14 +809,6 @@ static void pollEvent()
case SDL_KEYUP:
handleKeydown(event.key.keysym.sym, false);
break;
case SDL_TEXTINPUT:
{
const char* text = event.text.text;
if(strlen(text) == 1)
tic->ram.input.keyboard.text = *text;
}
break;
case SDL_QUIT:
platform.studio->exit();
break;

View File

@ -81,7 +81,7 @@ STATIC_ASSERT(tic_track, sizeof(tic_track) == 3*MUSIC_FRAMES+3);
STATIC_ASSERT(tic_vram, sizeof(tic_vram) == TIC_VRAM_SIZE);
STATIC_ASSERT(tic_ram, sizeof(tic_ram) == TIC_RAM_SIZE);
STATIC_ASSERT(tic_sound_register, sizeof(tic_sound_register) == 16+2);
STATIC_ASSERT(tic80_input, sizeof(tic80_input) == 16);
STATIC_ASSERT(tic80_input, sizeof(tic80_input) == 12);
static void update_amp(blip_buffer_t* blip, tic_sound_register_data* data, s32 new_amp )
{

View File

@ -422,7 +422,7 @@ typedef union
tic_tiles sprites;
tic_map map;
tic80_input input;
u8 unknown[12];
u8 unknown[16];
tic_sound_register registers[TIC_SOUND_CHANNELS];
tic_sfx sfx;
tic_music music;