vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: f0a0f38dfca2b25c62c8a81b3cba4cda03417b6d
Parent: 21929b5877058ac6e5a807654cc38f540aebd57b
Author: Randy Palamar
Date:   Wed, 21 Aug 2024 09:18:52 -0600

use relative position for making selections

Diffstat:
Mvtgl.c | 25+++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/vtgl.c b/vtgl.c @@ -85,6 +85,22 @@ get_terminal_top_left(Term *t) return result; } +static v2 +get_terminal_bot_left(Term *t) +{ + v2 cs = get_cell_size(t); + v2 occupied_size = {.x = t->size.w * cs.w, .y = t->size.h * cs.h}; + v2 delta = { + .x = t->gl.window_size.w - 2 * g_term_pad.w - occupied_size.w, + .y = t->gl.window_size.h - 2 * g_term_pad.h - occupied_size.h + }; + v2 result = { + .x = g_term_pad.w + delta.x / 2, + .y = g_term_pad.h + delta.y / 2 + }; + return result; +} + static void resize(Term *t) { @@ -365,13 +381,10 @@ mouse_to_cell_space(Term *t, v2 mouse) { iv2 result = {0}; v2 cell_size = get_cell_size(t); + v2 bot_left = get_terminal_bot_left(t); - /* TODO: this needs to be adjusted for padding */ - f32 delta_x = t->gl.window_size.x - t->size.w * cell_size.w; - f32 delta_y = t->gl.window_size.h - t->size.h * cell_size.h; - - result.x = (i32)((mouse.x + delta_x) / cell_size.w); - result.y = (i32)((mouse.y + delta_y) / cell_size.h) - 1; + result.x = (i32)((mouse.x - bot_left.x) / cell_size.w); + result.y = (i32)((mouse.y - bot_left.y) / cell_size.h); CLAMP(result.x, 0, t->size.w - 1); CLAMP(result.y, 0, t->size.h - 1);