term: Fix bug introduced when moving from int to size_t for coordinates. Fixes #110

This commit is contained in:
mintsuki 2021-09-11 08:43:39 +02:00
parent de673e2ac9
commit 7ad45e8daf
2 changed files with 20 additions and 4 deletions

View File

@ -242,10 +242,18 @@ void text_move_character(size_t new_x, size_t new_y, size_t old_x, size_t old_y)
void text_set_cursor_pos(size_t x, size_t y) { void text_set_cursor_pos(size_t x, size_t y) {
clear_cursor(); clear_cursor();
if (x >= VD_COLS / 2) { if (x >= VD_COLS / 2) {
x = VD_COLS / 2 - 1; if ((int)x < 0) {
x = 0;
} else {
x = VD_COLS / 2 - 1;
}
} }
if (y >= VD_ROWS) { if (y >= VD_ROWS) {
y = VD_ROWS - 1; if ((int)y < 0) {
y = 0;
} else {
y = VD_ROWS - 1;
}
} }
cursor_offset = y * VD_COLS + x * 2; cursor_offset = y * VD_COLS + x * 2;
draw_cursor(); draw_cursor();

View File

@ -416,10 +416,18 @@ bool gterm_disable_cursor(void) {
void gterm_set_cursor_pos(size_t x, size_t y) { void gterm_set_cursor_pos(size_t x, size_t y) {
clear_cursor(); clear_cursor();
if (x >= cols) { if (x >= cols) {
x = cols - 1; if ((int)x < 0) {
x = 0;
} else {
x = cols - 1;
}
} }
if (y >= rows) { if (y >= rows) {
y = rows - 1; if ((int)y < 0) {
y = 0;
} else {
y = rows - 1;
}
} }
cursor_x = x; cursor_x = x;
cursor_y = y; cursor_y = y;