From 2ed3153670ffba9d43f6033ce89dc33c241de193 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 25 Sep 2021 18:39:15 -0400 Subject: tk: Define colors within local header --- (limited to 'src/tk/text.c') diff --git a/src/tk/text.c b/src/tk/text.c index 8622e63..c96c924 100644 --- a/src/tk/text.c +++ b/src/tk/text.c @@ -23,6 +23,7 @@ #include #include "../tk.h" #include "../util.h" +#include "style.h" #include "widget.h" struct mftk_text { @@ -39,7 +40,6 @@ struct mftk_text { TTF_Font *font; int line_skip; int ascent; - SDL_Color *color; SDL_Texture *texture; int editable; int (*allowed)(void *, char); @@ -48,6 +48,11 @@ struct mftk_text { void *user_data; }; +static SDL_Color _mftk_text_color = { + .r = MFTK_COLOR_FORE_R, .g = MFTK_COLOR_FORE_G, + .b = MFTK_COLOR_FORE_B, .a = MFTK_COLOR_FORE_A +}; + static void _mftk_text_layout(struct mftk_widget *w __attribute__((__unused__))) { @@ -202,7 +207,7 @@ _mftk_text_render_val(struct mftk_text *t, SDL_Renderer *renderer) const char *c; int glyph_max_y; - surface = TTF_RenderUTF8_Blended(t->font, t->val, *t->color); + surface = TTF_RenderUTF8_Blended(t->font, t->val, _mftk_text_color); if (surface == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create surface: %s", @@ -271,9 +276,9 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y) } if (t->editable == SDL_TRUE && ( SDL_SetRenderDrawColor(renderer, - t->color->r, t->color->g, - t->color->b, t->color->a) < 0 || - SDL_RenderDrawLine(renderer, + _mftk_text_color.r, _mftk_text_color.g, + _mftk_text_color.b, _mftk_text_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", @@ -303,8 +308,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), + TTF_Font *font, int editable, int (*allowed)(void *, char), int (*action)(void *, const char *), int (*submit)(void *), void *user_data) { @@ -325,7 +329,6 @@ mftk_text_new(char min_char, char max_char, int len, const char *val, t->font = font; t->line_skip = TTF_FontLineSkip(font); t->ascent = TTF_FontAscent (font); - t->color = color; t->texture = NULL; t->editable = editable; t->allowed = allowed; -- cgit v0.9.1