summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-05-24 23:21:34 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-05-24 23:38:16 -0700
commit4e3dd029be7fa23be0276f029241e402b487b81e (patch)
treec14112a2457b8da5d3fbb3989424824bef8ace32
parent60353ac9dde8ec3178ef926afc9889551e77cc62 (diff)
modules/shapes: add scale setting
scale=1-.5 with a few other fractions in between Mostly added for the sake of rtv/compose where modules currently always go full-frame, which can be really annoying sometimes for shapes without any variety in the scale. When checkers starts filling cells using modules like shapes, it'll be interesting to see how this fares there since it'll probably be randomizing the settings too. At least floored at 50% should still produce something legible in /most/ of the checkers cell sizes. Definitely won't look like anything in the smaller end of the checkers sizes though... hrm.
-rw-r--r--src/modules/shapes/shapes.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/modules/shapes/shapes.c b/src/modules/shapes/shapes.c
index 68d194e..fd8dd40 100644
--- a/src/modules/shapes/shapes.c
+++ b/src/modules/shapes/shapes.c
@@ -65,6 +65,7 @@
#include "til_fb.h"
#define SHAPES_DEFAULT_TYPE SHAPES_TYPE_PINWHEEL
+#define SHAPES_DEFAULT_SCALE 1
#define SHAPES_DEFAULT_POINTS 5
#define SHAPES_DEFAULT_SPIN .1
@@ -78,6 +79,7 @@ typedef enum shapes_type_t {
typedef struct shapes_setup_t {
til_setup_t til_setup;
shapes_type_t type;
+ float scale;
unsigned n_points;
float spin;
} shapes_setup_t;
@@ -120,7 +122,7 @@ static void shapes_destroy_context(void *context)
static void shapes_render_fragment(void *context, unsigned ticks, unsigned cpu, til_fb_fragment_t *fragment)
{
shapes_context_t *ctxt = context;
- unsigned size = MIN(fragment->width, fragment->height);
+ unsigned size = MIN(fragment->width, fragment->height) * ctxt->setup.scale;
unsigned xoff = (fragment->width - size) >> 1;
unsigned yoff = (fragment->height - size) >> 1;
@@ -235,6 +237,7 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
const char *type;
const char *points;
const char *spin;
+ const char *scale;
const char *type_values[] = {
"circle",
"pinwheel",
@@ -281,6 +284,18 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
"1",
NULL
};
+ const char *scale_values[] = {
+ /* It's unclear to me if this even makes sense, but I can see some
+ * value in permitting something of a margin to exist around the shape.
+ * For that reason I'm not going smaller than 50%.
+ */
+ ".5",
+ ".66",
+ ".75",
+ ".9",
+ "1",
+ NULL
+ };
int r;
r = til_settings_get_and_describe_value(settings,
@@ -298,6 +313,21 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
if (r)
return r;
+ r = til_settings_get_and_describe_value(settings,
+ &(til_setting_desc_t){
+ .name = "Scaling factor",
+ .key = "scale",
+ .regex = "(1|0?\\.[0-9]{1,2})",
+ .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_SCALE),
+ .values = scale_values,
+ .annotations = NULL
+ },
+ &scale,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
+
if (!strcasecmp(type, "star") || !strcasecmp(type, "pinwheel")) {
r = til_settings_get_and_describe_value(settings,
&(til_setting_desc_t){
@@ -318,7 +348,7 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
&(til_setting_desc_t){
.name = "Spin factor",
.key = "spin",
- .regex = "-?(0|1|0\\.[0-9]{1,2})", /* Derived from pixbounce, I'm sure when regexes start getting actually applied we're going to have to revisit all of these and fix them with plenty of lols. */
+ .regex = "-?(0|1|0?\\.[0-9]{1,2})", /* Derived from pixbounce, I'm sure when regexes start getting actually applied we're going to have to revisit all of these and fix them with plenty of lols. */
.preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_SPIN),
.values = spin_values,
.annotations = NULL
@@ -351,6 +381,8 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
return -EINVAL;
}
+ sscanf(scale, "%f", &setup->scale); /* TODO: -EINVAL parse errors */
+
if (setup->type == SHAPES_TYPE_STAR || setup->type == SHAPES_TYPE_PINWHEEL) {
sscanf(points, "%u", &setup->n_points); /* TODO: -EINVAL parse errors */
sscanf(spin, "%f", &setup->spin); /* TODO: -EINVAL parse errors */
© All Rights Reserved