summaryrefslogtreecommitdiffstats
path: root/src/tk
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-06 16:30:44 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-06 16:30:44 (EDT)
commit94fde9dad4d2c9ef179289ef52d2a629d9d3977a (patch)
tree161a2a4487973066e86dd1380e2838ee40d7c14f /src/tk
parentbd2826284ce3a4ecde2493ad53a79473352e5933 (diff)
downloadmazefight-94fde9dad4d2c9ef179289ef52d2a629d9d3977a.zip
mazefight-94fde9dad4d2c9ef179289ef52d2a629d9d3977a.tar.gz
mazefight-94fde9dad4d2c9ef179289ef52d2a629d9d3977a.tar.bz2
tk: Pass key events
Diffstat (limited to 'src/tk')
-rw-r--r--src/tk/button.c10
-rw-r--r--src/tk/check.c10
-rw-r--r--src/tk/radio.c10
-rw-r--r--src/tk/text.c17
-rw-r--r--src/tk/widget.c6
-rw-r--r--src/tk/widget.h5
-rw-r--r--src/tk/window.c3
7 files changed, 57 insertions, 4 deletions
diff --git a/src/tk/button.c b/src/tk/button.c
index 5638fb0..4b25d17 100644
--- a/src/tk/button.c
+++ b/src/tk/button.c
@@ -42,6 +42,16 @@ _mftk_button_layout(struct mftk_widget *w)
}
static int
+_mftk_button_key_event(struct mftk_widget *w, SDL_Event *e)
+{
+ struct mftk_button *b = (struct mftk_button *) w;
+
+ /* TODO */
+
+ return 0;
+}
+
+static int
_mftk_button_mouse_event(struct mftk_widget *w, SDL_Event *e,
int x __attribute__((__unused__)),
int y __attribute__((__unused__)))
diff --git a/src/tk/check.c b/src/tk/check.c
index 1df3b98..407d969 100644
--- a/src/tk/check.c
+++ b/src/tk/check.c
@@ -81,6 +81,16 @@ _mftk_check_layout(struct mftk_widget *w)
}
static int
+_mftk_check_key_event(struct mftk_widget *w, SDL_Event *e)
+{
+ struct mftk_check *c = (struct mftk_check *) w;
+
+ /* TODO */
+
+ return 0;
+}
+
+static int
_mftk_check_mouse_event(struct mftk_widget *w, SDL_Event *e,
int x __attribute__((__unused__)),
int y __attribute__((__unused__)))
diff --git a/src/tk/radio.c b/src/tk/radio.c
index 7e4719c..f20b902 100644
--- a/src/tk/radio.c
+++ b/src/tk/radio.c
@@ -71,6 +71,16 @@ _mftk_radio_layout(struct mftk_widget *w)
}
static int
+_mftk_radio_key_event(struct mftk_widget *w, SDL_Event *e, int x, int y)
+{
+ struct mftk_radio *r = (struct mftk_radio *) w;
+
+ /* TODO */
+
+ return 0;
+}
+
+static int
_mftk_radio_mouse_event(struct mftk_widget *w, SDL_Event *e, int x, int y)
{
struct mftk_radio *r = (struct mftk_radio *) w;
diff --git a/src/tk/text.c b/src/tk/text.c
index 49ab13c..95bd03b 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -49,9 +49,7 @@ _mftk_text_layout(struct mftk_widget *w __attribute__((__unused__)))
}
static int
-_mftk_text_mouse_event(struct mftk_widget *w, SDL_Event *e,
- int x __attribute__((__unused__)),
- int y __attribute__((__unused__)))
+_mftk_text_key_event(struct mftk_widget *w, SDL_Event *e)
{
struct mftk_text *t = (struct mftk_text *) w;
@@ -60,6 +58,19 @@ _mftk_text_mouse_event(struct mftk_widget *w, SDL_Event *e,
/* TODO */
t->texture = NULL;
break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static int
+_mftk_text_mouse_event(struct mftk_widget *w, SDL_Event *e,
+ int x __attribute__((__unused__)),
+ int y __attribute__((__unused__)))
+{
+ switch (e->type) {
case SDL_MOUSEBUTTONUP:
if (e->button.button == SDL_BUTTON_LEFT) {
mftk_window_focus(w->window, w);
diff --git a/src/tk/widget.c b/src/tk/widget.c
index f124867..5cd5878 100644
--- a/src/tk/widget.c
+++ b/src/tk/widget.c
@@ -72,6 +72,12 @@ mftk_widget_index(struct mftk_widget *w, struct mftk_window *win)
}
int
+mftk_widget_key_event(struct mftk_widget *w, SDL_Event *e)
+{
+ return w->key_event(w, e);
+}
+
+int
mftk_widget_mouse_event(struct mftk_widget *w, SDL_Event *e, int x, int y)
{
return w->mouse_event(w, e, x, y);
diff --git a/src/tk/widget.h b/src/tk/widget.h
index 9064252..a5634a5 100644
--- a/src/tk/widget.h
+++ b/src/tk/widget.h
@@ -43,6 +43,7 @@ struct mftk_widget {
void (*layout)(struct mftk_widget *);
void (*index)(struct mftk_widget *,
struct mftk_window *);
+ int (*key_event)(struct mftk_widget *, SDL_Event *);
int (*mouse_event)(struct mftk_widget *, SDL_Event *,
int, int);
int (*render)(struct mftk_widget *, SDL_Renderer *,
@@ -78,6 +79,7 @@ mftk_widget_new(size_t size);
return NULL; \
}; \
w->layout = &_mftk_##name##_layout; \
+ w->key_event = &_mftk_##name##_key_event; \
w->mouse_event = &_mftk_##name##_mouse_event; \
w->render = &_mftk_##name##_render; \
w->destroy = &_mftk_##name##_destroy; \
@@ -116,6 +118,9 @@ int
mftk_widget_mouse_event(struct mftk_widget *w, SDL_Event *e, int x, int y);
int
+mftk_widget_key_event(struct mftk_widget *w, SDL_Event *e);
+
+int
mftk_widget_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y);
void
diff --git a/src/tk/window.c b/src/tk/window.c
index d4d7cb3..64040bf 100644
--- a/src/tk/window.c
+++ b/src/tk/window.c
@@ -88,7 +88,8 @@ mftk_window_event(struct mftk_window *w, SDL_Event *e)
w->focus->focused = SDL_TRUE;
break;
default:
- break;
+ return mftk_widget_key_event(w->focus,
+ e);
}
break;
case SDL_MOUSEBUTTONUP: