diff options
-rw-r--r-- | src/libs/txt/txt.c | 19 | ||||
-rw-r--r-- | src/libs/txt/txt.h | 2 | ||||
-rw-r--r-- | src/modules/asc/asc.c | 14 | ||||
-rw-r--r-- | src/modules/rkt/rkt.c | 24 | ||||
-rw-r--r-- | src/modules/rtv/rtv.c | 20 | ||||
-rw-r--r-- | src/til_builtins.c | 12 |
6 files changed, 50 insertions, 41 deletions
diff --git a/src/libs/txt/txt.c b/src/libs/txt/txt.c index 883cd3e..d575821 100644 --- a/src/libs/txt/txt.c +++ b/src/libs/txt/txt.c @@ -168,22 +168,19 @@ static inline void draw_char(til_fb_fragment_t *fragment, uint32_t color, int x, } -void txt_render_fragment(txt_t *txt, til_fb_fragment_t *fragment, uint32_t color, int x, int y, txt_align_t alignment) +static void txt_render(txt_t *txt, til_fb_fragment_t *fragment, uint32_t color, int jx, int jy) { - int jx, jy, col, row; + int col, row; char *str; assert(txt); assert(fragment); - justify(alignment, x, y, txt->width, txt->height, &jx, &jy); - if (!overlaps(jx, jy, txt->width, txt->height, fragment->x, fragment->y, fragment->width, fragment->height)) return; - for (col = 0, row = 0, str = txt->str; *str; str++) { switch (*str) { case ' '...'~': @@ -201,3 +198,15 @@ void txt_render_fragment(txt_t *txt, til_fb_fragment_t *fragment, uint32_t color } } } + + +void txt_render_fragment_aligned(txt_t *txt, til_fb_fragment_t *fragment, uint32_t color, int x, int y, txt_align_t alignment) +{ + int jx, jy; + + assert(txt); + + justify(alignment, x, y, txt->width, txt->height, &jx, &jy); + + return txt_render(txt, fragment, color, jx, jy); +} diff --git a/src/libs/txt/txt.h b/src/libs/txt/txt.h index a924b25..9318546 100644 --- a/src/libs/txt/txt.h +++ b/src/libs/txt/txt.h @@ -28,6 +28,6 @@ typedef struct txt_align_t { txt_t * txt_new(const char *str); txt_t * txt_newf(const char *fmt, ...); txt_t * txt_free(txt_t *txt); -void txt_render_fragment(txt_t *txt, til_fb_fragment_t *fragment, uint32_t color, int x, int y, txt_align_t alignment); +void txt_render_fragment_aligned(txt_t *txt, til_fb_fragment_t *fragment, uint32_t color, int x, int y, txt_align_t alignment); #endif diff --git a/src/modules/asc/asc.c b/src/modules/asc/asc.c index bdb482e..d47ac6d 100644 --- a/src/modules/asc/asc.c +++ b/src/modules/asc/asc.c @@ -108,13 +108,13 @@ static void asc_render_fragment(til_module_context_t *context, til_stream_t *str til_fb_fragment_clear(fragment); - txt_render_fragment(ctxt->txt, fragment, 0xffffffff, - ctxt->vars.x * ((float)fragment->frame_width) * .5f + .5f * ((float)fragment->frame_width), - ctxt->vars.y * ((float)fragment->frame_height) * .5f + .5f * ((float)fragment->frame_height), - (txt_align_t){ - .horiz = s->halign, - .vert = s->valign - }); + txt_render_fragment_aligned(ctxt->txt, fragment, 0xffffffff, + ctxt->vars.x * ((float)fragment->frame_width) * .5f + .5f * ((float)fragment->frame_width), + ctxt->vars.y * ((float)fragment->frame_height) * .5f + .5f * ((float)fragment->frame_height), + (txt_align_t){ + .horiz = s->halign, + .vert = s->valign + }); } diff --git a/src/modules/rkt/rkt.c b/src/modules/rkt/rkt.c index 677e2b9..2e8e696 100644 --- a/src/modules/rkt/rkt.c +++ b/src/modules/rkt/rkt.c @@ -350,12 +350,12 @@ static void rkt_render_fragment(til_module_context_t *context, til_stream_t *str * as this is a diagnostic it's not so important. */ til_fb_fragment_clear(*fragment_ptr); - txt_render_fragment(msg, *fragment_ptr, 0xffffffff, - 0, 0, - (txt_align_t){ - .horiz = TXT_HALIGN_LEFT, - .vert = TXT_VALIGN_TOP, - }); + txt_render_fragment_aligned(msg, *fragment_ptr, 0xffffffff, + 0, 0, + (txt_align_t){ + .horiz = TXT_HALIGN_LEFT, + .vert = TXT_VALIGN_TOP, + }); txt_free(msg); } @@ -368,12 +368,12 @@ static void rkt_render_fragment(til_module_context_t *context, til_stream_t *str * will revisit the status text in the future. Not a huge priority since * none of this should be active in "production" playback mode. */ - txt_render_fragment(msg, *fragment_ptr, 0xffffffff, - 0, 0, - (txt_align_t){ - .horiz = TXT_HALIGN_LEFT, - .vert = TXT_VALIGN_TOP, - }); + txt_render_fragment_aligned(msg, *fragment_ptr, 0xffffffff, + 0, 0, + (txt_align_t){ + .horiz = TXT_HALIGN_LEFT, + .vert = TXT_VALIGN_TOP, + }); txt_free(msg); } diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index 0c2ab73..f0dd9dd 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -336,18 +336,18 @@ static int rtv_finish_frame(til_module_context_t *context, til_stream_t *stream, til_fb_fragment_t *fragment = *fragment_ptr; if (ctxt->caption) { - txt_render_fragment(ctxt->caption, fragment, 0x00000000, - 1, fragment->frame_height + 1, - (txt_align_t){ + txt_render_fragment_aligned(ctxt->caption, fragment, 0x00000000, + 1, fragment->frame_height + 1, + (txt_align_t){ + .horiz = TXT_HALIGN_LEFT, + .vert = TXT_VALIGN_BOTTOM + }); + txt_render_fragment_aligned(ctxt->caption, fragment, 0xffffffff, + 0, fragment->frame_height, + (txt_align_t){ .horiz = TXT_HALIGN_LEFT, .vert = TXT_VALIGN_BOTTOM - }); - txt_render_fragment(ctxt->caption, fragment, 0xffffffff, - 0, fragment->frame_height, - (txt_align_t){ - .horiz = TXT_HALIGN_LEFT, - .vert = TXT_VALIGN_BOTTOM - }); + }); } return 0; diff --git a/src/til_builtins.c b/src/til_builtins.c index aa6c159..e127261 100644 --- a/src/til_builtins.c +++ b/src/til_builtins.c @@ -143,12 +143,12 @@ static void _ref_render_fragment(til_module_context_t *context, til_stream_t *st txt_t *msg = txt_newf("%s: BAD PATH \"%s\"", context->setup->path, s->path); til_fb_fragment_clear(*fragment_ptr); - txt_render_fragment(msg, *fragment_ptr, 0xffffffff, - 0, 0, - (txt_align_t){ - .horiz = TXT_HALIGN_LEFT, - .vert = TXT_VALIGN_TOP, - }); + txt_render_fragment_aligned(msg, *fragment_ptr, 0xffffffff, + 0, 0, + (txt_align_t){ + .horiz = TXT_HALIGN_LEFT, + .vert = TXT_VALIGN_TOP, + }); txt_free(msg); /* TODO: maybe print all available contexts into the fragment? */ return; |