summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-06 09:14:08 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-06 09:17:55 (EDT)
commit4693d1d70855b97d57cdbe92552ba304362fb453 (patch)
treeada3fa724286cd6643a5ec958632082a0f413366
parentff2bc6c6cbeae860835198983a5368ffa120dd65 (diff)
downloadmazefight-4693d1d70855b97d57cdbe92552ba304362fb453.zip
mazefight-4693d1d70855b97d57cdbe92552ba304362fb453.tar.gz
mazefight-4693d1d70855b97d57cdbe92552ba304362fb453.tar.bz2
tk: Implement focusing by mouse
-rw-r--r--src/tk/button.c1
-rw-r--r--src/tk/check.c1
-rw-r--r--src/tk/radio.c10
-rw-r--r--src/tk/text.c16
-rw-r--r--src/tk/widget.h3
-rw-r--r--src/tk/window.c8
6 files changed, 37 insertions, 2 deletions
diff --git a/src/tk/button.c b/src/tk/button.c
index a236dd4..0b5e874 100644
--- a/src/tk/button.c
+++ b/src/tk/button.c
@@ -51,6 +51,7 @@ _mftk_button_event(struct mftk_widget *w, SDL_Event *e,
switch (e->type) {
case SDL_MOUSEBUTTONUP:
if (e->button.button == SDL_BUTTON_LEFT) {
+ mftk_window_focus(w->window, w);
if (b->action == NULL) {
return 0;
}
diff --git a/src/tk/check.c b/src/tk/check.c
index a2eadd0..fbd3b23 100644
--- a/src/tk/check.c
+++ b/src/tk/check.c
@@ -81,6 +81,7 @@ _mftk_check_event(struct mftk_widget *w, SDL_Event *e,
switch (e->type) {
case SDL_MOUSEBUTTONUP:
if (e->button.button == SDL_BUTTON_LEFT) {
+ mftk_window_focus(w->window, w);
c->state = !c->state;
if (c->action == NULL) {
return 0;
diff --git a/src/tk/radio.c b/src/tk/radio.c
index 11acbae..6f767af 100644
--- a/src/tk/radio.c
+++ b/src/tk/radio.c
@@ -75,6 +75,16 @@ _mftk_radio_event(struct mftk_widget *w, SDL_Event *e, int x, int y)
{
struct mftk_radio *r = (struct mftk_radio *) w;
+ switch (e->type) {
+ case SDL_MOUSEBUTTONUP:
+ if (e->button.button == SDL_BUTTON_LEFT) {
+ mftk_window_focus(w->window, w);
+ }
+ break;
+ default:
+ break;
+ }
+
return mftk_widget_event(r->grid, e, x, y);
}
diff --git a/src/tk/text.c b/src/tk/text.c
index 052beeb..88b8e37 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -55,8 +55,20 @@ _mftk_text_event(struct mftk_widget *w, SDL_Event *e,
{
struct mftk_text *t = (struct mftk_text *) w;
- /* TODO */
- t->texture = NULL;
+ switch (e->type) {
+ case SDL_KEYDOWN:
+ /* TODO */
+ t->texture = NULL;
+ break;
+ case SDL_MOUSEBUTTONUP:
+ if (e->button.button == SDL_BUTTON_LEFT) {
+ mftk_window_focus(w->window, w);
+ }
+ break;
+ default:
+ break;
+ }
+
return 0;
}
diff --git a/src/tk/widget.h b/src/tk/widget.h
index 83abe0b..27400c4 100644
--- a/src/tk/widget.h
+++ b/src/tk/widget.h
@@ -26,6 +26,9 @@
void
mftk_window_index(struct mftk_window *win, struct mftk_widget *wid);
+void
+mftk_window_focus(struct mftk_window *win, struct mftk_widget *wid);
+
enum mftk_widget_role {
MFTK_WIDGET_ROLE_NONE,
MFTK_WIDGET_ROLE_FOCUSABLE,
diff --git a/src/tk/window.c b/src/tk/window.c
index 61c017f..53fbb41 100644
--- a/src/tk/window.c
+++ b/src/tk/window.c
@@ -100,6 +100,14 @@ mftk_window_event(struct mftk_window *w, SDL_Event *e)
return 0;
}
+void
+mftk_window_focus(struct mftk_window *win, struct mftk_widget *wid)
+{
+ win->focus->focused = SDL_FALSE;
+ win->focus = wid;
+ win->focus->focused = SDL_TRUE;
+}
+
int
mftk_window_render(struct mftk_window *w, SDL_Renderer *renderer)
{