vtgl

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

Commit: 3febfbd497ad1c5479edc7f8c618867aeb11c91d
Parent: 7eb72fc276b9781d494e3826dd81558a0ff8fe26
Author: Randy Palamar
Date:   Sat, 19 Oct 2024 12:41:17 -0600

drop cell padding

this is incompatible with rendering proper glyph runs.

Diffstat:
Mconfig.def.h | 6++----
Mvtgl.c | 38+++++++++++++++-----------------------
2 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -12,10 +12,8 @@ static FontDesc g_fonts[][FS_LAST] = { static FontDesc g_debug_font_desc = {.path = "/usr/share/fonts/gofont/Go-Mono-Bold.ttf", .height = 18}; #endif -/* NOTE: terminal padding in pixels */ -static v2 g_term_pad = {.w = 8, .h = 8}; -/* NOTE: cell padding in pixels (glyphs will be centered) */ -static v2 g_cell_pad = {.w = 0, .h = 0}; +/* NOTE: terminal margin in pixels */ +static v2 g_term_margin = {.w = 8, .h = 8}; static u8 g_tabstop = 8; diff --git a/vtgl.c b/vtgl.c @@ -57,14 +57,7 @@ set_projection_matrix(GLCtx *gl) static v2 get_cell_size(Term *t) { - v2 result = {.w = t->fa.info.w + g_cell_pad.w, .h = t->fa.info.h + g_cell_pad.h}; - return result; -} - -static v2 -get_cell_pad_off(void) -{ - v2 result = {.w = 0.5 * g_cell_pad.w, .h = 0.5 * g_cell_pad.h}; + v2 result = {.w = t->fa.info.w, .h = t->fa.info.h}; return result; } @@ -104,8 +97,8 @@ static void resize(Term *t) { v2 ws = t->gl.window_size; - ws.w -= 2 * g_term_pad.w; - ws.h -= 2 * g_term_pad.h; + ws.w -= 2 * g_term_margin.w; + ws.h -= 2 * g_term_margin.h; uv2 old_size = t->size; v2 cs = get_cell_size(t); @@ -240,7 +233,7 @@ draw_rectangle(RenderPushBuffer *rpb, GLCtx *gl, Rect r, Colour colour) } static void -push_cell(RenderPushBuffer *rpb, GLCtx *gl, Arena a, FontAtlas *fa, Cell c, Rect r, v2 cell_font_delta) +push_cell(RenderPushBuffer *rpb, GLCtx *gl, Arena a, FontAtlas *fa, Cell c, Rect r, f32 font_y_delta) { BEGIN_TIMED_BLOCK(); u32 idx = get_render_push_buffer_idx(rpb, gl, 2); @@ -254,8 +247,8 @@ push_cell(RenderPushBuffer *rpb, GLCtx *gl, Arena a, FontAtlas *fa, Cell c, Rect rpb->vertoffsets[idx + 0] = r.pos; rpb->vertoffsets[idx + 1] = (v2){ - .x = r.pos.x + g.delta.x + cell_font_delta.x, - .y = r.pos.y + g.delta.y + cell_font_delta.y, + .x = r.pos.x + g.delta.x, + .y = r.pos.y + g.delta.y + font_y_delta, }; rpb->texscales[idx + 0] = (v2){0}; @@ -283,7 +276,7 @@ push_cell(RenderPushBuffer *rpb, GLCtx *gl, Arena a, FontAtlas *fa, Cell c, Rect static void push_cell_row(RenderPushBuffer *rpb, GLCtx *gl, Arena a, FontAtlas *fa, Cell *row, u32 len, - b32 inverse, Rect cr, v2 cell_font_delta) + b32 inverse, Rect cr, f32 font_y_delta) { ASSERT(inverse == 0 || inverse == 1); v2 cs = cr.size; @@ -295,7 +288,7 @@ push_cell_row(RenderPushBuffer *rpb, GLCtx *gl, Arena a, FontAtlas *fa, Cell *ro if (cell.style.attr & ATTR_WIDE) cr.size = csw; else cr.size = cs; cell.style.attr ^= inverse * ATTR_INVERSE; - push_cell(rpb, gl, a, fa, cell, cr, cell_font_delta); + push_cell(rpb, gl, a, fa, cell, cr, font_y_delta); cr.pos.x += cr.size.w; } } @@ -313,14 +306,13 @@ render_framebuffer(Term *t, RenderPushBuffer *rpb) v2 cs = get_cell_size(t); Rect cr = {.pos = {.x = tl.x, .y = tl.y - cs.h}, .size = cs}; - v2 cell_font_delta = get_cell_pad_off(); - cell_font_delta.y += t->fa.info.baseline; + f32 font_y_delta = t->fa.info.baseline; TermView *tv = t->views + t->view_idx; /* NOTE: draw whole framebuffer */ for (u32 r = 0; r < t->size.h; r++) { push_cell_row(rpb, &t->gl, t->arena_for_frame, &t->fa, tv->fb.rows[r], t->size.w, 0, - cr, cell_font_delta); + cr, font_y_delta); cr.pos.y -= cs.h; } @@ -335,14 +327,14 @@ render_framebuffer(Term *t, RenderPushBuffer *rpb) for (; curs.y < end.y; curs.y++) { u32 len = t->size.w - curs.x - 1; push_cell_row(rpb, &t->gl, t->arena_for_frame, &t->fa, - tv->fb.rows[curs.y] + curs.x, len, 1, cr, cell_font_delta); + tv->fb.rows[curs.y] + curs.x, len, 1, cr, font_y_delta); curs.x = 0; cr.pos.x = tl.x; cr.pos.y -= cs.h; } /* NOTE: do the last row */ push_cell_row(rpb, &t->gl, t->arena_for_frame, &t->fa, tv->fb.rows[curs.y] + curs.x, - end.x - curs.x + 1, 1, cr, cell_font_delta); + end.x - curs.x + 1, 1, cr, font_y_delta); } /* NOTE: draw cursor */ @@ -357,7 +349,7 @@ render_framebuffer(Term *t, RenderPushBuffer *rpb) cursor.style.attr ^= ATTR_INVERSE; if ((t->mode & TM_ALTSCREEN) == 0) cursor.style.attr |= ATTR_BLINK; - push_cell(rpb, &t->gl, t->arena_for_frame, &t->fa, cursor, cr, cell_font_delta); + push_cell(rpb, &t->gl, t->arena_for_frame, &t->fa, cursor, cr, font_y_delta); } END_TIMED_BLOCK(); @@ -742,8 +734,8 @@ init_term(Term *t, Arena *a, iv2 cells) selection_clear(&t->selection); v2 cs = get_cell_size(t); iv2 requested_size = { - .x = cs.x * cells.x + 2 * g_term_pad.x, - .y = cs.y * cells.y + 2 * g_term_pad.y, + .x = cs.x * cells.x + 2 * g_term_margin.x, + .y = cs.y * cells.y + 2 * g_term_margin.y, }; return requested_size; }