Allow typing with keyboard in menuitemKeyboard

This commit is contained in:
Matthew Coppola committed 2024-12-17 05:47:43 -05:00
1 parent 1e76f6af69
commit da07772b1c
5 files changed
+329 -43

No files matched your search

+54
View File
@@ -87,6 +87,10 @@ static f32 mouseSensX = 1.5f;
static f32 mouseSensY = 1.5f;
static s32 lastKey = 0;
static s32 keyRepeat = 0;
// buffer used to store text input during a text input event
static char textInputBuffer[11] = {0};
static const char *ckNames[CK_TOTAL_COUNT] = {
"R_CBUTTONS",
@@ -496,6 +500,7 @@ static int inputEventFilter(void *data, SDL_Event *event)
if (!lastKey) {
lastKey = VK_KEYBOARD_BEGIN + event->key.keysym.scancode;
}
keyRepeat = event->key.repeat;
break;
case SDL_CONTROLLERBUTTONDOWN:
@@ -521,6 +526,9 @@ static int inputEventFilter(void *data, SDL_Event *event)
}
}
break;
case SDL_TEXTINPUT:
inputSetTextInput(event->text.text);
break;
default:
break;
@@ -658,6 +666,9 @@ s32 inputInit(void)
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC);
}
// SDL enables text input event handling by default
inputStopTextInput();
// try to load controller db from an external file in the save folder
if (fsFileSize("$S/" CONTROLLERDB_FNAME)) {
const char *dbpath = fsFullPath("$S/" CONTROLLERDB_FNAME);
@@ -1114,6 +1125,11 @@ s32 inputKeyJustPressed(u32 vk)
return result;
}
s32 inputKeyJustPressedWithRepeat(u32 vk)
{
return inputKeyJustPressed(vk) || (keyRepeat && inputKeyPressed(vk));
}
static inline u32 inputContToContKey(const u32 cont)
{
if (cont == 0) {
@@ -1316,6 +1332,44 @@ s32 inputGetLastKey(void)
return lastKey;
}
void inputStartTextInput(void)
{
SDL_StartTextInput();
}
void inputStopTextInput(void)
{
SDL_StopTextInput();
textInputBuffer[0] = '\0';
}
s32 inputIsTextInputActive(void)
{
return SDL_IsTextInputActive();
}
void inputSetTextInput(char *textInput)
{
for (size_t i = 0; i < sizeof textInputBuffer - 1; ++i) {
if (textInput && i < strlen(textInput)) {
textInputBuffer[i] = textInput[i];
} else {
textInputBuffer[i] = '\0';
}
}
}
char *inputGetTextInput(void)
{
return textInputBuffer;
}
u32 inputGetModState(void)
{
return SDL_GetModState();
}
PD_CONSTRUCTOR static void inputConfigInit(void)
{
configRegisterInt("Input.MouseEnabled", &mouseEnabled, 0, 1);