mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-06 07:15:30 -04:00
box-drawing: implement LIGHT diagonal lines using pixman
Use trapezoids to rasterize the diagonal lines.
This commit is contained in:
parent
19fa1b30b8
commit
e05a510a7c
1 changed files with 52 additions and 30 deletions
|
|
@ -1363,44 +1363,66 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
draw_box_drawings_light_diagonal(struct buf *buf, double k, double c)
|
|
||||||
{
|
|
||||||
#define linear_equation(x) (k * (x) + c)
|
|
||||||
|
|
||||||
int num_samples = buf->width * 16;
|
|
||||||
|
|
||||||
for (int i = 0; i < num_samples; i++) {
|
|
||||||
double x = i / 16.;
|
|
||||||
int col = round(x);
|
|
||||||
int row = round(linear_equation(x));
|
|
||||||
|
|
||||||
if (row >= 0 && row < buf->height) {
|
|
||||||
size_t ofs = col / 8;
|
|
||||||
size_t bit_no = col % 8;
|
|
||||||
buf->data[row * buf->stride + ofs] |= 1 << bit_no;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef linear_equation
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_box_drawings_light_diagonal_upper_right_to_lower_left(struct buf *buf)
|
draw_box_drawings_light_diagonal_upper_right_to_lower_left(struct buf *buf)
|
||||||
{
|
{
|
||||||
/* y = k * x + c */
|
pixman_trapezoid_t trap = {
|
||||||
double c = buf->height - 1;
|
.top = pixman_int_to_fixed(0),
|
||||||
double k = (0 - (buf->height - 1)) / (double)(buf->width - 1 - 0);
|
.bottom = pixman_int_to_fixed(buf->height),
|
||||||
draw_box_drawings_light_diagonal(buf, k, c);
|
.left = {
|
||||||
|
.p1 = {
|
||||||
|
.x = pixman_double_to_fixed(buf->width - thickness(LIGHT) / 2.),
|
||||||
|
.y = pixman_int_to_fixed(0),
|
||||||
|
},
|
||||||
|
.p2 = {
|
||||||
|
.x = pixman_double_to_fixed(0 - thickness(LIGHT) / 2.),
|
||||||
|
.y = pixman_int_to_fixed(buf->height),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.right = {
|
||||||
|
.p1 = {
|
||||||
|
.x = pixman_double_to_fixed(buf->width + thickness(LIGHT) / 2.),
|
||||||
|
.y = pixman_int_to_fixed(0),
|
||||||
|
},
|
||||||
|
.p2 = {
|
||||||
|
.x = pixman_double_to_fixed(0 + thickness(LIGHT) / 2.),
|
||||||
|
.y = pixman_int_to_fixed(buf->height),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pixman_rasterize_trapezoid(buf->pix, &trap, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_box_drawings_light_diagonal_upper_left_to_lower_right(struct buf *buf)
|
draw_box_drawings_light_diagonal_upper_left_to_lower_right(struct buf *buf)
|
||||||
{
|
{
|
||||||
/* y = k * x + c */
|
pixman_trapezoid_t trap = {
|
||||||
double c = 0;
|
.top = pixman_int_to_fixed(0),
|
||||||
double k = (buf->height - 1 - 0) / (double)(buf->width - 1 - 0);
|
.bottom = pixman_int_to_fixed(buf->height),
|
||||||
draw_box_drawings_light_diagonal(buf, k, c);
|
.left = {
|
||||||
|
.p1 = {
|
||||||
|
.x = pixman_double_to_fixed(0 - thickness(LIGHT) / 2.),
|
||||||
|
.y = pixman_int_to_fixed(0),
|
||||||
|
},
|
||||||
|
.p2 = {
|
||||||
|
.x = pixman_double_to_fixed(buf->width - thickness(LIGHT) / 2.),
|
||||||
|
.y = pixman_int_to_fixed(buf->height),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.right = {
|
||||||
|
.p1 = {
|
||||||
|
.x = pixman_double_to_fixed(0 + thickness(LIGHT) / 2.),
|
||||||
|
.y = pixman_int_to_fixed(0),
|
||||||
|
},
|
||||||
|
.p2 = {
|
||||||
|
.x = pixman_double_to_fixed(buf->width + thickness(LIGHT) / 2.),
|
||||||
|
.y = pixman_int_to_fixed(buf->height),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pixman_rasterize_trapezoid(buf->pix, &trap, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue