aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/saffron_window.c')
-rw-r--r--src/saffron_window.c19
1 files changed, 13 insertions, 6 deletions
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 <stdio.h>
#include <SDL3/SDL_events.h>
#include <stdlib.h>
#include <SDL3/SDL.h>
#include <SDL3_ttf/SDL_ttf.h>
-#include <saffron_api.h>
-#include <saffron_widget.h>
-#include <saffron_window.h>
+#include <saffron.h>
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);