From 0cebba8c7013201ec685b0ca35212294d3d009f3 Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Thu, 9 Apr 2026 14:08:23 +1200 Subject: Click event routing IT WORKS IT WORKS IT WORKS YESSSSSSSSSSSSSSSSS --- src/saffron_window.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/saffron_window.c') diff --git a/src/saffron_window.c b/src/saffron_window.c index 4bdae76..a25fa0e 100644 --- a/src/saffron_window.c +++ b/src/saffron_window.c @@ -1,17 +1,16 @@ +#include #include #include #include #include -#include -#include -#include +#include SaffronWindow* saffron_window_new(const char* title, int w, int h) { SaffronWindow* window = malloc(sizeof(SaffronWindow)); window->root = saffron_widget_new(); // frick, need to implement this. window->title = title; - window->w = w; - window->h = h; + window->w = window->root->w = w; + window->h = window->root->h = h; window->sdl_window = SDL_CreateWindow(title, w, h, SDL_WINDOW_RESIZABLE); window->renderer = SDL_CreateRenderer(window->sdl_window, NULL); return window; @@ -35,7 +34,15 @@ void saffron_window_main(SaffronWindow *window) { if (event.type == SDL_EVENT_QUIT) { running = false; } - // TODO: send events to widgets and stuff + if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN) { + printf("[saffron] mouse down!\n"); + if (event.button.button == SDL_BUTTON_LEFT) { + printf("[saffron] left click at %f, %f!\n", event.button.x, event.button.y); + printf("[saffron] calling hit test at coordinates\n"); + SaffronWidget* hit = saffron_widget_hit_test(window->root, (int)event.button.x, (int)event.button.y); + if (hit && hit->on_click) hit->on_click(hit); + } + } } SDL_SetRenderDrawColor(window->renderer, 0, 0, 0, 255); -- cgit v1.2.3