summaryrefslogtreecommitdiffstats
path: root/src/tk
diff options
context:
space:
mode:
Diffstat (limited to 'src/tk')
-rw-r--r--src/tk/button.c29
-rw-r--r--src/tk/style.h8
2 files changed, 34 insertions, 3 deletions
diff --git a/src/tk/button.c b/src/tk/button.c
index c0a0c61..fa0cb65 100644
--- a/src/tk/button.c
+++ b/src/tk/button.c
@@ -26,6 +26,7 @@ struct mftk_button {
struct mftk_widget parent;
struct mftk_widget *label;
int padding;
+ int border;
int (*action)(void *);
void *user_data;
};
@@ -37,8 +38,8 @@ _mftk_button_layout(struct mftk_widget *w)
mftk_widget_layout(b->label);
- w->w = b->label->w + b->padding * 2;
- w->h = b->label->h + b->padding * 2;
+ w->w = b->label->w + b->padding * 2 + b->border * 2;
+ w->h = b->label->h + b->padding * 2 + b->border * 2;
}
static void
@@ -107,11 +108,32 @@ _mftk_button_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
{
struct mftk_button *b = (struct mftk_button *) w;
SDL_Rect rect;
+ SDL_Color border;
rect.x = x;
rect.y = y;
rect.w = w->w;
rect.h = w->h;
+ if (w->focused == SDL_TRUE) {
+ border.r = MFTK_COLOR_BDRF_R, border.g = MFTK_COLOR_BDRF_G;
+ border.b = MFTK_COLOR_BDRF_B, border.a = MFTK_COLOR_BDRF_A;
+ } else {
+ border.r = MFTK_COLOR_BDRN_R, border.g = MFTK_COLOR_BDRN_G;
+ border.b = MFTK_COLOR_BDRN_B, border.a = MFTK_COLOR_BDRN_A;
+ }
+ if (SDL_SetRenderDrawColor(renderer,
+ border.r, border.g, border.b, border.a) < 0 ||
+ SDL_RenderFillRect(renderer, &rect) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't render widget: %s",
+ SDL_GetError());
+ return -1;
+ }
+
+ rect.x += b->border;
+ rect.y += b->border;
+ rect.w -= b->border * 2;
+ rect.h -= b->border * 2;
if (SDL_SetRenderDrawColor(renderer,
MFTK_COLOR_BACK_R, MFTK_COLOR_BACK_G,
MFTK_COLOR_BACK_B, MFTK_COLOR_BACK_A) < 0 ||
@@ -139,7 +161,7 @@ _mftk_button_destroy(struct mftk_widget *w)
}
struct mftk_widget *
-mftk_button_new(TTF_Font *font, const char *text, int padding,
+mftk_button_new(TTF_Font *font, const char *text, int padding, int border,
int (*action)(void *), void *user_data, SDL_Renderer *renderer)
{
struct mftk_widget *w;
@@ -154,6 +176,7 @@ mftk_button_new(TTF_Font *font, const char *text, int padding,
}
b->padding = padding;
+ b->border = border;
b->action = action;
b->user_data = user_data;
diff --git a/src/tk/style.h b/src/tk/style.h
index 14a1ea4..a8ff76f 100644
--- a/src/tk/style.h
+++ b/src/tk/style.h
@@ -32,6 +32,14 @@
#define MFTK_COLOR_BACK_G 0xAF
#define MFTK_COLOR_BACK_B 0xAF
#define MFTK_COLOR_BACK_A 0xFF
+#define MFTK_COLOR_BDRN_R 0x00 /* Widget normal border color */
+#define MFTK_COLOR_BDRN_G 0x00
+#define MFTK_COLOR_BDRN_B 0x00
+#define MFTK_COLOR_BDRN_A 0xFF
+#define MFTK_COLOR_BDRF_R 0x00 /* Widget focus border color */
+#define MFTK_COLOR_BDRF_G 0x00
+#define MFTK_COLOR_BDRF_B 0xAF
+#define MFTK_COLOR_BDRF_A 0xFF
#define MFTK_COLOR_FORE_R 0x00 /* Text color */
#define MFTK_COLOR_FORE_G 0x00
#define MFTK_COLOR_FORE_B 0x00