summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/menu.c4
-rw-r--r--src/tk.h2
-rw-r--r--src/tk/text.c28
3 files changed, 24 insertions, 10 deletions
diff --git a/src/menu.c b/src/menu.c
index 8308ba4..5a9de35 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -139,8 +139,8 @@ _mf_menu_form(SDL_Renderer *renderer, TTF_Font *text_font,
}
menu->text = mftk_text_new('0', '9', rand_max_len, menu->seed_buf,
- text_font, text_color, &_mf_menu_seed, &_mf_menu_play,
- menu);
+ text_font, text_color, SDL_TRUE, &_mf_menu_seed,
+ &_mf_menu_play, menu);
grid = mftk_grid_new(5, 2, MF_ROW_M, MF_COL_M,
mftk_label_new(text_font, "Seed", text_color, renderer),
MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T,
diff --git a/src/tk.h b/src/tk.h
index cedd57d..c83ac9e 100644
--- a/src/tk.h
+++ b/src/tk.h
@@ -77,7 +77,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,
+ TTF_Font *font, SDL_Color *color, int editable,
int (*action)(void *, const char *), int (*submit)(void *),
void *user_data);
diff --git a/src/tk/text.c b/src/tk/text.c
index 3b95d2a..ccfaf7f 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -41,6 +41,7 @@ struct mftk_text {
int ascent;
SDL_Color *color;
SDL_Texture *texture;
+ int editable;
int (*action)(void *, const char *);
int (*submit)(void *);
void *user_data;
@@ -169,6 +170,12 @@ _mftk_text_mouse_event(struct mftk_widget *w, SDL_Event *e,
int x __attribute__((__unused__)),
int y __attribute__((__unused__)))
{
+ struct mftk_text *t = (struct mftk_text *) w;
+
+ if (t->editable == SDL_FALSE) {
+ return 0;
+ }
+
switch (e->type) {
case SDL_MOUSEBUTTONUP:
if (e->button.button == SDL_BUTTON_LEFT) {
@@ -257,10 +264,12 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
SDL_GetError());
return -1;
}
- if (SDL_SetRenderDrawColor(renderer, t->color->r, t->color->g,
- t->color->b, t->color->a) < 0 ||
- SDL_RenderDrawLine(renderer,
- x, y + w->h, x + w->w, y + w->h) < 0) {
+ if (t->editable == SDL_TRUE && (
+ SDL_SetRenderDrawColor(renderer,
+ t->color->r, t->color->g,
+ t->color->b, t->color->a) < 0 ||
+ SDL_RenderDrawLine(renderer,
+ x, y + w->h, x + w->w, y + w->h) < 0)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Couldn't render widget: %s",
SDL_GetError());
@@ -289,7 +298,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,
+ TTF_Font *font, SDL_Color *color, int editable,
int (*action)(void *, const char *), int (*submit)(void *),
void *user_data)
{
@@ -298,7 +307,11 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
int advance;
char ch;
- mftk_widget_init_focusable(w, t, text);
+ if (editable == SDL_TRUE) {
+ mftk_widget_init_focusable(w, t, text);
+ } else {
+ mftk_widget_init(w, t, text);
+ }
t->min_char = min_char;
t->max_char = max_char;
@@ -308,6 +321,7 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
t->ascent = TTF_FontAscent (font);
t->color = color;
t->texture = NULL;
+ t->editable = editable;
t->action = action;
t->submit = submit;
t->user_data = user_data;
@@ -350,7 +364,7 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
w->w = advance;
}
}
- w->h = t->line_skip + 1;
+ w->h = t->line_skip + (editable == SDL_TRUE ? 1 : 0);
return w;
}