|
|
|
@ -9,8 +9,19 @@ bool addStringToInputTextValue(TextInput* textInput, const char* strToAdd) {
|
|
|
|
|
|
|
|
|
|
const size_t lenText = strlen(textInput->value);
|
|
|
|
|
const size_t lenStrToAdd = strlen(strToAdd);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
textInput->value = (char*) realloc(textInput->value, sizeof(char) * (lenText+lenStrToAdd+1));
|
|
|
|
|
strcat(textInput->value, strToAdd);*/
|
|
|
|
|
|
|
|
|
|
if (textInput->maxTextSize != 0) {
|
|
|
|
|
if (lenText + lenStrToAdd > textInput->maxTextSize) {
|
|
|
|
|
fprintf(stderr, "WARNING: text to be added is too long");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
textInput->value = (char*) realloc(textInput->value, sizeof(char) * (lenText+lenStrToAdd+1));
|
|
|
|
|
}
|
|
|
|
|
strcat(textInput->value, strToAdd);
|
|
|
|
|
textInput->cursorPosition += lenStrToAdd;
|
|
|
|
|
return true;
|
|
|
|
@ -192,15 +203,17 @@ bool drawTextInputOnRenderer(SDL_Renderer* renderer, const TextInput* textInput)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool initTextInput(TextInput* textInput, const SDL_Rect* size, const SDL_Color* textColor, TTF_Font* font)
|
|
|
|
|
bool initTextInput(TextInput* textInput, const SDL_Rect* size, const SDL_Color* textColor, TTF_Font* font, size_t maxTextSize)
|
|
|
|
|
{
|
|
|
|
|
size_t sizeToMalloc;
|
|
|
|
|
if(textInput == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "WARNING: Can't assign value to NULL to create TextInput\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textInput->value = (char*) malloc(sizeof(char));
|
|
|
|
|
textInput->maxTextSize = maxTextSize <= 0 ? 0 : maxTextSize;
|
|
|
|
|
sizeToMalloc = textInput->maxTextSize == 0 ? sizeof(char) : maxTextSize * sizeof(char);
|
|
|
|
|
textInput->value = (char*) malloc(sizeToMalloc);
|
|
|
|
|
if(textInput->value == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "WARNING: Can't allocate memory space to TextInput\n");
|
|
|
|
|