diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-07 14:20:39 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-07 14:20:39 (EDT) |
commit | d3783c83f614b3beded3d6a5c528005f480524e3 (patch) | |
tree | db34ff0fd328b53b6201aecc9fbc78a852189171 /src | |
parent | a194b1e9ed5d9049a9786ca91340fbae75aa08f6 (diff) | |
download | mazefight-d3783c83f614b3beded3d6a5c528005f480524e3.zip mazefight-d3783c83f614b3beded3d6a5c528005f480524e3.tar.gz mazefight-d3783c83f614b3beded3d6a5c528005f480524e3.tar.bz2 |
tk: Add submit callback to check, radio, and text
Diffstat (limited to 'src')
-rw-r--r-- | src/menu.c | 13 | ||||
-rw-r--r-- | src/tk.h | 12 | ||||
-rw-r--r-- | src/tk/check.c | 9 | ||||
-rw-r--r-- | src/tk/radio.c | 11 | ||||
-rw-r--r-- | src/tk/text.c | 7 |
5 files changed, 35 insertions, 17 deletions
@@ -128,28 +128,31 @@ _mf_menu_form(SDL_Renderer *renderer, TTF_Font *text_font, mftk_label_new(text_font, "Seed", text_color, renderer), MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T, mftk_text_new('0', '9', rand_max_len, seed_buf, - text_font, text_color, &_mf_menu_seed, menu), + text_font, text_color, &_mf_menu_seed, + &_mf_menu_play, menu), MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T, mftk_label_new(text_font, "Size", text_color, renderer), MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T, mftk_radio_new(MF_CHK_BTN_W, MF_CHK_BTN_P, &chkb_color, &chkm_color, MF_CHK_LBL_P, MF_CHK_ITM_P, - text_font, text_color, &_mf_menu_size, menu, - renderer, 0, 3, "15x15", "20x20", "30x30"), + text_font, text_color, &_mf_menu_size, + &_mf_menu_play, menu, renderer, 0, 3, "15x15", + "20x20", "30x30"), MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T, mftk_label_new(text_font, "Fog of war", text_color, renderer), MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T, mftk_check_new(MF_CHK_BTN_W, MF_CHK_BTN_P, &chkb_color, &chkm_color, SDL_TRUE, 0, NULL, NULL, NULL, - &_mf_menu_fow, menu, renderer), + &_mf_menu_fow, &_mf_menu_play, menu, renderer), MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T, mftk_label_new(text_font, "Reveal maze", text_color, renderer), MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T, mftk_check_new(MF_CHK_BTN_W, MF_CHK_BTN_P, &chkb_color, &chkm_color, SDL_FALSE, 0, NULL, NULL, NULL, - &_mf_menu_reveal, menu, renderer), + &_mf_menu_reveal, &_mf_menu_play, menu, + renderer), MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T, mftk_blank_new(), MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T, @@ -64,20 +64,22 @@ struct mftk_widget * mftk_check_new(int butn_width, int butn_padding, SDL_Color *butn_color, SDL_Color *mark_color, int state, int label_padding, TTF_Font *font, const char *text, SDL_Color *text_color, - int (*action)(void *, int), void *user_data, - SDL_Renderer *renderer); + int (*action)(void *, int), int (*submit)(void *), + void *user_data, SDL_Renderer *renderer); struct mftk_widget * mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color, SDL_Color *mark_color, int label_padding, int item_padding, TTF_Font *font, SDL_Color *text_color, - int (*action)(void *, int), void *user_data, - SDL_Renderer *renderer, int state, int options, ...); + int (*action)(void *, int), int (*submit)(void *), + void *user_data, SDL_Renderer *renderer, int state, int options, + ...); struct mftk_widget * mftk_text_new(char min_char, char max_char, int len, const char *val, TTF_Font *font, SDL_Color *color, - int (*action)(void *, const char *), void *user_data); + int (*action)(void *, const char *), int (*submit)(void *), + void *user_data); struct mftk_widget * mftk_blank_new(void); diff --git a/src/tk/check.c b/src/tk/check.c index 898a21e..b26f7d7 100644 --- a/src/tk/check.c +++ b/src/tk/check.c @@ -34,6 +34,7 @@ struct mftk_check { struct mftk_widget *label; int steals_focus; int (*action)(void *, int); + int (*submit)(void *); void *user_data; }; @@ -101,12 +102,13 @@ _mftk_check_key_event(struct mftk_widget *w, SDL_Event *e) case SDL_KEYDOWN: switch (e->key.keysym.sym) { case SDLK_SPACE: - case SDLK_RETURN: c->state = !c->state; if (c->action == NULL) { return 0; } return c->action(c->user_data,c->state); + case SDLK_RETURN: + return c->submit(c->user_data); default: break; } @@ -266,8 +268,8 @@ struct mftk_widget * mftk_check_new(int butn_width, int butn_padding, SDL_Color *butn_color, SDL_Color *mark_color, int state, int label_padding, TTF_Font *font, const char *text, SDL_Color *text_color, - int (*action)(void *, int), void *user_data, - SDL_Renderer *renderer) + int (*action)(void *, int), int (*submit)(void *), + void *user_data, SDL_Renderer *renderer) { struct mftk_widget *w; struct mftk_check *c; @@ -291,6 +293,7 @@ mftk_check_new(int butn_width, int butn_padding, SDL_Color *butn_color, c->label_padding = label_padding; c->steals_focus = SDL_TRUE; c->action = action; + c->submit = submit; c->user_data = user_data; return w; diff --git a/src/tk/radio.c b/src/tk/radio.c index 99e2b8b..79271ee 100644 --- a/src/tk/radio.c +++ b/src/tk/radio.c @@ -37,6 +37,7 @@ struct mftk_radio { int state; int options; int (*action)(void *, int); + int (*submit)(void *); void *user_data; }; @@ -117,6 +118,8 @@ _mftk_radio_key_event(struct mftk_widget *w, SDL_Event *e) return 0; } return r->action(r->user_data,r->state); + case SDLK_RETURN: + return r->submit(r->user_data); default: break; } @@ -168,8 +171,9 @@ struct mftk_widget * mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color, SDL_Color *mark_color, int label_padding, int item_padding, TTF_Font *font, SDL_Color *text_color, - int (*action)(void *, int), void *user_data, - SDL_Renderer *renderer, int state, int options, ...) + int (*action)(void *, int), int (*submit)(void *), + void *user_data, SDL_Renderer *renderer, int state, int options, + ...) { struct mftk_widget *w; struct mftk_radio *r; @@ -201,7 +205,7 @@ mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color, r->children[i] = mftk_check_new(butn_width, butn_padding, butn_color, mark_color, (i == state), label_padding, font, va_arg(ap, const char *), - text_color, &_mftk_radio_state_change, + text_color, &_mftk_radio_state_change, submit, &r->states[i], renderer); if (r->children[i] == NULL) { for (; i >= 0; --i) { @@ -234,6 +238,7 @@ mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color, r->state = state; r->options = options; r->action = action; + r->submit = submit; r->user_data = user_data; return w; diff --git a/src/tk/text.c b/src/tk/text.c index 4a8196d..027da71 100644 --- a/src/tk/text.c +++ b/src/tk/text.c @@ -42,6 +42,7 @@ struct mftk_text { SDL_Color *color; SDL_Texture *texture; int (*action)(void *, const char *); + int (*submit)(void *); void *user_data; }; @@ -123,6 +124,8 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e) return 0; } return t->action(t->user_data, t->val); + case SDLK_RETURN: + return t->submit(t->user_data); default: break; } @@ -287,7 +290,8 @@ _mftk_text_destroy(struct mftk_widget *w) struct mftk_widget * mftk_text_new(char min_char, char max_char, int len, const char *val, TTF_Font *font, SDL_Color *color, - int (*action)(void *, const char *), void *user_data) + int (*action)(void *, const char *), int (*submit)(void *), + void *user_data) { struct mftk_widget *w; struct mftk_text *t; @@ -306,6 +310,7 @@ mftk_text_new(char min_char, char max_char, int len, const char *val, t->color = color; t->texture = NULL; t->action = action; + t->submit = submit; t->user_data = user_data; t->val = calloc(len + 1, sizeof(*t->val)); |