diff options
Diffstat (limited to 'src/tk')
-rw-r--r-- | src/tk/check.c | 39 | ||||
-rw-r--r-- | src/tk/radio.c | 11 |
2 files changed, 41 insertions, 9 deletions
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); |