summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-06 16:59:35 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-06 16:59:35 (EDT)
commitd6fdd303045ed9e0439005039e3c61f51d065931 (patch)
treed0a5349f91ea6b404d94695975eab66e6c1e1abb /src
parentc81ec0dd9447a4388b9d250d6db2ff98d9689af6 (diff)
downloadmazefight-d6fdd303045ed9e0439005039e3c61f51d065931.zip
mazefight-d6fdd303045ed9e0439005039e3c61f51d065931.tar.gz
mazefight-d6fdd303045ed9e0439005039e3c61f51d065931.tar.bz2
tk: Add radio key handling
Diffstat (limited to 'src')
-rw-r--r--src/tk/radio.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/tk/radio.c b/src/tk/radio.c
index f20b902..d3001c3 100644
--- a/src/tk/radio.c
+++ b/src/tk/radio.c
@@ -35,6 +35,7 @@ struct mftk_radio {
struct mftk_widget *grid;
struct _mftk_radio_state *states;
int state;
+ int options;
int (*action)(void *, int);
void *user_data;
};
@@ -71,11 +72,45 @@ _mftk_radio_layout(struct mftk_widget *w)
}
static int
-_mftk_radio_key_event(struct mftk_widget *w, SDL_Event *e, int x, int y)
+_mftk_radio_key_event(struct mftk_widget *w, SDL_Event *e)
{
struct mftk_radio *r = (struct mftk_radio *) w;
- /* TODO */
+ switch (e->type) {
+ case SDL_KEYDOWN:
+ switch (e->key.keysym.sym) {
+ case SDLK_UP:
+ mftk_check_set_state(r->children[
+ r->state], SDL_FALSE);
+ --r->state;
+ if (r->state < 0) {
+ r->state = r->options - 1;
+ }
+ mftk_check_set_state(r->children[
+ r->state], SDL_TRUE);
+ if (r->action == NULL) {
+ return 0;
+ }
+ return r->action(r->user_data,r->state);
+ case SDLK_DOWN:
+ mftk_check_set_state(r->children[
+ r->state], SDL_FALSE);
+ ++r->state;
+ if (r->state >= r->options) {
+ r->state = 0;
+ }
+ mftk_check_set_state(r->children[
+ r->state], SDL_TRUE);
+ if (r->action == NULL) {
+ return 0;
+ }
+ return r->action(r->user_data,r->state);
+ default:
+ break;
+ }
+ default:
+ break;
+ }
return 0;
}
@@ -185,6 +220,7 @@ mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color,
}
r->state = state;
+ r->options = options;
r->action = action;
r->user_data = user_data;