Skip to content

Commit

Permalink
Merge pull request #2305 from NeoLight1010/numpad-enter
Browse files Browse the repository at this point in the history
Handle Numpad Enter key as regular Enter key
  • Loading branch information
nesbox authored Sep 25, 2023
2 parents cc50420 + c556efb commit 9ed1529
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/studio/editors/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ static void processViKeyboard(Code* code)
else if (keyWasPressed(code->studio, tic_key_tab))
doTab(code, shift, ctrl);

else if (keyWasPressed(code->studio, tic_key_return))
else if (enterWasPressed(code->studio))
newLine(code);

else if (clear || shift)
Expand Down Expand Up @@ -2995,14 +2995,14 @@ static void processKeyboard(Code* code)
else if(keyWasPressed(code->studio, tic_key_pagedown)) pageDown(code);
else if(keyWasPressed(code->studio, tic_key_delete)) deleteChar(code);
else if(keyWasPressed(code->studio, tic_key_backspace)) backspaceChar(code);
else if(keyWasPressed(code->studio, tic_key_return)) newLine(code);
else if(enterWasPressed(code->studio)) newLine(code);
else if(keyWasPressed(code->studio, tic_key_tab)) doTab(code, shift, ctrl);
else usedKeybinding = false;
}

if(!usedKeybinding)
{
if(shift && keyWasPressed(code->studio, tic_key_return))
if(shift && enterWasPressed(code->studio))
{
newLineAutoClose(code);
usedKeybinding = true;
Expand Down Expand Up @@ -3181,7 +3181,7 @@ static void textFindTick(Code* code)
{


if(keyWasPressed(code->studio, tic_key_return)) setCodeMode(code, TEXT_EDIT_MODE);
if(enterWasPressed(code->studio)) setCodeMode(code, TEXT_EDIT_MODE);
else if(keyWasPressed(code->studio, tic_key_up)
|| keyWasPressed(code->studio, tic_key_down)
|| keyWasPressed(code->studio, tic_key_left)
Expand Down Expand Up @@ -3226,7 +3226,7 @@ static void textFindTick(Code* code)
static void textReplaceTick(Code* code)
{

if(keyWasPressed(code->studio, tic_key_return)) {
if (enterWasPressed(code->studio)) {
if (*code->popup.text && code->popup.offset == NULL) //still in "find" mode
{
code->popup.offset = code->popup.text + strlen(code->popup.text);
Expand Down Expand Up @@ -3317,7 +3317,7 @@ static void textGoToTick(Code* code)
{
tic_mem* tic = code->tic;

if(keyWasPressed(code->studio, tic_key_return))
if(enterWasPressed(code->studio))
{
if(*code->popup.text)
updateGotoCode(code);
Expand Down Expand Up @@ -3462,7 +3462,7 @@ static void processSidebar(Code* code)
else if(keyWasPressed(code->studio, tic_key_end))
updateSidebarIndex(code, code->sidebar.size - 1);

else if(keyWasPressed(code->studio, tic_key_return))
else if(enterWasPressed(code->studio))
{
updateSidebarCode(code);
setCodeMode(code, TEXT_EDIT_MODE);
Expand Down
4 changes: 2 additions & 2 deletions src/studio/editors/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ static void processPatternKeyboard(Music* music)
else if(keyWasPressed(music->studio, tic_key_left)) colLeft(music);
else if(keyWasPressed(music->studio, tic_key_right)) colRight(music);
else if(keyWasPressed(music->studio, tic_key_down)
|| keyWasPressed(music->studio, tic_key_return))
|| enterWasPressed(music->studio))
music->tracker.edit.y = music->scroll.pos;
else
{
Expand Down Expand Up @@ -1542,7 +1542,7 @@ static void processKeyboard(Music* music)
? playTrack(music)
: stopTrack(music);
}
else if(keyWasPressed(music->studio, tic_key_return))
else if(enterWasPressed(music->studio))
{
stopped
? (shift
Expand Down
2 changes: 1 addition & 1 deletion src/studio/screens/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -4089,7 +4089,7 @@ static void processKeyboard(Console* console)
if(console->input.pos > len)
console->input.pos = len;
}
else if(keyWasPressed(console->studio, tic_key_return)) processConsoleCommand(console);
else if(enterWasPressed(console->studio)) processConsoleCommand(console);
else if(keyWasPressed(console->studio, tic_key_backspace)) processConsoleBackspace(console);
else if(keyWasPressed(console->studio, tic_key_delete)) processConsoleDel(console);
else if(keyWasPressed(console->studio, tic_key_home)) processConsoleHome(console);
Expand Down
3 changes: 1 addition & 2 deletions src/studio/screens/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ static void drawMenu(Menu* menu, s32 x, s32 y)
}
}

if(tic_api_btnp(menu->tic, A, -1, -1)
|| tic_api_keyp(tic, tic_key_return, Hold, Period))
if(tic_api_btnp(menu->tic, A, -1, -1) || ticEnterWasPressed(tic, -1, -1))
{
if(option)
{
Expand Down
6 changes: 3 additions & 3 deletions src/studio/screens/surf.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,8 @@ static void processGamepad(Surf* surf)
move(surf, dir);
}

if(tic_api_btnp(tic, A, -1, -1)
|| tic_api_keyp(tic, tic_key_return, -1, -1))
if(tic_api_btnp(tic, A, -1, -1)
|| ticEnterWasPressed(tic, -1, -1))
{
SurfItem* item = getMenuItem(surf);
item->dir
Expand Down Expand Up @@ -906,4 +906,4 @@ void freeSurf(Surf* surf)
freeAnim(surf);
resetMenu(surf);
free(surf);
}
}
23 changes: 21 additions & 2 deletions src/studio/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,19 @@ bool keyWasPressed(Studio* studio, tic_key key)
return tic_api_keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD);
}

bool enterWasPressed(Studio* studio)
{
tic_mem* tic = studio->tic;
return ticEnterWasPressed(tic, KEYBOARD_HOLD, KEYBOARD_PERIOD);
}

bool ticEnterWasPressed(tic_mem* tic, s32 hold, s32 period)
{
return tic_api_keyp(tic, tic_key_return, hold, period) ||
tic_api_keyp(tic, tic_key_numpadenter, hold, period);
}


bool anyKeyWasPressed(Studio* studio)
{
tic_mem* tic = studio->tic;
Expand Down Expand Up @@ -1695,6 +1708,12 @@ void gotoMenu(Studio* studio)
studio->mainmenu = studio_mainmenu_init(studio->menu, studio->config);
}

static bool enterWasPressedOnce(Studio* studio)
{
return keyWasPressedOnce(studio, tic_key_return) ||
keyWasPressedOnce(studio, tic_key_numpadenter);
}

static void processShortcuts(Studio* studio)
{
tic_mem* tic = studio->tic;
Expand All @@ -1716,7 +1735,7 @@ static void processShortcuts(Studio* studio)

if(alt)
{
if (keyWasPressedOnce(studio, tic_key_return)) gotoFullscreen(studio);
if (enterWasPressedOnce(studio)) gotoFullscreen(studio);
#if defined(BUILD_EDITORS)
else if(studio->mode != TIC_RUN_MODE)
{
Expand All @@ -1735,7 +1754,7 @@ static void processShortcuts(Studio* studio)
#if defined(BUILD_EDITORS)
else if(keyWasPressedOnce(studio, tic_key_pageup)) changeStudioMode(studio, -1);
else if(keyWasPressedOnce(studio, tic_key_pagedown)) changeStudioMode(studio, +1);
else if(keyWasPressedOnce(studio, tic_key_return)) runGame(studio);
else if(enterWasPressedOnce(studio)) runGame(studio);
else if(keyWasPressedOnce(studio, tic_key_r)) runGame(studio);
else if(keyWasPressedOnce(studio, tic_key_s)) saveProject(studio);
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/studio/studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ tic_map* getBankMap(Studio* studio);

char getKeyboardText(Studio* studio);
bool keyWasPressed(Studio* studio, tic_key key);
bool enterWasPressed(Studio* studio);
bool anyKeyWasPressed(Studio* studio);
bool ticEnterWasPressed(tic_mem* tic, s32 hold, s32 period);

const StudioConfig* getConfig(Studio* studio);
struct Start* getStartScreen(Studio* studio);
Expand Down

0 comments on commit 9ed1529

Please sign in to comment.