From ecb780f1478c00d28f81c7141de9e0f2c8971e9b Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 22 Jan 2023 16:02:44 -0800 Subject: modules/blinds: add taps for T,step,count Part of me wants to give the blinds arbitrary angle instead of the vert/horiz options. But part of the beauty of blinds is the jaggy-free aliasing-free sharp edges by virtue of always being orthonormal using whole pixels. Maybe in the future there could be a orientation setting where you pick horiz/vert/angular. Then only when angular does it get a theta tap and use angled blinds with anti-aliased imperfect edges... --- src/modules/blinds/blinds.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/modules/blinds/blinds.c b/src/modules/blinds/blinds.c index a2cf181..f8c2597 100644 --- a/src/modules/blinds/blinds.c +++ b/src/modules/blinds/blinds.c @@ -7,6 +7,8 @@ #include "til.h" #include "til_fb.h" #include "til_module_context.h" +#include "til_stream.h" +#include "til_tap.h" /* Copyright (C) 2017-2022 Vito Caputo */ @@ -27,6 +29,15 @@ typedef struct blinds_setup_t { typedef struct blinds_context_t { til_module_context_t til_module_context; + struct { + til_tap_t t, step, count; + } taps; + + struct { + float t, step, count; + } vars; + + float *t, *step, *count; blinds_setup_t setup; } blinds_context_t; @@ -48,6 +59,10 @@ static til_module_context_t * blinds_create_context(const til_module_t *module, if (!ctxt) return NULL; + ctxt->taps.t = til_tap_init_float(ctxt, &ctxt->t, 1, &ctxt->vars.t, "T"); + ctxt->taps.step = til_tap_init_float(ctxt, &ctxt->step, 1, &ctxt->vars.step, "step"); + ctxt->taps.count = til_tap_init_float(ctxt, &ctxt->count, 1, &ctxt->vars.count, "count"); + ctxt->setup = *(blinds_setup_t *)setup; return &ctxt->til_module_context; @@ -88,18 +103,27 @@ static void blinds_render_fragment(til_module_context_t *context, til_stream_t * blinds_context_t *ctxt = (blinds_context_t *)context; til_fb_fragment_t *fragment = *fragment_ptr; - float r = til_ticks_to_rads(ticks); unsigned blind; + float t; + + if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.t)) + *ctxt->t = til_ticks_to_rads(ticks); + + if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.step)) + *ctxt->step = .1f; + + if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.count)) + *ctxt->count = ctxt->setup.count; til_fb_fragment_clear(fragment); - for (blind = 0; blind < ctxt->setup.count; blind++, r += .1) { + for (t = *ctxt->t, blind = 0; blind < (unsigned)*ctxt->count; blind++, t += *ctxt->step) { switch (ctxt->setup.orientation) { case BLINDS_ORIENTATION_HORIZONTAL: - draw_blind_horizontal(fragment, blind, ctxt->setup.count, 1.f - fabsf(cosf(r))); + draw_blind_horizontal(fragment, blind, ctxt->setup.count, 1.f - fabsf(cosf(t))); break; case BLINDS_ORIENTATION_VERTICAL: - draw_blind_vertical(fragment, blind, ctxt->setup.count, 1.f - fabsf(cosf(r))); + draw_blind_vertical(fragment, blind, ctxt->setup.count, 1.f - fabsf(cosf(t))); break; } } -- cgit v1.2.3