aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-08-03 19:12:13 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-08-05 17:51:42 +0000
commit950c1b6010efe07a9a65116618a980179ed279a5 (patch)
tree2b4a4cf8a5bc21afab801a89853e8ba8eeeb5bfe
parentbox-drawing: deal with quads in the same as sextants (diff)
box-drawing: pre-calculate sextant x,y offsets
We’re using floating point math, as a way to ensure that sextant primitives overlap, rather than leaving empty spaces, or being uneven, when the cell width/height isn’t divisible with 2 (width) or 3 (height). This gets rid of all floating point math from the sextant drawing functions.
-rw-r--r--box-drawing.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/box-drawing.c b/box-drawing.c
index 63e8034a..5e511262 100644
--- a/box-drawing.c
+++ b/box-drawing.c
@@ -29,7 +29,12 @@ struct buf {
float cell_size;
float base_thickness;
bool solid_shades;
+
int thickness[2];
+
+ /* For sextants and wedges */
+ int x_halfs[2];
+ int y_thirds[4];
};
static const pixman_color_t white = {0xffff, 0xffff, 0xffff, 0xffff};
@@ -1956,37 +1961,37 @@ draw_quadrant(struct buf *buf, wchar_t wc)
static void
sextant_upper_left(struct buf *buf)
{
- rect(0, 0, round(buf->width / 2.), round(buf->height / 3.));
+ rect(0, 0, buf->x_halfs[0], buf->y_thirds[0]);
}
static void
sextant_middle_left(struct buf *buf)
{
- rect(0, buf->height / 3, round(buf->width / 2.), round(2. * buf->height / 3.));
+ rect(0, buf->y_thirds[1], buf->x_halfs[0], buf->y_thirds[2]);
}
static void
sextant_lower_left(struct buf *buf)
{
- rect(0, 2 * buf->height / 3, round(buf->width / 2.), buf->height);
+ rect(0, buf->y_thirds[3], buf->x_halfs[0], buf->height);
}
static void
sextant_upper_right(struct buf *buf)
{
- rect(buf->width / 2, 0, buf->width, round(buf->height / 3.));
+ rect(buf->x_halfs[1], 0, buf->width, buf->y_thirds[0]);
}
static void
sextant_middle_right(struct buf *buf)
{
- rect(buf->width / 2, buf->height / 3, buf->width, round(2. * buf->height / 3.));
+ rect(buf->x_halfs[1], buf->y_thirds[1], buf->width, buf->y_thirds[2]);
}
static void
sextant_lower_right(struct buf *buf)
{
- rect(buf->width / 2, 2 * buf->height / 3, buf->width, buf->height);
+ rect(buf->x_halfs[1], buf->y_thirds[3], buf->width, buf->height);
}
static void
@@ -2759,6 +2764,14 @@ box_drawing(const struct terminal *term, wchar_t wc)
buf.thickness[LIGHT] = _thickness(&buf, LIGHT);
buf.thickness[HEAVY] = _thickness(&buf, HEAVY);
+ buf.x_halfs[0] = round(width / 2.); /* End point first half */
+ buf.x_halfs[1] = width / 2; /* Start point second half */
+
+ buf.y_thirds[0] = round(height / 3.); /* End point first third */
+ buf.y_thirds[1] = height / 3; /* Start point second third */
+ buf.y_thirds[2] = round(2. * height / 3.); /* End point second third */
+ buf.y_thirds[3] = 2 * height / 3; /* Start point last third */
+
LOG_DBG("LIGHT=%d, HEAVY=%d",
_thickness(&buf, LIGHT), _thickness(&buf, HEAVY));