summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tk/box.c20
-rw-r--r--src/tk/button.c15
-rw-r--r--src/tk/check.c25
-rw-r--r--src/tk/text.c25
4 files changed, 34 insertions, 51 deletions
diff --git a/src/tk/box.c b/src/tk/box.c
index fd6c071..976aeb1 100644
--- a/src/tk/box.c
+++ b/src/tk/box.c
@@ -108,18 +108,12 @@ _mftk_box_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
if (SDL_SetRenderDrawColor(renderer,
MFTK_COLOR_FBDR_R, MFTK_COLOR_FBDR_G,
MFTK_COLOR_FBDR_B, MFTK_COLOR_FBDR_A) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
- "Couldn't render widget: %s",
- SDL_GetError());
- return -1;
+ goto err;
}
#define _mftk_edge(X, Y, W, H) \
edge.x = X, edge.y = Y, edge.w = W, edge.h = H; \
if (SDL_RenderFillRect(renderer, &edge) < 0) { \
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
- "Couldn't render widget: %s", \
- SDL_GetError()); \
- return -1; \
+ goto err; \
}
_mftk_edge(outer.x , outer.y , outer.w , b->border);
_mftk_edge(outer.x , inner.y + inner.h, outer.w , b->border);
@@ -132,10 +126,7 @@ _mftk_box_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
MFTK_COLOR_FORM_R, MFTK_COLOR_FORM_G,
MFTK_COLOR_FORM_B, MFTK_COLOR_FORM_A) < 0 ||
SDL_RenderFillRect(renderer, &inner) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
- "Couldn't render widget: %s",
- SDL_GetError());
- return -1;
+ goto err;
}
/* Child widget */
@@ -145,6 +136,11 @@ _mftk_box_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
}
return 0;
+
+ err:
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't render widget: %s", SDL_GetError());
+ return -1;
}
static void
diff --git a/src/tk/button.c b/src/tk/button.c
index fa0cb65..911c024 100644
--- a/src/tk/button.c
+++ b/src/tk/button.c
@@ -124,10 +124,7 @@ _mftk_button_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
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;
+ goto err;
}
rect.x += b->border;
@@ -138,10 +135,7 @@ _mftk_button_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
MFTK_COLOR_BACK_R, MFTK_COLOR_BACK_G,
MFTK_COLOR_BACK_B, MFTK_COLOR_BACK_A) < 0 ||
SDL_RenderFillRect(renderer, &rect) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
- "Couldn't render widget: %s",
- SDL_GetError());
- return -1;
+ goto err;
}
if (mftk_widget_render(b->label, renderer,
@@ -150,6 +144,11 @@ _mftk_button_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
}
return 0;
+
+ err:
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't render widget: %s", SDL_GetError());
+ return -1;
}
static void
diff --git a/src/tk/check.c b/src/tk/check.c
index fd23b6a..c1defa2 100644
--- a/src/tk/check.c
+++ b/src/tk/check.c
@@ -170,9 +170,6 @@ _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;
}
@@ -190,9 +187,6 @@ _mftk_check_render_cir(SDL_Rect *rect, SDL_Color *color, SDL_Renderer *renderer)
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;
}
@@ -200,9 +194,6 @@ _mftk_check_render_cir(SDL_Rect *rect, SDL_Color *color, SDL_Renderer *renderer)
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)
@@ -232,7 +223,6 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
int (*render)(SDL_Rect *, SDL_Color *, SDL_Renderer *);
SDL_Rect rect;
SDL_Color *border;
- int e = 0;
if (c->shape == MFTK_CHECK_SHAPE_BOX) {
render = &_mftk_check_render_box;
@@ -250,7 +240,7 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
border = &_mftk_check_bdrn_color;
}
if (render(&rect, border, renderer) < 0) {
- e = -1;
+ goto err;
}
rect.x += c->butn_border;
@@ -258,7 +248,7 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
rect.w -= c->butn_border * 2;
rect.h -= c->butn_border * 2;
if (render(&rect, &_mftk_check_butn_color, renderer) < 0) {
- e = -1;
+ goto err;
}
if (c->state == SDL_TRUE) {
@@ -267,16 +257,21 @@ _mftk_check_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
rect.w -= c->butn_padding * 2;
rect.h -= c->butn_padding * 2;
if (render(&rect, &_mftk_check_mark_color, renderer) < 0) {
- e = -1;
+ goto err;
}
}
if (c->label != NULL && mftk_widget_render(c->label, renderer,
x + c->butn_width + c->label_padding, y) < 0) {
- e = -1;
+ goto err;
}
- return e;
+ return 0;
+
+ err:
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't render widget: %s", SDL_GetError());
+ return -1;
}
static void
diff --git a/src/tk/text.c b/src/tk/text.c
index 2b9a026..d83d5da 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -288,10 +288,7 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
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;
+ goto err;
}
rect.x += t->border;
rect.y += t->border;
@@ -301,10 +298,7 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
MFTK_COLOR_BACK_R, MFTK_COLOR_BACK_G,
MFTK_COLOR_BACK_B, MFTK_COLOR_BACK_A) <
0 || SDL_RenderFillRect(renderer, &rect) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
- "Couldn't render widget: %s",
- SDL_GetError());
- return -1;
+ goto err;
}
}
@@ -321,10 +315,7 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
if (t->val[0] != '\0' &&
SDL_RenderCopy(renderer, t->texture, NULL, &rect) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
- "Couldn't render widget: %s",
- SDL_GetError());
- return -1;
+ goto err;
}
timer = SDL_GetTicks();
if (timer - t->blink_timer >= MFTK_CURSOR_BLINK_MS) {
@@ -343,14 +334,16 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
SDL_RenderDrawLine(renderer,
x + cur_x, y + t->y,
x + cur_x, y + t->h) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
- "Couldn't render widget: %s",
- SDL_GetError());
- return -1;
+ goto err;
}
}
return 0;
+
+ err:
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't render widget: %s", SDL_GetError());
+ return -1;
}
static void