summaryrefslogtreecommitdiff
path: root/src/modules/checkers/checkers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/checkers/checkers.c')
-rw-r--r--src/modules/checkers/checkers.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/modules/checkers/checkers.c b/src/modules/checkers/checkers.c
index c4e02c1..841aadd 100644
--- a/src/modules/checkers/checkers.c
+++ b/src/modules/checkers/checkers.c
@@ -26,6 +26,8 @@
#define CHECKERS_DEFAULT_PATTERN CHECKERS_PATTERN_CHECKERED
#define CHECKERS_DEFAULT_DYNAMICS CHECKERS_DYNAMICS_ODD
#define CHECKERS_DEFAULT_DYNAMICS_RATE 1.0
+#define CHECKERS_DEFAULT_SAMPLED 0
+#define CHECKERS_DEFAULT_COLOR 0xffffffff
typedef enum checkers_pattern_t {
@@ -47,6 +49,8 @@ typedef struct checkers_setup_t {
checkers_pattern_t pattern;
checkers_dynamics_t dynamics;
float rate;
+ uint32_t color;
+ unsigned sampled:1;
} checkers_setup_t;
typedef struct checkers_context_t {
@@ -60,6 +64,8 @@ static checkers_setup_t checkers_default_setup = {
.pattern = CHECKERS_DEFAULT_PATTERN,
.dynamics = CHECKERS_DEFAULT_DYNAMICS,
.rate = CHECKERS_DEFAULT_DYNAMICS_RATE,
+ .sampled = CHECKERS_DEFAULT_SAMPLED,
+ .color = CHECKERS_DEFAULT_COLOR,
};
@@ -165,8 +171,14 @@ static void checkers_render_fragment(void *context, unsigned ticks, unsigned cpu
if (!state)
til_fb_fragment_clear(fragment);
- else
- til_fb_fragment_fill(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, 0xffffffff);
+ else {
+ uint32_t color = ctxt->setup.color;
+
+ if (ctxt->setup.sampled && fragment->cleared)
+ color = til_fb_fragment_get_pixel_unchecked(fragment, fragment->x + (fragment->width >> 1), fragment->y + (fragment->height >> 1));
+
+ til_fb_fragment_fill(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, color);
+ }
}
@@ -176,6 +188,7 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se
const char *pattern;
const char *dynamics;
const char *dynamics_rate;
+ const char *sampled;
const char *size_values[] = {
"4",
"8",
@@ -209,6 +222,11 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se
".0001",
NULL
};
+ const char *bool_values[] = {
+ "off",
+ "on",
+ NULL
+ };
int r;
r = til_settings_get_and_describe_value(settings,
@@ -270,6 +288,20 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se
return r;
}
+ r = til_settings_get_and_describe_value(settings,
+ &(til_setting_desc_t){
+ .name = "Sample checker colors when overlayed",
+ .key = "sampled",
+ .preferred = bool_values[CHECKERS_DEFAULT_SAMPLED],
+ .values = bool_values,
+ .annotations = NULL
+ },
+ &sampled,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
+
if (res_setup) {
checkers_setup_t *setup;
@@ -306,6 +338,21 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se
if (setup->dynamics != CHECKERS_DYNAMICS_ODD && setup->dynamics != CHECKERS_DYNAMICS_EVEN)
sscanf(dynamics_rate, "%f", &setup->rate);
+ /* FIXME TODO: I wonder if sampled should be more like a color mode {color, randomized, sampled, textured}
+ * with the til_fb_fragment_* putters adding a flag for allowing texturing.
+ * the problem here is that if a texture isn't made available on the fb, we wouldn't still be doing things
+ * like sampling or randomizing the colors. They should both be occurring, maybe there needs to be a separate
+ * field for controlling wether texturing is permitted, not part of color mode. like texturing=on,off
+ */
+ if (!strcasecmp(sampled, "on"))
+ setup->sampled = 1;
+
+ /* XXX FIXME TODO: color setting, parse web-style #rrggbb? */
+ /* XXX FIXME TODO: color setting, parse web-style #rrggbb? */
+ /* XXX FIXME TODO: color setting, parse web-style #rrggbb? */
+ /* XXX FIXME TODO: color setting, parse web-style #rrggbb? */
+ setup->color = CHECKERS_DEFAULT_COLOR;
+
*res_setup = &setup->til_setup;
}
© All Rights Reserved