aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-01-28 03:01:13 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-01-28 15:17:49 +0100
commitfd53c7da8c5f2b79b87f624e313ff508072361ad (patch)
treedb569413cd3d42034a22368a7980aa99d7d55235 /src/gui
parente49e3073c67af785447ddb0ecbdc521b68cf3ea9 (diff)
downloadjancity-fd53c7da8c5f2b79b87f624e313ff508072361ad.tar.gz
Big rushed update
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/inc/gui/rounded_rect.h5
-rw-r--r--src/gui/src/rounded_rect.c30
2 files changed, 23 insertions, 12 deletions
diff --git a/src/gui/inc/gui/rounded_rect.h b/src/gui/inc/gui/rounded_rect.h
index 13242f4..b027b67 100644
--- a/src/gui/inc/gui/rounded_rect.h
+++ b/src/gui/inc/gui/rounded_rect.h
@@ -15,6 +15,7 @@ struct gui_rounded_rect
{
struct gui_common common;
unsigned short w, h;
+ unsigned char r, g, b;
bool adjust;
};
@@ -27,13 +28,15 @@ enum
GUI_ROUNDED_RECT_MID_VERT,
GUI_ROUNDED_RECT_DOWN_LEFT,
GUI_ROUNDED_RECT_DOWN_RIGHT,
- GUI_ROUNDED_RECT_MID,
+ GUI_ROUNDED_RECT_MID_TOP,
+ GUI_ROUNDED_RECT_MID_DOWN,
MAX_GUI_ROUNDED_RECT_SPRITES
};
extern struct sprite gui_rounded_rect_sprites[MAX_GUI_ROUNDED_RECT_SPRITES];
+/* Pad one line to avoid redefinition. */
UTIL_STATIC_ASSERT(!offsetof(struct gui_rounded_rect, common),
"unexpected offset for struct gui_rounded_rect");
diff --git a/src/gui/src/rounded_rect.c b/src/gui/src/rounded_rect.c
index 4ae3780..f37dcae 100644
--- a/src/gui/src/rounded_rect.c
+++ b/src/gui/src/rounded_rect.c
@@ -134,30 +134,36 @@ static int render_rect(const struct gui_rounded_rect *const r,
rect_get_or_ret(sel, -1);
semitrans_rect_init(sel);
- const struct sprite *const mid = &refs[GUI_ROUNDED_RECT_MID],
+ const struct sprite *const mid = &refs[GUI_ROUNDED_RECT_MID_TOP],
*const vert = &refs[GUI_ROUNDED_RECT_MID_VERT];
sel->x = x + vert->w;
sel->y = y + mid->h;
sel->w = r->w - (vert->w * 2);
sel->h = r->h - (mid->h * 2);
- sel->r = 72;
- sel->g = 66;
- sel->b = 56;
+ sel->r = r->r;
+ sel->g = r->g;
+ sel->b = r->b;
rect_sort(sel);
return 0;
}
static int render_mid(const struct gui_rounded_rect *const r,
- const short x, const short y)
+ const short x, const short y, const struct sprite *const s)
{
- const short mid_w = refs[GUI_ROUNDED_RECT_MID].w,
+ const short mid_w = s->w,
top_w = refs[GUI_ROUNDED_RECT_UP_LEFT].w,
w = r->w - (top_w * 2),
rem_mid = w % mid_w,
whole_mid = w / mid_w,
n_mid = rem_mid ? whole_mid + 1 : whole_mid;
+ if (n_mid < 0)
+ {
+ fprintf(stderr, "%s: invalid dimensions\n", __func__);
+ return -1;
+ }
+
for (struct
{
size_t i;
@@ -166,7 +172,7 @@ static int render_mid(const struct gui_rounded_rect *const r,
{
sprite_get_or_ret(m, -1);
- if (sprite_clone(&refs[GUI_ROUNDED_RECT_MID], m))
+ if (sprite_clone(s, m))
return -1;
m->x = a.x;
@@ -186,13 +192,15 @@ static int render_mid(const struct gui_rounded_rect *const r,
static int render_midtop(const struct gui_rounded_rect *const r,
const short x, const short y)
{
- return render_mid(r, x, y);
+ return render_mid(r, x, y, &refs[GUI_ROUNDED_RECT_MID_TOP]);
}
static int render_middown(const struct gui_rounded_rect *const r,
const short x, const short y)
{
- return render_mid(r, x, y + r->h - refs[GUI_ROUNDED_RECT_MID].h);
+ const struct sprite *const s = &refs[GUI_ROUNDED_RECT_MID_DOWN];
+
+ return render_mid(r, x, y + r->h - s->h, s);
}
static int render(const struct gui_common *const g)
@@ -242,8 +250,8 @@ static void add_child(struct gui_common *const parent,
short w, h;
const short ref_w = refs[GUI_ROUNDED_RECT_MID_VERT].w,
- ref_h = refs[GUI_ROUNDED_RECT_MID].h,
- min_w = ref_w * 2 + refs[GUI_ROUNDED_RECT_MID].w,
+ ref_h = refs[GUI_ROUNDED_RECT_MID_TOP].h,
+ min_w = ref_w * 2 + refs[GUI_ROUNDED_RECT_MID_TOP].w,
min_h = ref_h * 2 + refs[GUI_ROUNDED_RECT_MID_VERT].h;
child->cb->get_dim(child, &w, &h);