summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2022-01-27 19:44:50 (EST)
committer P. J. McDermott <pj@pehjota.net>2022-01-27 19:44:50 (EST)
commit22c1a167f7e82296ab8f222291b95129df0d6d78 (patch)
treee3f2f8090c992d0ad5c4c449697edcb0a7fec437
parent92caa6344f71f3681ed255b56ecfa9294f497ab9 (diff)
downloadmazefight-22c1a167f7e82296ab8f222291b95129df0d6d78.zip
mazefight-22c1a167f7e82296ab8f222291b95129df0d6d78.tar.gz
mazefight-22c1a167f7e82296ab8f222291b95129df0d6d78.tar.bz2
tk: Add border with focus indication to check
-rw-r--r--src/menu.c20
-rw-r--r--src/tk.h16
-rw-r--r--src/tk/check.c39
-rw-r--r--src/tk/radio.c11
4 files changed, 60 insertions, 26 deletions
diff --git a/src/menu.c b/src/menu.c
index 3c037a8..c2c3b17 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -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,
diff --git a/src/tk.h b/src/tk.h
index d152f31..e99d23f 100644
--- a/src/tk.h
+++ b/src/tk.h
@@ -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);