diff options
-rw-r--r-- | src/tk/check.c | 75 | ||||
-rw-r--r-- | src/tk/widget.h | 8 |
2 files changed, 55 insertions, 28 deletions
diff --git a/src/tk/check.c b/src/tk/check.c index b5f91b8..e84d30a 100644 --- a/src/tk/check.c +++ b/src/tk/check.c @@ -22,18 +22,27 @@ #include "widget.h" struct mftk_check { - struct mftk_widget parent; - int butn_width; - int butn_padding; - SDL_Color *butn_color; - SDL_Color *mark_color; - int state; - int label_padding; - struct mftk_widget *label; - int (*action)(void *, int); - void *user_data; + struct mftk_widget parent; + 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; + int (*action)(void *, int); + void *user_data; }; +void +mftk_check_set_shape(struct mftk_widget *w, enum mftk_check_shape shape) +{ + struct mftk_check *c = (struct mftk_check *) w; + + c->shape = shape; +} + static void _mftk_check_layout(struct mftk_widget *w) { @@ -73,23 +82,35 @@ _mftk_check_event(struct mftk_widget *w, SDL_Event *e, } static int +_mftk_check_render_box(SDL_Rect *rect, SDL_Color *color, SDL_Renderer *renderer) +{ + if (SDL_SetRenderDrawColor(renderer, + color->r, color->g, color->b, color->a) < 0 || + SDL_RenderFillRect(renderer, rect) < 0) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Couldn't render widget: %s", + SDL_GetError()); + return -1; + } + + return 0; +} + +static int _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; + int e = 0; rect.x = x; rect.y = y; rect.w = c->butn_width; rect.h = c->butn_width; - if (SDL_SetRenderDrawColor(renderer, - c->butn_color->r, c->butn_color->g, - c->butn_color->b, c->butn_color->a) < 0 || - SDL_RenderFillRect(renderer, &rect) < 0) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "Couldn't render widget: %s", - SDL_GetError()); - return -1; + if (c->shape == MFTK_CHECK_SHAPE_BOX) { + if (_mftk_check_render_box(&rect, c->butn_color, renderer) < 0){ + e = -1; + } } if (c->state == SDL_TRUE) { @@ -97,23 +118,20 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y) rect.y += c->butn_padding; rect.w -= c->butn_padding * 2; rect.h -= c->butn_padding * 2; - if (SDL_SetRenderDrawColor(renderer, - c->mark_color->r, c->mark_color->g, - c->mark_color->b, c->mark_color->a) < 0 - || SDL_RenderFillRect(renderer, &rect) < 0) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "Couldn't render widget: %s", - SDL_GetError()); - return -1; + if (c->shape == MFTK_CHECK_SHAPE_BOX) { + if (_mftk_check_render_box(&rect, c->mark_color, + renderer) < 0) { + e = -1; + } } } if (c->label != NULL && mftk_widget_render(c->label, renderer, x + c->butn_width + c->label_padding, y) < 0) { - return -1; + e = -1; } - return 0; + return e; } static void @@ -146,6 +164,7 @@ 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; diff --git a/src/tk/widget.h b/src/tk/widget.h index 4966749..047dd6d 100644 --- a/src/tk/widget.h +++ b/src/tk/widget.h @@ -49,4 +49,12 @@ mftk_widget_new(size_t size); t_w = (struct mftk_##name *) w; \ } while (0) +enum mftk_check_shape { + MFTK_CHECK_SHAPE_BOX, + MFTK_CHECK_SHAPE_CIR +}; + +void +mftk_check_set_shape(struct mftk_widget *w, enum mftk_check_shape shape); + #endif /* MFTK_WIDGET_H_ */ |