diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/menu.c | 20 | ||||
-rw-r--r-- | src/tk.h | 16 | ||||
-rw-r--r-- | src/tk/check.c | 39 | ||||
-rw-r--r-- | src/tk/radio.c | 11 |
4 files changed, 60 insertions, 26 deletions
@@ -179,10 +179,10 @@ _mf_menu_form(SDL_Renderer *renderer, TTF_Font *text_font, MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T, 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, MF_CHK_LBL_P, - MF_CHK_ITM_P, text_font, &_mf_menu_size, - &_mf_menu_play, menu, renderer, 0, 3, "15x15", - "20x20", "30x30"), + mftk_radio_new(MF_CHK_BTN_W, MF_CHK_BTN_P, MF_BTN_B, + 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", renderer), MFTK_GRID_HALIGN_R|MFTK_GRID_VALIGN_T, @@ -190,15 +190,15 @@ _mf_menu_form(SDL_Renderer *renderer, TTF_Font *text_font, MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T, 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, SDL_TRUE, 0, - NULL, NULL, &_mf_menu_fow, &_mf_menu_play, menu, - renderer), + mftk_check_new(MF_CHK_BTN_W, MF_CHK_BTN_P, MF_BTN_B, + 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, SDL_FALSE, 0, - NULL, NULL, &_mf_menu_reveal, &_mf_menu_play, - menu, renderer), + mftk_check_new(MF_CHK_BTN_W, MF_CHK_BTN_P, MF_BTN_B, + 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, @@ -59,15 +59,17 @@ mftk_box_new(int container_w, int container_h, int own_w, int own_h, int padding, int border, struct mftk_widget *child); struct mftk_widget * -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); +mftk_check_new(int butn_width, int butn_padding, int butn_border, 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, 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, ...); +mftk_radio_new(int butn_width, int butn_padding, int butn_border, + 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(const char *allowed_chars, int len, const char *val, diff --git a/src/tk/check.c b/src/tk/check.c index 3746761..13af1cf 100644 --- a/src/tk/check.c +++ b/src/tk/check.c @@ -28,6 +28,7 @@ struct mftk_check { enum mftk_check_shape shape; int butn_width; int butn_padding; + int butn_border; int state; int label_padding; struct mftk_widget *label; @@ -41,6 +42,14 @@ static SDL_Color _mftk_check_butn_color = { .r = MFTK_COLOR_BACK_R, .g = MFTK_COLOR_BACK_G, .b = MFTK_COLOR_BACK_B, .a = MFTK_COLOR_BACK_A }; +static SDL_Color _mftk_check_bdrn_color = { + .r = MFTK_COLOR_BDRN_R, .g = MFTK_COLOR_BDRN_G, + .b = MFTK_COLOR_BDRN_B, .a = MFTK_COLOR_BDRN_A +}; +static SDL_Color _mftk_check_bdrf_color = { + .r = MFTK_COLOR_BDRF_R, .g = MFTK_COLOR_BDRF_G, + .b = MFTK_COLOR_BDRF_B, .a = MFTK_COLOR_BDRF_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 @@ -79,7 +88,7 @@ _mftk_check_layout(struct mftk_widget *w) mftk_widget_layout(c->label); } - w->w = c->butn_width; + w->w = c->butn_width + c->butn_border; if (c->label != NULL) { w->w += c->label_padding + c->label->w; } @@ -221,8 +230,28 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y) { struct mftk_check *c = (struct mftk_check *) w; SDL_Rect rect; + SDL_Color *border; int e = 0; + rect.x = x - c->butn_border; + rect.y = y - c->butn_border; + rect.w = c->butn_width + c->butn_border * 2; + rect.h = c->butn_width + c->butn_border * 2; + if (w->focused == SDL_TRUE) { + border = &_mftk_check_bdrf_color; + } else { + border = &_mftk_check_bdrn_color; + } + if (c->shape == MFTK_CHECK_SHAPE_BOX) { + if (_mftk_check_render_box(&rect, border, renderer) < 0) { + e = -1; + } + } else { + if (_mftk_check_render_cir(&rect, border, renderer) < 0) { + e = -1; + } + } + rect.x = x; rect.y = y; rect.w = c->butn_width; @@ -278,9 +307,10 @@ _mftk_check_destroy(struct mftk_widget *w) } struct mftk_widget * -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) +mftk_check_new(int butn_width, int butn_padding, int butn_border, 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; @@ -298,6 +328,7 @@ mftk_check_new(int butn_width, int butn_padding, int state, int label_padding, c->shape = MFTK_CHECK_SHAPE_BOX; c->butn_width = butn_width; c->butn_padding = butn_padding; + c->butn_border = butn_border; c->state = state; c->label_padding = label_padding; c->steals_focus = SDL_TRUE; diff --git a/src/tk/radio.c b/src/tk/radio.c index 8fb86bd..9f60bd3 100644 --- a/src/tk/radio.c +++ b/src/tk/radio.c @@ -169,10 +169,11 @@ _mftk_radio_destroy(struct mftk_widget *w) } struct mftk_widget * -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, ...) +mftk_radio_new(int butn_width, int butn_padding, int butn_border, + 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; @@ -202,7 +203,7 @@ mftk_radio_new(int butn_width, int butn_padding, int label_padding, va_start(ap, options); for (i = 0; i < options; ++i) { r->children[i] = mftk_check_new(butn_width, butn_padding, - (i == state), label_padding, font, + butn_border, (i == state), label_padding, font, va_arg(ap, const char *), &_mftk_radio_state_change, submit, &r->states[i], renderer); |