vtgl

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

Commit: 6554a03245002e17fcad62279eccf79c5ae1fdb4
Parent: 0ddc8946923f4b2d439f32e7bf37152af6e7205e
Author: Randy Palamar
Date:   Sun,  1 Sep 2024 13:10:36 -0600

add configurable cell padding for glyphs

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

diff --git a/config.def.h b/config.def.h @@ -4,7 +4,9 @@ static char *g_fonts[] = { }; /* NOTE: terminal padding in pixels */ -static v2 g_term_pad = {.w = 8, .h = 8}; +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 = 6}; static u8 g_tabstop = 8; diff --git a/vtgl.c b/vtgl.c @@ -61,11 +61,14 @@ set_projection_matrix(GLCtx *gl) static v2 get_cell_size(Term *t) { - /* TODO: Make padding configurable */ - v2 result = { - .w = t->fa.size.w + 0, - .h = t->fa.size.h + 8, - }; + v2 result = {.w = t->fa.size.w + g_cell_pad.w, .h = t->fa.size.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}; return result; } @@ -277,7 +280,7 @@ draw_rectangle(RenderPushBuffer *rpb, GLCtx *gl, Rect r, Colour colour) } static void -push_cell(RenderPushBuffer *rpb, GLCtx *gl, FontAtlas *fa, Cell c, Rect r, f32 font_text_dy) +push_cell(RenderPushBuffer *rpb, GLCtx *gl, FontAtlas *fa, Cell c, Rect r, v2 cell_font_delta) { u32 idx = get_render_push_buffer_idx(rpb, gl, 2); @@ -290,8 +293,8 @@ push_cell(RenderPushBuffer *rpb, GLCtx *gl, FontAtlas *fa, Cell c, Rect r, f32 f rpb->vertoffsets[idx + 0] = r.pos; rpb->vertoffsets[idx + 1] = (v2){ - .x = r.pos.x + g.delta.x, - .y = r.pos.y + g.delta.y + font_text_dy, + .x = r.pos.x + g.delta.x + cell_font_delta.x, + .y = r.pos.y + g.delta.y + cell_font_delta.y, }; rpb->texscales[idx + 0] = (v2){0}; @@ -316,7 +319,8 @@ push_cell(RenderPushBuffer *rpb, GLCtx *gl, FontAtlas *fa, Cell c, Rect r, f32 f } static void -push_cell_row(Term *t, Cell *row, u32 len, b32 inverse, Rect cr, RenderPushBuffer *rpb) +push_cell_row(RenderPushBuffer *rpb, GLCtx *gl, FontAtlas *fa, Cell *row, u32 len, b32 inverse, + Rect cr, v2 cell_font_delta) { ASSERT(inverse == 0 || inverse == 1); v2 cs = cr.size; @@ -328,7 +332,7 @@ push_cell_row(Term *t, Cell *row, u32 len, b32 inverse, Rect cr, RenderPushBuffe if (cell.style.attr & ATTR_WIDE) cr.size = csw; else cr.size = cs; cell.style.attr ^= inverse * ATTR_INVERSE; - push_cell(rpb, &t->gl, &t->fa, cell, cr, t->fa.deltay); + push_cell(rpb, gl, fa, cell, cr, cell_font_delta); cr.pos.x += cr.size.w; } } @@ -344,10 +348,14 @@ 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.deltay; + TermView *tv = t->views + t->view_idx; /* NOTE: draw whole framebuffer */ for (u32 r = 0; r < t->size.h; r++) { - push_cell_row(t, tv->fb.rows[r], t->size.w, 0, cr, rpb); + push_cell_row(rpb, &t->gl, &t->fa, tv->fb.rows[r], t->size.w, 0, + cr, cell_font_delta); cr.pos.y -= cs.h; } @@ -361,13 +369,15 @@ render_framebuffer(Term *t, RenderPushBuffer *rpb) /* NOTE: do full rows first */ for (; curs.y < end.y; curs.y++) { u32 len = t->size.w - curs.x - 1; - push_cell_row(t, tv->fb.rows[curs.y] + curs.x, len, 1, cr, rpb); + push_cell_row(rpb, &t->gl, &t->fa, tv->fb.rows[curs.y] + curs.x, len, 1, + cr, cell_font_delta); curs.x = 0; cr.pos.x = tl.x; cr.pos.y -= cs.h; } /* NOTE: do the last row */ - push_cell_row(t, tv->fb.rows[curs.y] + curs.x, end.x - curs.x + 1, 1, cr, rpb); + push_cell_row(rpb, &t->gl, &t->fa, tv->fb.rows[curs.y] + curs.x, + end.x - curs.x + 1, 1, cr, cell_font_delta); } /* NOTE: draw cursor */ @@ -382,7 +392,7 @@ render_framebuffer(Term *t, RenderPushBuffer *rpb) if (cursor.style.attr & ATTR_WIDE) cr.size.w *= 2; cursor.style.attr ^= ATTR_INVERSE; - push_cell(rpb, &t->gl, &t->fa, cursor, cr, t->fa.deltay); + push_cell(rpb, &t->gl, &t->fa, cursor, cr, cell_font_delta); } }