summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tk/check.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tk/check.c b/src/tk/check.c
index e84d30a..c8e639c 100644
--- a/src/tk/check.c
+++ b/src/tk/check.c
@@ -18,6 +18,7 @@
*/
#include <SDL.h>
+#include <math.h>
#include "../tk.h"
#include "widget.h"
@@ -97,6 +98,52 @@ _mftk_check_render_box(SDL_Rect *rect, SDL_Color *color, SDL_Renderer *renderer)
}
static int
+_mftk_check_render_cir(SDL_Rect *rect, SDL_Color *color, SDL_Renderer *renderer)
+{
+ int e = 0;
+ int r;
+ int x;
+ int y;
+ int i;
+
+ if (SDL_SetRenderDrawColor(renderer,
+ color->r, color->g, color->b, color->a) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't render widget: %s",
+ SDL_GetError());
+ e = -1;
+ }
+
+#define _mftk_check_px(X, Y) \
+ do { \
+ if (SDL_RenderDrawPoint(renderer, \
+ rect->x + r + X, rect->y + r + Y) < 0){\
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
+ "Couldn't render widget: %s", \
+ SDL_GetError()); \
+ e = -1; \
+ } \
+ } while (0)
+
+ r = rect->w / 2;
+ for (x = 0, y = r; y > x; ++x) {
+ y = round(sqrt((r-0.5)*(r-0.5) - (x-0.5)*(x-0.5)) + 0.5);
+ for (i = 0; i <= y; ++i) _mftk_check_px( x, i);
+ for (i = 0; i >= 0-y; --i) _mftk_check_px( x, i);
+ for (i = 0; i <= y; ++i) _mftk_check_px(0-x, i);
+ for (i = 0; i >= 0-y; --i) _mftk_check_px(0-x, i);
+ for (i = 0; i <= y; ++i) _mftk_check_px( i, x);
+ for (i = 0; i <= y; ++i) _mftk_check_px( i, 0-x);
+ for (i = 0; i >= 0-y; --i) _mftk_check_px( i, x);
+ for (i = 0; i >= 0-y; --i) _mftk_check_px( i, 0-x);
+ }
+
+#undef _mftk_check_px
+
+ return e;
+}
+
+static int
_mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
{
struct mftk_check *c = (struct mftk_check *) w;
@@ -111,6 +158,10 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
if (_mftk_check_render_box(&rect, c->butn_color, renderer) < 0){
e = -1;
}
+ } else {
+ if (_mftk_check_render_cir(&rect, c->butn_color, renderer) < 0){
+ e = -1;
+ }
}
if (c->state == SDL_TRUE) {
@@ -123,6 +174,11 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
renderer) < 0) {
e = -1;
}
+ } else {
+ if (_mftk_check_render_cir(&rect, c->mark_color,
+ renderer) < 0) {
+ e = -1;
+ }
}
}