Can't figure out why this.cur_size never increases above 1 when i add characters to this.char. Any ideas whats wrong with the appendInTextBox?
Code:
/** \ TEXT BOX /
typedef struct TextBox {
SDL_Texture* texture_normal;
SDL_Texture* texture_selected;
SDL_Texture* texture_btn_txt;
SDL_Rect rect_box;
SDL_Rect rect_text;
int cur_size;
int max_size;
char* msg;
bool highlighted;
bool selected;
bool show;
} TextBox;
*/
TextBox createTextBox(SDL_Texture* tex_norm, SDL_Texture* tex_select, TTF_Font *font, SDL_Color txt_color, int x, int y, bool show)
{
TextBox this;
this.rect_box.x = x;
this.rect_box.y = y;
if (tex_norm != NULL) {
this.texture_normal = tex_norm;
SDL_QueryTexture(this.texture_normal, NULL, NULL, &this.rect_box.w, &this.rect_box.h);
}
if (tex_select != NULL) {
this.texture_selected = tex_select;
}
this.highlighted = false;
this.selected = false;
this.show = show;
this.max_size = 10;
this.cur_size = 0;
this.msg = malloc(this.max_size + 2);
this.msg[0] = '\0';
return this;
}
void appendInTextBox(TextBox this, char* msg_)
{
for (int i = 0; msg_[i] != '\0'; i++)
{
if (this.cur_size < this.max_size) {
this.msg[this.cur_size] = msg_[i];
this.cur_size++;
this.msg[this.cur_size] = '\0';
}
}
printf("cur: %d, s: %s\n", this.cur_size, this.msg);
}