diff options
Diffstat (limited to 'src/saffron_widget.c')
| -rw-r--r-- | src/saffron_widget.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/saffron_widget.c b/src/saffron_widget.c index 85b2013..932b7a5 100644 --- a/src/saffron_widget.c +++ b/src/saffron_widget.c @@ -1,8 +1,7 @@ #include <SDL3/SDL.h> +#include <stdio.h> #include <stdlib.h> -#include <saffron_widget.h> -#include <saffron_api.h> -#include <saffron_window.h> +#include <saffron.h> SaffronWidget* saffron_widget_new(void) { /* This function is a generic primitive for creating widgets. You wouldn't want to do this manually unless you're a lunatic. It is meant to be wrapped around by other functions that change the default parameters, for example, what sane person makes a widget 0x0x0x0? you LUNATIC! */ @@ -57,3 +56,26 @@ void saffron_widget_add_child(SaffronWidget *parent, SaffronWidget *child) { parent->child_count++; } +SaffronWidget* saffron_widget_hit_test(SaffronWidget* widget, int x, int y) { + if (!widget) { + printf("[saffron] hit test: widget is NULL!\n"); + return NULL; + } + if (x < widget->x || x > widget->x + widget->w) { + printf("[saffron] hit test: widget failed X bounds check!\n"); + return NULL; + } + if (y < widget->y || y > widget->y + widget->h) { + printf("[saffron] hit test: widget failed Y bounds check!\n"); + return NULL; + } + + // check children front to back + for (int i = widget->child_count - 1; i >= 0; i--) { + printf("[saffron] recursing to child (%i)\n", i); + SaffronWidget* hit = saffron_widget_hit_test(widget->children[i], x, y); + if (hit) return hit; + } + + return widget; +} |
