summaryrefslogtreecommitdiffstats
path: root/src/tk
diff options
context:
space:
mode:
Diffstat (limited to 'src/tk')
-rw-r--r--src/tk/button.c4
-rw-r--r--src/tk/grid.c25
-rw-r--r--src/tk/label.c4
-rw-r--r--src/tk/widget.c4
-rw-r--r--src/tk/widget.h2
5 files changed, 32 insertions, 7 deletions
diff --git a/src/tk/button.c b/src/tk/button.c
index 0db91a9..ffac9de 100644
--- a/src/tk/button.c
+++ b/src/tk/button.c
@@ -42,7 +42,9 @@ _mftk_button_layout(struct mftk_widget *w)
}
static int
-_mftk_button_event(struct mftk_widget *w, SDL_Event *e)
+_mftk_button_event(struct mftk_widget *w, SDL_Event *e,
+ int x __attribute__((__unused__)),
+ int y __attribute__((__unused__)))
{
struct mftk_button *b = (struct mftk_button *) w;
diff --git a/src/tk/grid.c b/src/tk/grid.c
index 5994929..67fa677 100644
--- a/src/tk/grid.c
+++ b/src/tk/grid.c
@@ -79,12 +79,33 @@ _mftk_grid_layout(struct mftk_widget *w)
}
static int
-_mftk_grid_event(struct mftk_widget *w, SDL_Event *e)
+_mftk_grid_event(struct mftk_widget *w, SDL_Event *e, int x, int y)
{
- struct mftk_grid *g = (struct mftk_grid *) w;
+ struct mftk_grid *g = (struct mftk_grid *) w;
+ SDL_Point p;
+ SDL_Rect rect;
+ int r;
+ int c;
+ struct mftk_widget *child;
switch (e->type) {
case SDL_MOUSEBUTTONUP:
+ p.x = e->button.x;
+ p.y = e->button.y;
+ for (r = 0; r < g->rows; ++r) {
+ for (c = 0; c < g->cols; ++c) {
+ child = g->children[r * g->cols + c];
+ rect.x = x + g->children_x[c];
+ rect.y = y + g->children_y[r];
+ rect.w = child->w;
+ rect.h = child->h;
+ if (SDL_PointInRect(&p, &rect)
+ == SDL_TRUE) {
+ return mftk_widget_event(child,
+ e, x, y);
+ }
+ }
+ }
break;
default:
break;
diff --git a/src/tk/label.c b/src/tk/label.c
index ec4400a..1fcfd84 100644
--- a/src/tk/label.c
+++ b/src/tk/label.c
@@ -37,7 +37,9 @@ _mftk_label_layout(struct mftk_widget *w __attribute__((__unused__)))
static int
_mftk_label_event(struct mftk_widget *w __attribute__((__unused__)),
- SDL_Event *e __attribute__((__unused__)))
+ SDL_Event *e __attribute__((__unused__)),
+ int x __attribute__((__unused__)),
+ int y __attribute__((__unused__)))
{
/* No events */
return 0;
diff --git a/src/tk/widget.c b/src/tk/widget.c
index 1bf9407..ea4835e 100644
--- a/src/tk/widget.c
+++ b/src/tk/widget.c
@@ -61,9 +61,9 @@ mftk_widget_layout(struct mftk_widget *w)
}
int
-mftk_widget_event(struct mftk_widget *w, SDL_Event *e)
+mftk_widget_event(struct mftk_widget *w, SDL_Event *e, int x, int y)
{
- return w->event(w, e);
+ return w->event(w, e, x, y);
}
int
diff --git a/src/tk/widget.h b/src/tk/widget.h
index ae81553..4966749 100644
--- a/src/tk/widget.h
+++ b/src/tk/widget.h
@@ -28,7 +28,7 @@ struct mftk_widget {
int vis;
int can_focus;
void (*layout)(struct mftk_widget *);
- int (*event)(struct mftk_widget *, SDL_Event *);
+ int (*event)(struct mftk_widget *, SDL_Event *, int, int);
int (*render)(struct mftk_widget *, SDL_Renderer *, int, int);
void (*destroy)(struct mftk_widget *);
};