Skip to content

Commit

Permalink
Fix console text rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Nov 23, 2024
1 parent f83058a commit 3e6dc77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/console/console_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef struct {
int isopen;
int ownsinput;
int ypos;
text_object text_cache[2];
hashmap cmds; // string -> command
} console;

Expand Down

0 comments on commit 3e6dc77

Please sign in to comment.