From 3e6dc776929c48e9d881f1b5aeb7ac45ec0b08af Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Sat, 23 Nov 2024 11:02:13 -0800 Subject: [PATCH] Fix console text rendering --- src/console/console.c | 8 +++++--- src/console/console_type.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/console/console.c b/src/console/console.c index febba90c2..d59f0c96c 100644 --- a/src/console/console.c +++ b/src/console/console.c @@ -268,6 +268,7 @@ void console_event(game_state *gs, SDL_Event *e) { if(isprint(c) && len < sizeof(con->input) - 1) { con->input[len + 1] = '\0'; con->input[len] = tolower(c); + con->text_cache[0].dirty = true; } } } else if(e->type == SDL_KEYDOWN) { @@ -293,11 +294,13 @@ void console_event(game_state *gs, SDL_Event *e) { } else if(scancode == SDL_SCANCODE_BACKSPACE || scancode == SDL_SCANCODE_DELETE) { if(len > 0) { con->input[len - 1] = '\0'; + con->text_cache[0].dirty = true; } } else if(scancode == SDL_SCANCODE_RETURN || scancode == SDL_SCANCODE_KP_ENTER) { // send the input somewhere and clear the input line console_handle_line(gs); con->input[0] = '\0'; + con->text_cache[0].dirty = true; } else if(scancode == SDL_SCANCODE_PAGEUP) { console_output_scroll_up(1); } else if(scancode == SDL_SCANCODE_PAGEDOWN) { @@ -311,7 +314,6 @@ void console_render(void) { return; } - static text_object text_cache[2] = {0}; if(con->ypos > 0) { if(con->histpos != -1 && con->histpos_changed) { char *input = list_get(&con->history, con->histpos); @@ -329,11 +331,11 @@ void console_render(void) { tconf.font = FONT_SMALL; // input line tconf.cforeground = TEXT_MEDIUM_GREEN; - text_render(&text_cache[0], &tconf, TEXT_DEFAULT, 0, con->ypos - 7, 300, 6, con->input); + text_render(&con->text_cache[0], &tconf, TEXT_DEFAULT, 0, con->ypos - 7, 300, 6, con->input); // cursor tconf.cforeground = TEXT_BLINKY_GREEN; - text_render(&text_cache[1], &tconf, TEXT_DEFAULT, strlen(con->input) * font_small.w, con->ypos - 7, 6, 6, + text_render(&con->text_cache[1], &tconf, TEXT_DEFAULT, strlen(con->input) * font_small.w, con->ypos - 7, 6, 6, CURSOR_STR); console_output_render(); } diff --git a/src/console/console_type.h b/src/console/console_type.h index b0b19f22d..4bbf378d8 100644 --- a/src/console/console_type.h +++ b/src/console/console_type.h @@ -20,6 +20,7 @@ typedef struct { int isopen; int ownsinput; int ypos; + text_object text_cache[2]; hashmap cmds; // string -> command } console;