summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/defs.h20
-rw-r--r--src/game.c23
-rw-r--r--src/menu.c71
-rw-r--r--src/tk.h29
-rw-r--r--src/tk/box.c9
-rw-r--r--src/tk/button.c18
-rw-r--r--src/tk/check.c38
-rw-r--r--src/tk/label.c11
-rw-r--r--src/tk/radio.c16
-rw-r--r--src/tk/style.h44
-rw-r--r--src/tk/text.c19
11 files changed, 143 insertions, 155 deletions
diff --git a/src/defs.h b/src/defs.h
index 47559c1..50380ec 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -72,26 +72,6 @@
#define MF_COLOR_MAZE_G 0x00
#define MF_COLOR_MAZE_B 0x00
#define MF_COLOR_MAZE_A 0xFF
-#define MF_COLOR_FORM_R 0xDF /* Form background color */
-#define MF_COLOR_FORM_G 0xDF
-#define MF_COLOR_FORM_B 0xDF
-#define MF_COLOR_FORM_A 0xDF
-#define MF_COLOR_FORE_R 0x00 /* Text color */
-#define MF_COLOR_FORE_G 0x00
-#define MF_COLOR_FORE_B 0x00
-#define MF_COLOR_FORE_A 0xFF
-#define MF_COLOR_BUTN_R 0xAF /* Button fill color */
-#define MF_COLOR_BUTN_G 0xAF
-#define MF_COLOR_BUTN_B 0xAF
-#define MF_COLOR_BUTN_A 0xFF
-#define MF_COLOR_CHKB_R 0xAF /* Radio button and check box button fill color */
-#define MF_COLOR_CHKB_G 0xAF
-#define MF_COLOR_CHKB_B 0xAF
-#define MF_COLOR_CHKB_A 0xFF
-#define MF_COLOR_CHKM_R 0x00 /* Radio button and check box mark fill color */
-#define MF_COLOR_CHKM_G 0x00
-#define MF_COLOR_CHKM_B 0x00
-#define MF_COLOR_CHKM_A 0xFF
#define MF_COLOR_FOGW_R 0x2F /* Fog of war color */
#define MF_COLOR_FOGW_G 0x2F
#define MF_COLOR_FOGW_B 0x2F
diff --git a/src/game.c b/src/game.c
index faf2beb..e544aa1 100644
--- a/src/game.c
+++ b/src/game.c
@@ -50,17 +50,15 @@ _mf_game_exit(void *user_data __attribute__((__unused__)))
static struct mftk_widget *
_mf_game_form(SDL_Renderer *renderer, TTF_Font *text_font,
- SDL_Color *text_color, SDL_Color *butn_color,
struct _mf_game *game)
{
game->timer = mftk_text_new('\0', '\0', 5, "00:00", text_font,
- text_color, SDL_FALSE, NULL, NULL, NULL, NULL);
+ 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,
- mftk_button_new(text_font, "Exit", text_color,
- butn_color, MF_BTN_P, &_mf_game_exit, NULL,
- renderer),
+ mftk_button_new(text_font, "Exit", MF_BTN_P,
+ &_mf_game_exit, NULL, renderer),
MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_B
);
}
@@ -146,9 +144,6 @@ mf_game(long seed, int size, int fow, int reveal, int enemies,
SDL_Color maze_color;
char *font_path = NULL;
TTF_Font *text_font = NULL;
- SDL_Color form_color;
- SDL_Color text_color;
- SDL_Color butn_color;
struct _mf_game game;
struct mftk_window *win = NULL;
int fr;
@@ -199,19 +194,11 @@ mf_game(long seed, int size, int fow, int reveal, int enemies,
free(font_path);
font_path = NULL;
- form_color.r = MF_COLOR_FORM_R, form_color.g = MF_COLOR_FORM_G;
- form_color.b = MF_COLOR_FORM_B, form_color.a = MF_COLOR_FORM_A;
- text_color.r = MF_COLOR_FORE_R, text_color.g = MF_COLOR_FORE_G;
- text_color.b = MF_COLOR_FORE_B, text_color.a = MF_COLOR_FORE_A;
- butn_color.r = MF_COLOR_BUTN_R, butn_color.g = MF_COLOR_BUTN_G;
- butn_color.b = MF_COLOR_BUTN_B, butn_color.a = MF_COLOR_BUTN_A;
-
win = mftk_window_new(MF_WINDOW_H, 0, mftk_box_new(
MF_WINDOW_W - MF_WINDOW_H, MF_WINDOW_H,
MF_WINDOW_W - MF_WINDOW_H, MF_WINDOW_H,
- MF_FORM_P, &form_color,
- _mf_game_form(renderer, text_font,
- &text_color, &butn_color, &game)));
+ MF_FORM_P,
+ _mf_game_form(renderer, text_font, &game)));
game.beg = SDL_GetTicks();
diff --git a/src/menu.c b/src/menu.c
index c5087ee..53b530c 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -146,8 +146,6 @@ _mf_menu_play(void *user_data)
static struct mftk_widget *
_mf_menu_form(SDL_Renderer *renderer, TTF_Font *text_font,
- SDL_Color *text_color, SDL_Color *butn_color,
- SDL_Color *chkb_color, SDL_Color *chkm_color,
struct _mf_menu *menu)
{
double rand_max_len;
@@ -175,54 +173,47 @@ _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_isdigit,
- &_mf_menu_seed, &_mf_menu_play, menu);
+ 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,
- text_font, text_color, SDL_TRUE, &_mf_menu_isdigit,
+ 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,
- mftk_label_new(text_font, "Seed", text_color, renderer),
+ mftk_label_new(text_font, "Seed", renderer),
MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T,
menu->seed_text,
MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T,
- mftk_label_new(text_font, "Size", text_color, renderer),
+ mftk_label_new(text_font, "Size", renderer),
MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T,
- mftk_radio_new(MF_CHK_BTN_W, MF_CHK_BTN_P, chkb_color,
- chkm_color, MF_CHK_LBL_P, MF_CHK_ITM_P,
- text_font, text_color, &_mf_menu_size,
+ mftk_radio_new(MF_CHK_BTN_W, MF_CHK_BTN_P, MF_CHK_LBL_P,
+ MF_CHK_ITM_P, text_font, &_mf_menu_size,
&_mf_menu_play, menu, renderer, 0, 3, "15x15",
"20x20", "30x30"),
MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T,
- mftk_label_new(text_font, "Enemies", text_color,
- renderer),
+ mftk_label_new(text_font, "Enemies", renderer),
MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T,
menu->enemies_text,
MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T,
- mftk_label_new(text_font, "Fog of war", text_color,
- renderer),
+ mftk_label_new(text_font, "Fog of war", renderer),
MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T,
- mftk_check_new(MF_CHK_BTN_W, MF_CHK_BTN_P, chkb_color,
- chkm_color, SDL_TRUE, 0, NULL, NULL, NULL,
- &_mf_menu_fow, &_mf_menu_play, menu, renderer),
- MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T,
- mftk_label_new(text_font, "Reveal maze", text_color,
+ mftk_check_new(MF_CHK_BTN_W, MF_CHK_BTN_P, SDL_TRUE, 0,
+ NULL, NULL, &_mf_menu_fow, &_mf_menu_play, menu,
renderer),
+ MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T,
+ mftk_label_new(text_font, "Reveal maze", renderer),
MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T,
- mftk_check_new(MF_CHK_BTN_W, MF_CHK_BTN_P, chkb_color,
- chkm_color, SDL_FALSE, 0, NULL, NULL, NULL,
- &_mf_menu_reveal, &_mf_menu_play, menu,
- renderer),
+ mftk_check_new(MF_CHK_BTN_W, MF_CHK_BTN_P, SDL_FALSE, 0,
+ NULL, NULL, &_mf_menu_reveal, &_mf_menu_play,
+ menu, renderer),
MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T,
mftk_blank_new(),
MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T,
mftk_grid_new(1, 2, 0, MF_BTN_M,
- mftk_button_new(text_font, "Quit", text_color,
- butn_color, MF_BTN_P, &_mf_menu_quit,
- NULL, renderer),
+ mftk_button_new(text_font, "Quit", MF_BTN_P,
+ &_mf_menu_quit, NULL, renderer),
MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T,
- mftk_button_new(text_font, "Play", text_color,
- butn_color, MF_BTN_P, &_mf_menu_play,
- menu, renderer),
+ mftk_button_new(text_font, "Play", MF_BTN_P,
+ &_mf_menu_play, menu, renderer),
MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T
),
MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T
@@ -240,11 +231,6 @@ mf_menu(SDL_Renderer *renderer)
char *font_path = NULL;
TTF_Font *title_font = NULL;
TTF_Font *text_font = NULL;
- SDL_Color form_color;
- SDL_Color text_color;
- SDL_Color butn_color;
- SDL_Color chkb_color;
- SDL_Color chkm_color;
struct mftk_window *win = NULL;
SDL_Event event;
@@ -287,26 +273,13 @@ mf_menu(SDL_Renderer *renderer)
free(font_path);
font_path = NULL;
- form_color.r = MF_COLOR_FORM_R, form_color.g = MF_COLOR_FORM_G;
- form_color.b = MF_COLOR_FORM_B, form_color.a = MF_COLOR_FORM_A;
- text_color.r = MF_COLOR_FORE_R, text_color.g = MF_COLOR_FORE_G;
- text_color.b = MF_COLOR_FORE_B, text_color.a = MF_COLOR_FORE_A;
- butn_color.r = MF_COLOR_BUTN_R, butn_color.g = MF_COLOR_BUTN_G;
- butn_color.b = MF_COLOR_BUTN_B, butn_color.a = MF_COLOR_BUTN_A;
- chkb_color.r = MF_COLOR_CHKB_R, chkb_color.g = MF_COLOR_CHKB_G;
- chkb_color.b = MF_COLOR_CHKB_B, chkb_color.a = MF_COLOR_CHKB_A;
- chkm_color.r = MF_COLOR_CHKM_R, chkm_color.g = MF_COLOR_CHKM_G;
- chkm_color.b = MF_COLOR_CHKM_B, chkm_color.a = MF_COLOR_CHKM_A;
-
win = mftk_window_new(0, 0, mftk_box_new(MF_WINDOW_W, MF_WINDOW_H, 0, 0,
- MF_FORM_P, &form_color,
+ MF_FORM_P,
mftk_grid_new(2, 1, MF_TITLE_M, 0,
mftk_label_new(title_font, "Maze Fight",
- &text_color, renderer),
+ renderer),
MFTK_GRID_HALIGN_C|MFTK_GRID_VALIGN_T,
_mf_menu_form(renderer, text_font,
- &text_color, &butn_color,
- &chkb_color, &chkm_color,
&menu),
MFTK_GRID_HALIGN_C|MFTK_GRID_VALIGN_T
)
diff --git a/src/tk.h b/src/tk.h
index 598b971..90b0bcf 100644
--- a/src/tk.h
+++ b/src/tk.h
@@ -39,12 +39,10 @@ void
mftk_window_destroy(struct mftk_window **w_p);
struct mftk_widget *
-mftk_label_new(TTF_Font *font, const char *text, SDL_Color *color,
- SDL_Renderer *renderer);
+mftk_label_new(TTF_Font *font, const char *text, SDL_Renderer *renderer);
struct mftk_widget *
-mftk_button_new(TTF_Font *font, const char *text, SDL_Color *text_color,
- SDL_Color *fill_color, int padding,
+mftk_button_new(TTF_Font *font, const char *text, int padding,
int (*action)(void *), void *user_data, SDL_Renderer *renderer);
#define MFTK_GRID_HALIGN_L 1
@@ -58,27 +56,22 @@ mftk_grid_new(int rows, int cols, int row_spacing, int col_spacing, ...);
struct mftk_widget *
mftk_box_new(int container_w, int container_h, int own_w, int own_h,
- int padding, SDL_Color *bg_color, struct mftk_widget *child);
+ int padding, struct mftk_widget *child);
struct mftk_widget *
-mftk_check_new(int butn_width, int butn_padding, SDL_Color *butn_color,
- SDL_Color *mark_color, int state, int label_padding,
- TTF_Font *font, const char *text, SDL_Color *text_color,
- int (*action)(void *, int), int (*submit)(void *),
- void *user_data, SDL_Renderer *renderer);
+mftk_check_new(int butn_width, int butn_padding, int state, int label_padding,
+ TTF_Font *font, const char *text, int (*action)(void *, int),
+ int (*submit)(void *), void *user_data, SDL_Renderer *renderer);
struct mftk_widget *
-mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color,
- SDL_Color *mark_color, int label_padding, int item_padding,
- TTF_Font *font, SDL_Color *text_color,
- int (*action)(void *, int), int (*submit)(void *),
- void *user_data, SDL_Renderer *renderer, int state, int options,
- ...);
+mftk_radio_new(int butn_width, int butn_padding, int label_padding,
+ int item_padding, TTF_Font *font, int (*action)(void *, int),
+ int (*submit)(void *), void *user_data, SDL_Renderer *renderer,
+ int state, int options, ...);
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);
diff --git a/src/tk/box.c b/src/tk/box.c
index da0ef5d..003af66 100644
--- a/src/tk/box.c
+++ b/src/tk/box.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include "../tk.h"
+#include "style.h"
#include "widget.h"
struct mftk_box {
@@ -29,7 +30,6 @@ struct mftk_box {
int container_w;
int container_h;
int padding;
- SDL_Color *bg_color;
struct mftk_widget *child;
int child_x;
int child_y;
@@ -97,8 +97,8 @@ _mftk_box_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
rect.w = w->w;
rect.h = w->h;
if (SDL_SetRenderDrawColor(renderer,
- b->bg_color->r, b->bg_color->g,
- b->bg_color->b, b->bg_color->a) < 0 ||
+ MFTK_COLOR_FORM_R, MFTK_COLOR_FORM_G,
+ MFTK_COLOR_FORM_B, MFTK_COLOR_FORM_A) < 0 ||
SDL_RenderFillRect(renderer, &rect) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Couldn't render widget: %s",
@@ -125,7 +125,7 @@ _mftk_box_destroy(struct mftk_widget *w)
struct mftk_widget *
mftk_box_new(int container_w, int container_h, int own_w, int own_h,
- int padding, SDL_Color *bg_color, struct mftk_widget *child)
+ int padding, struct mftk_widget *child)
{
struct mftk_widget *w;
struct mftk_box *b;
@@ -137,7 +137,6 @@ mftk_box_new(int container_w, int container_h, int own_w, int own_h,
w->w = own_w;
w->h = own_h;
b->padding = padding;
- b->bg_color = bg_color;
b->child = child;
child->container = w;
diff --git a/src/tk/button.c b/src/tk/button.c
index 1152bd9..47f59f6 100644
--- a/src/tk/button.c
+++ b/src/tk/button.c
@@ -19,12 +19,12 @@
#include <SDL.h>
#include "../tk.h"
+#include "style.h"
#include "widget.h"
struct mftk_button {
struct mftk_widget parent;
struct mftk_widget *label;
- SDL_Color *fill_color;
int padding;
int (*action)(void *);
void *user_data;
@@ -113,8 +113,8 @@ _mftk_button_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
rect.w = w->w;
rect.h = w->h;
if (SDL_SetRenderDrawColor(renderer,
- b->fill_color->r, b->fill_color->g,
- b->fill_color->b, b->fill_color->a) < 0 ||
+ MFTK_COLOR_BUTN_R, MFTK_COLOR_BUTN_G,
+ MFTK_COLOR_BUTN_B, MFTK_COLOR_BUTN_A) < 0 ||
SDL_RenderFillRect(renderer, &rect) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Couldn't render widget: %s",
@@ -139,8 +139,7 @@ _mftk_button_destroy(struct mftk_widget *w)
}
struct mftk_widget *
-mftk_button_new(TTF_Font *font, const char *text, SDL_Color *text_color,
- SDL_Color *fill_color, int padding,
+mftk_button_new(TTF_Font *font, const char *text, int padding,
int (*action)(void *), void *user_data, SDL_Renderer *renderer)
{
struct mftk_widget *w;
@@ -148,16 +147,15 @@ mftk_button_new(TTF_Font *font, const char *text, SDL_Color *text_color,
mftk_widget_init_focusable(w, b, button);
- b->label = mftk_label_new(font, text, text_color, renderer);
+ b->label = mftk_label_new(font, text, renderer);
if (b->label == NULL) {
free(b);
return NULL;
}
- b->fill_color = fill_color;
- b->padding = padding;
- b->action = action;
- b->user_data = user_data;
+ b->padding = padding;
+ b->action = action;
+ b->user_data = user_data;
return w;
}
diff --git a/src/tk/check.c b/src/tk/check.c
index 0b2ea56..b24db0b 100644
--- a/src/tk/check.c
+++ b/src/tk/check.c
@@ -20,6 +20,7 @@
#include <SDL.h>
#include <math.h>
#include "../tk.h"
+#include "style.h"
#include "widget.h"
struct mftk_check {
@@ -27,8 +28,6 @@ struct mftk_check {
enum mftk_check_shape shape;
int butn_width;
int butn_padding;
- SDL_Color *butn_color;
- SDL_Color *mark_color;
int state;
int label_padding;
struct mftk_widget *label;
@@ -38,6 +37,15 @@ struct mftk_check {
void *user_data;
};
+static SDL_Color _mftk_check_butn_color = {
+ .r = MFTK_COLOR_CHKB_R, .g = MFTK_COLOR_CHKB_G,
+ .b = MFTK_COLOR_CHKB_B, .a = MFTK_COLOR_CHKB_A
+};
+static SDL_Color _mftk_check_mark_color = {
+ .r = MFTK_COLOR_CHKM_R, .g = MFTK_COLOR_CHKM_G,
+ .b = MFTK_COLOR_CHKM_B, .a = MFTK_COLOR_CHKM_A
+};
+
void
mftk_check_set_shape(struct mftk_widget *w, enum mftk_check_shape shape)
{
@@ -220,11 +228,13 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
rect.w = c->butn_width;
rect.h = c->butn_width;
if (c->shape == MFTK_CHECK_SHAPE_BOX) {
- if (_mftk_check_render_box(&rect, c->butn_color, renderer) < 0){
+ if (_mftk_check_render_box(&rect, &_mftk_check_butn_color,
+ renderer) < 0) {
e = -1;
}
} else {
- if (_mftk_check_render_cir(&rect, c->butn_color, renderer) < 0){
+ if (_mftk_check_render_cir(&rect, &_mftk_check_butn_color,
+ renderer) < 0) {
e = -1;
}
}
@@ -235,12 +245,14 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
rect.w -= c->butn_padding * 2;
rect.h -= c->butn_padding * 2;
if (c->shape == MFTK_CHECK_SHAPE_BOX) {
- if (_mftk_check_render_box(&rect, c->mark_color,
+ if (_mftk_check_render_box(&rect,
+ &_mftk_check_mark_color,
renderer) < 0) {
e = -1;
}
} else {
- if (_mftk_check_render_cir(&rect, c->mark_color,
+ if (_mftk_check_render_cir(&rect,
+ &_mftk_check_mark_color,
renderer) < 0) {
e = -1;
}
@@ -266,19 +278,17 @@ _mftk_check_destroy(struct mftk_widget *w)
}
struct mftk_widget *
-mftk_check_new(int butn_width, int butn_padding, SDL_Color *butn_color,
- SDL_Color *mark_color, int state, int label_padding,
- TTF_Font *font, const char *text, SDL_Color *text_color,
- int (*action)(void *, int), int (*submit)(void *),
- void *user_data, SDL_Renderer *renderer)
+mftk_check_new(int butn_width, int butn_padding, int state, int label_padding,
+ TTF_Font *font, const char *text, int (*action)(void *, int),
+ int (*submit)(void *), void *user_data, SDL_Renderer *renderer)
{
struct mftk_widget *w;
struct mftk_check *c;
mftk_widget_init_focusable(w, c, check);
- if (font != NULL && text != NULL && text_color != NULL) {
- c->label = mftk_label_new(font, text, text_color, renderer);
+ if (font != NULL && text != NULL) {
+ c->label = mftk_label_new(font, text, renderer);
if (c->label == NULL) {
free(c);
return NULL;
@@ -288,8 +298,6 @@ mftk_check_new(int butn_width, int butn_padding, SDL_Color *butn_color,
c->shape = MFTK_CHECK_SHAPE_BOX;
c->butn_width = butn_width;
c->butn_padding = butn_padding;
- c->butn_color = butn_color;
- c->mark_color = mark_color;
c->state = state;
c->label_padding = label_padding;
c->steals_focus = SDL_TRUE;
diff --git a/src/tk/label.c b/src/tk/label.c
index dcd827e..bd4e5a4 100644
--- a/src/tk/label.c
+++ b/src/tk/label.c
@@ -20,6 +20,7 @@
#include <SDL.h>
#include <SDL_ttf.h>
#include "../tk.h"
+#include "style.h"
#include "widget.h"
struct mftk_label {
@@ -29,6 +30,11 @@ struct mftk_label {
int h;
};
+static SDL_Color _mftk_label_color = {
+ .r = MFTK_COLOR_FORE_R, .g = MFTK_COLOR_FORE_G,
+ .b = MFTK_COLOR_FORE_B, .a = MFTK_COLOR_FORE_A
+};
+
static void
_mftk_label_layout(struct mftk_widget *w __attribute__((__unused__)))
{
@@ -75,8 +81,7 @@ _mftk_label_destroy(struct mftk_widget *w)
}
struct mftk_widget *
-mftk_label_new(TTF_Font *font, const char *text, SDL_Color *color,
- SDL_Renderer *renderer)
+mftk_label_new(TTF_Font *font, const char *text, SDL_Renderer *renderer)
{
struct mftk_widget *w;
struct mftk_label *l;
@@ -89,7 +94,7 @@ mftk_label_new(TTF_Font *font, const char *text, SDL_Color *color,
mftk_widget_init(w, l, label);
- surface = TTF_RenderUTF8_Blended(font, text, *color);
+ surface = TTF_RenderUTF8_Blended(font, text, _mftk_label_color);
if (surface == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Couldn't create surface: %s",
diff --git a/src/tk/radio.c b/src/tk/radio.c
index 755be15..8fb86bd 100644
--- a/src/tk/radio.c
+++ b/src/tk/radio.c
@@ -169,12 +169,10 @@ _mftk_radio_destroy(struct mftk_widget *w)
}
struct mftk_widget *
-mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color,
- SDL_Color *mark_color, int label_padding, int item_padding,
- TTF_Font *font, SDL_Color *text_color,
- int (*action)(void *, int), int (*submit)(void *),
- void *user_data, SDL_Renderer *renderer, int state, int options,
- ...)
+mftk_radio_new(int butn_width, int butn_padding, int label_padding,
+ int item_padding, TTF_Font *font, int (*action)(void *, int),
+ int (*submit)(void *), void *user_data, SDL_Renderer *renderer,
+ int state, int options, ...)
{
struct mftk_widget *w;
struct mftk_radio *r;
@@ -204,9 +202,9 @@ mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color,
va_start(ap, options);
for (i = 0; i < options; ++i) {
r->children[i] = mftk_check_new(butn_width, butn_padding,
- butn_color, mark_color, (i == state),
- label_padding, font, va_arg(ap, const char *),
- text_color, &_mftk_radio_state_change, submit,
+ (i == state), label_padding, font,
+ va_arg(ap, const char *),
+ &_mftk_radio_state_change, submit,
&r->states[i], renderer);
if (r->children[i] == NULL) {
for (; i >= 0; --i) {
diff --git a/src/tk/style.h b/src/tk/style.h
new file mode 100644
index 0000000..16b4e25
--- /dev/null
+++ b/src/tk/style.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2021 P. J. McDermott
+ *
+ * This file is part of Maze Fight
+ *
+ * Maze Fight is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Maze Fight is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Maze Fight. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MFTK_STYLE_H_
+#define MFTK_STYLE_H_
+
+#define MFTK_COLOR_FORM_R 0xDF /* Form background color */
+#define MFTK_COLOR_FORM_G 0xDF
+#define MFTK_COLOR_FORM_B 0xDF
+#define MFTK_COLOR_FORM_A 0xDF
+#define MFTK_COLOR_FORE_R 0x00 /* Text color */
+#define MFTK_COLOR_FORE_G 0x00
+#define MFTK_COLOR_FORE_B 0x00
+#define MFTK_COLOR_FORE_A 0xFF
+#define MFTK_COLOR_BUTN_R 0xAF /* Button fill color */
+#define MFTK_COLOR_BUTN_G 0xAF
+#define MFTK_COLOR_BUTN_B 0xAF
+#define MFTK_COLOR_BUTN_A 0xFF
+#define MFTK_COLOR_CHKB_R 0xAF /* Radio button and check box button fill color */
+#define MFTK_COLOR_CHKB_G 0xAF
+#define MFTK_COLOR_CHKB_B 0xAF
+#define MFTK_COLOR_CHKB_A 0xFF
+#define MFTK_COLOR_CHKM_R 0x00 /* Radio button and check box mark fill color */
+#define MFTK_COLOR_CHKM_G 0x00
+#define MFTK_COLOR_CHKM_B 0x00
+#define MFTK_COLOR_CHKM_A 0xFF
+
+#endif /* MFTK_STYLE_H_ */
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 <string.h>
#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;