diff --git a/Pontu/src/engine/InputProcessor.c b/Pontu/src/engine/InputProcessor.c index 4e889e2..79059e0 100644 --- a/Pontu/src/engine/InputProcessor.c +++ b/Pontu/src/engine/InputProcessor.c @@ -3,7 +3,8 @@ InputProcessor createInputProcessor() { InputProcessor inputProcessor = { .tabButton = array_P_Button_Create(), - .tabTextInput = array_TextInput_Create() + .tabTextInput = array_TextInput_Create(), + .selectedTextInput = NULL }; return inputProcessor; } diff --git a/Pontu/src/engine/TextInput.c b/Pontu/src/engine/TextInput.c index ab36541..0e21f34 100644 --- a/Pontu/src/engine/TextInput.c +++ b/Pontu/src/engine/TextInput.c @@ -14,8 +14,8 @@ bool addStringToInputTextValueAtCursor(TextInput* textInput, const char* strToAd const size_t lenStrToAdd = strlen(strToAdd); char newValue[lenText+lenStrToAdd+1]; - //strcpy(newValue, ""); - strncat(newValue, textInput->value, textInput->cursorPosition); + strcpy(newValue, ""); + strncpy(newValue, textInput->value, textInput->cursorPosition); strcat(newValue, strToAdd); strcat(newValue, textInput->value+textInput->cursorPosition); @@ -34,8 +34,8 @@ bool addStringToInputTextValueAtCursor(TextInput* textInput, const char* strToAd bool removeCharacterToInputTextValueAtCursor(TextInput* textInput) { size_t removeSize = 0; - size_t lenText = strlen(textInput->value); - while (lenText>removeSize && textInput->value[textInput->cursorPosition - 1] < -64) { + size_t lenText = strlen(textInput->value); + while (lenText>removeSize && textInput->value[textInput->cursorPosition - removeSize-1] < -64) { removeSize++; } if (lenText>removeSize) { @@ -69,9 +69,9 @@ bool removeCharacterToInputTextValueAtCursor(TextInput* textInput) } strcpy(tmp, textInput->value); - //strcpy(textInput->value, ""); + strcpy(textInput->value, ""); strncpy(textInput->value, tmp, textInput->cursorPosition-removeSize); - strcat(textInput->value, tmp+textInput->cursorPosition); + strcat(textInput->value, tmp+textInput->cursorPosition+1); textInput->cursorPosition -= 1; return true; } diff --git a/Pontu/test/testTextInputWithProcessor.c b/Pontu/test/testTextInputWithProcessor.c index c810003..ab0b0a4 100644 --- a/Pontu/test/testTextInputWithProcessor.c +++ b/Pontu/test/testTextInputWithProcessor.c @@ -52,7 +52,7 @@ SDL_Rect windowSize = {10, 10, 900, 900}; TextInput* textInput = array_TextInput_Last(&inputProcessor.tabTextInput); SDL_Rect size = {.x=10, .y=10, .w=90, .h=20}; - if(!initTextInput(textInput, &size, NULL, fontHandler.fonts[FONT_retro])) + if(!initTextInput(textInput, &size, NULL, fontHandler.fonts[FONT_PublicPixel])) { fprintf(stderr, "WARNING: can't init TextInput\n"); return;