summaryrefslogtreecommitdiffstats
path: root/src/tk
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-07 19:48:44 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-07 19:48:44 (EDT)
commit7400b756adb8c65e5e30d4a46dbd052d547b6104 (patch)
tree530b0767d5c7b62c71671b4bfa04dc96af7a326e /src/tk
parentc039f3e47de09f7653f4666f62fff2d6a1dd8b26 (diff)
downloadmazefight-7400b756adb8c65e5e30d4a46dbd052d547b6104.zip
mazefight-7400b756adb8c65e5e30d4a46dbd052d547b6104.tar.gz
mazefight-7400b756adb8c65e5e30d4a46dbd052d547b6104.tar.bz2
tk: Make text widget optionally static
Diffstat (limited to 'src/tk')
-rw-r--r--src/tk/text.c28
1 files changed, 21 insertions, 7 deletions
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;
}