commit 9c2187caf6ed1ae879c74854af037777707eb23d
parent 07a20345dc4d1ff7a311dc1359c36394dfbc3769
Author: lumidify <nobody@lumidify.org>
Date: Fri, 3 May 2024 10:40:31 +0200
Fix clipping on border sides
Diffstat:
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/ltk/graphics_xlib.c b/src/ltk/graphics_xlib.c
@@ -151,32 +151,40 @@ ltk_surface_draw_border_clipped(ltk_surface *s, ltk_color *c, ltk_rect rect, ltk
XSetForeground(s->window->renderdata->dpy, s->window->gc, c->xcolor.pixel);
int width;
ltk_rect final_rect = ltk_rect_intersect(rect, clip_rect);
+ if (final_rect.w == 0 || final_rect.h == 0)
+ return;
+ /* TODO: I guess this could be done with fewer branches because it isn't really necessary to perform
+ a completel rect intersection each time, but it probably doesn't matter. */
if (border_sides & LTK_BORDER_TOP) {
width = rect.y - final_rect.y;
if (width > -line_width) {
width = line_width + width;
- XFillRectangle(s->window->renderdata->dpy, s->d, s->window->gc, final_rect.x, final_rect.y, final_rect.w, width);
+ ltk_rect draw_rect = ltk_rect_intersect(final_rect, (ltk_rect){final_rect.x, final_rect.y, final_rect.w, width});
+ XFillRectangle(s->window->renderdata->dpy, s->d, s->window->gc, draw_rect.x, draw_rect.y, draw_rect.w, draw_rect.h);
}
}
if (border_sides & LTK_BORDER_BOTTOM) {
width = (final_rect.y + final_rect.h) - (rect.y + rect.h);
if (width > -line_width) {
width = line_width + width;
- XFillRectangle(s->window->renderdata->dpy, s->d, s->window->gc, final_rect.x, final_rect.y + final_rect.h - width, final_rect.w, width);
+ ltk_rect draw_rect = ltk_rect_intersect(final_rect, (ltk_rect){final_rect.x, final_rect.y + final_rect.h - width, final_rect.w, width});
+ XFillRectangle(s->window->renderdata->dpy, s->d, s->window->gc, draw_rect.x, draw_rect.y, draw_rect.w, draw_rect.h);
}
}
if (border_sides & LTK_BORDER_LEFT) {
width = rect.x - final_rect.x;
if (width > -line_width) {
width = line_width + width;
- XFillRectangle(s->window->renderdata->dpy, s->d, s->window->gc, final_rect.x, final_rect.y, width, final_rect.h);
+ ltk_rect draw_rect = ltk_rect_intersect(final_rect, (ltk_rect){final_rect.x, final_rect.y, width, final_rect.h});
+ XFillRectangle(s->window->renderdata->dpy, s->d, s->window->gc, draw_rect.x, draw_rect.y, draw_rect.w, draw_rect.h);
}
}
if (border_sides & LTK_BORDER_RIGHT) {
width = (final_rect.x + final_rect.w) - (rect.x + rect.w);
if (width > -line_width) {
width = line_width + width;
- XFillRectangle(s->window->renderdata->dpy, s->d, s->window->gc, final_rect.x + final_rect.w - width, final_rect.y, width, final_rect.h);
+ ltk_rect draw_rect = ltk_rect_intersect(final_rect, (ltk_rect){final_rect.x + final_rect.w - width, final_rect.y, width, final_rect.h});
+ XFillRectangle(s->window->renderdata->dpy, s->d, s->window->gc, draw_rect.x, draw_rect.y, draw_rect.w, draw_rect.h);
}
}
}