summaryrefslogtreecommitdiff
path: root/src/modules/rtv/rtv.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-11-16 19:48:52 -0800
committerVito Caputo <vcaputo@pengaru.com>2019-11-16 20:06:42 -0800
commit79fd2e75eb449b2cbd1950e4863075b78608a247 (patch)
tree22bf1261e81103e94a958fc3bae1700d1a013978 /src/modules/rtv/rtv.c
parenta6f43bc59fc1292060081d5a4837f5679e1b186f (diff)
modules/rtv: add captions
The idea is to have captions similar to how MTV did back in the 80s. It'd be nice to make the text resolution independent, but this is a good first stab for an afternoon of tooling around.
Diffstat (limited to 'src/modules/rtv/rtv.c')
-rw-r--r--src/modules/rtv/rtv.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c
index 8848e82..215f5d2 100644
--- a/src/modules/rtv/rtv.c
+++ b/src/modules/rtv/rtv.c
@@ -3,6 +3,7 @@
#include "fb.h"
#include "rototiller.h"
+#include "txt/txt.h"
#include "util.h"
/* Copyright (C) 2019 - Vito Caputo <vcaputo@pengaru.com> */
@@ -24,16 +25,18 @@
* same thing over and over.
*/
-#define RTV_SNOW_DURATION_SECS 1
-#define RTV_DURATION_SECS 15
+#define RTV_SNOW_DURATION_SECS 1
+#define RTV_DURATION_SECS 15
+#define RTV_CAPTION_DURATION_SECS 5
typedef struct rtv_context_t {
const rototiller_module_t **modules;
size_t n_modules;
- time_t next_switch;
+ time_t next_switch, next_hide_caption;
const rototiller_module_t *module;
void *module_ctxt;
+ txt_t *caption;
const rototiller_module_t *snow_module;
} rtv_context_t;
@@ -69,6 +72,7 @@ static void setup_next_module(rtv_context_t *ctxt)
ctxt->module->destroy_context(ctxt->module_ctxt);
ctxt->module_ctxt = NULL;
+ ctxt->caption = txt_free(ctxt->caption);
}
if (ctxt->module != ctxt->snow_module) {
@@ -82,7 +86,15 @@ static void setup_next_module(rtv_context_t *ctxt)
ctxt->modules[i] == ctxt->snow_module);
ctxt->module = ctxt->modules[i];
+
+ ctxt->caption = txt_newf("Title: %s\nAuthor: %s\nDescription: %s\nLicense: %s",
+ ctxt->module->name,
+ ctxt->module->author,
+ ctxt->module->description,
+ ctxt->module->license);
+
ctxt->next_switch = time(NULL) + RTV_DURATION_SECS;
+ ctxt->next_hide_caption = time(NULL) + RTV_CAPTION_DURATION_SECS;
}
if (ctxt->module->create_context)
@@ -111,15 +123,35 @@ static void rtv_destroy_context(void *context)
static void rtv_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter)
{
rtv_context_t *ctxt = context;
+ time_t now = time(NULL);
- if (time(NULL) >= ctxt->next_switch)
+ if (now >= ctxt->next_switch)
setup_next_module(ctxt);
+ if (now >= ctxt->next_hide_caption)
+ ctxt->caption = txt_free(ctxt->caption);
+
rototiller_module_render(ctxt->module, ctxt->module_ctxt, fragment);
}
static void rtv_finish_frame(void *context, fb_fragment_t *fragment)
{
- /* TODO: this is stubbed here for drawing the caption overlay */
+ rtv_context_t *ctxt = context;
+
+ if (!ctxt->caption)
+ return;
+
+ txt_render_fragment(ctxt->caption, fragment, 0x00000000,
+ 1, fragment->frame_height + 1,
+ (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
+ });
}
© All Rights Reserved