diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tk/radio.c | 40 |
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; |