diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 2 | ||||
-rw-r--r-- | src/menu.c | 14 | ||||
-rw-r--r-- | src/tk.h | 1 | ||||
-rw-r--r-- | src/tk/text.c | 10 |
4 files changed, 20 insertions, 7 deletions
@@ -54,7 +54,7 @@ _mf_game_form(SDL_Renderer *renderer, TTF_Font *text_font, struct _mf_game *game) { game->timer = mftk_text_new('\0', '\0', 5, "00:00", text_font, - text_color, SDL_FALSE, NULL, NULL, NULL); + text_color, SDL_FALSE, NULL, NULL, NULL, NULL); return mftk_grid_new(2, 1, MF_ROW_M, MF_COL_M, game->timer, MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T, @@ -50,6 +50,12 @@ struct _mf_menu { }; static int +_mf_menu_isdigit(void *user_data __attribute__((__unused__)), char c) +{ + return isdigit(c); +} + +static int _mf_menu_seed(void *user_data, const char *seed) { struct _mf_menu *menu = (struct _mf_menu *) user_data; @@ -169,11 +175,11 @@ _mf_menu_form(SDL_Renderer *renderer, TTF_Font *text_font, } menu->seed_text = mftk_text_new('0', '9', rand_max_len, menu->seed_buf, - text_font, text_color, SDL_TRUE, &_mf_menu_seed, - &_mf_menu_play, menu); + text_font, text_color, SDL_TRUE, &_mf_menu_isdigit, + &_mf_menu_seed, &_mf_menu_play, menu); menu->enemies_text = mftk_text_new('0', '9', 2, menu->enemies_buf, - text_font, text_color, SDL_TRUE, &_mf_menu_enemies, - &_mf_menu_play, menu); + text_font, text_color, SDL_TRUE, &_mf_menu_isdigit, + &_mf_menu_enemies, &_mf_menu_play, menu); grid = mftk_grid_new(6, 2, MF_ROW_M, MF_COL_M, mftk_label_new(text_font, "Seed", text_color, renderer), MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T, @@ -78,6 +78,7 @@ mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color, struct mftk_widget * mftk_text_new(char min_char, char max_char, int len, const char *val, TTF_Font *font, SDL_Color *color, int editable, + int (*allowed)(void *, char), int (*action)(void *, const char *), int (*submit)(void *), void *user_data); diff --git a/src/tk/text.c b/src/tk/text.c index ccfaf7f..f509c14 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 editable; + int (*allowed)(void *, char); int (*action)(void *, const char *); int (*submit)(void *); void *user_data; @@ -144,8 +145,11 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e) for (i = 0, j = 0; i < newlen && e->text.text[j] != '\0'; ++j) { - if (e->text.text[j] < t->min_char) continue; - if (e->text.text[j] > t->max_char) continue; + if (t->allowed != NULL && + t->allowed(t->user_data, + e->text.text[j]) <= 0) { + continue; + } t->val[t->cur + i] = e->text.text[j]; ++i; } @@ -299,6 +303,7 @@ _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 editable, + int (*allowed)(void *, char), int (*action)(void *, const char *), int (*submit)(void *), void *user_data) { @@ -322,6 +327,7 @@ mftk_text_new(char min_char, char max_char, int len, const char *val, t->color = color; t->texture = NULL; t->editable = editable; + t->allowed = allowed; t->action = action; t->submit = submit; t->user_data = user_data; |