summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/defs.h3
-rw-r--r--src/game.c2
-rw-r--r--src/menu.c4
-rw-r--r--src/tk.h2
-rw-r--r--src/tk/text.c30
5 files changed, 21 insertions, 20 deletions
diff --git a/src/defs.h b/src/defs.h
index 50380ec..ba67c29 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -101,4 +101,7 @@
#define MF_COLOR_EEYE_B 0xDF
#define MF_COLOR_EEYE_A 0xFF
+/* Text widget digits */
+#define MF_DIGITS "0123456789"
+
#endif /* MF_DEFS_H_ */
diff --git a/src/game.c b/src/game.c
index e544aa1..1db249a 100644
--- a/src/game.c
+++ b/src/game.c
@@ -52,7 +52,7 @@ static struct mftk_widget *
_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,
+ game->timer = mftk_text_new(MF_DIGITS ":", 5, "00:00", text_font,
SDL_FALSE, NULL, NULL, NULL, NULL);
return mftk_grid_new(2, 1, MF_ROW_M, MF_COL_M,
game->timer,
diff --git a/src/menu.c b/src/menu.c
index 53b530c..e82cf93 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -172,10 +172,10 @@ _mf_menu_form(SDL_Renderer *renderer, TTF_Font *text_font,
return NULL;
}
- menu->seed_text = mftk_text_new('0', '9', rand_max_len, menu->seed_buf,
+ menu->seed_text = mftk_text_new(MF_DIGITS, rand_max_len, menu->seed_buf,
text_font, SDL_TRUE, &_mf_menu_isdigit, &_mf_menu_seed,
&_mf_menu_play, menu);
- menu->enemies_text = mftk_text_new('0', '9', 2, menu->enemies_buf,
+ menu->enemies_text = mftk_text_new(MF_DIGITS, 2, menu->enemies_buf,
text_font, SDL_TRUE, &_mf_menu_isdigit,
&_mf_menu_enemies, &_mf_menu_play, menu);
grid = mftk_grid_new(6, 2, MF_ROW_M, MF_COL_M,
diff --git a/src/tk.h b/src/tk.h
index 90b0bcf..55ac0a3 100644
--- a/src/tk.h
+++ b/src/tk.h
@@ -70,7 +70,7 @@ mftk_radio_new(int butn_width, int butn_padding, int label_padding,
int state, int options, ...);
struct mftk_widget *
-mftk_text_new(char min_char, char max_char, int len, const char *val,
+mftk_text_new(const char *allowed_chars, int len, const char *val,
TTF_Font *font, 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 c96c924..644200b 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -28,8 +28,7 @@
struct mftk_text {
struct mftk_widget parent;
- char min_char;
- char max_char;
+ const char *allowed_chars;
int len;
int cur;
int y;
@@ -307,7 +306,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,
+mftk_text_new(const char *allowed_chars, int len, const char *val,
TTF_Font *font, int editable, int (*allowed)(void *, char),
int (*action)(void *, const char *), int (*submit)(void *),
void *user_data)
@@ -323,18 +322,17 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
mftk_widget_init(w, t, text);
}
- t->min_char = min_char;
- t->max_char = max_char;
- t->len = len;
- t->font = font;
- t->line_skip = TTF_FontLineSkip(font);
- t->ascent = TTF_FontAscent (font);
- t->texture = NULL;
- t->editable = editable;
- t->allowed = allowed;
- t->action = action;
- t->submit = submit;
- t->user_data = user_data;
+ t->allowed_chars = allowed_chars;
+ t->len = len;
+ t->font = font;
+ t->line_skip = TTF_FontLineSkip(font);
+ t->ascent = TTF_FontAscent (font);
+ t->texture = NULL;
+ t->editable = editable;
+ t->allowed = allowed;
+ t->action = action;
+ t->submit = submit;
+ t->user_data = user_data;
t->val = calloc(len + 1, sizeof(*t->val));
if (t->val == NULL) {
@@ -361,7 +359,7 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
memcpy(t->val, val, t->cur);
w->w = 0;
- for (ch = min_char; ch <= max_char; ++ch) {
+ for (ch = allowed_chars[0]; ch != '\0'; ++ch) {
if (TTF_GlyphMetrics(font, ch, NULL, NULL, NULL, NULL, &advance)
< 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,