display: Add display_line API for vector strokes.

This commit is contained in:
Lars Brinkhoff 2021-03-29 08:43:29 +02:00
parent f424080742
commit fe27bbedc5
2 changed files with 73 additions and 0 deletions

View file

@ -809,6 +809,72 @@ display_point(int x, /* 0..xpixels (unscaled) */
return lx*lx + ly*ly <= scaled_pen_radius_squared;
} /* display_point */
#define ABS(_X) ((_X) >= 0 ? (_X) : -(_X))
#define SIGN(_X) ((_X) >= 0 ? 1 : -1)
static void
xline (int x, int y, int x2, int dx, int dy, int level)
{
int ix = SIGN(dx);
int iy = SIGN(dy);
int ay;
dx = ABS(dx);
dy = ABS(dy);
ay = dy/2;
for (;;) {
display_point (x, y, level, 0);
if (x == x2)
break;
if (ay > 0) {
y += iy;
ay -= dx;
}
ay += dy;
x += ix;
}
}
static void
yline (int x, int y, int y2, int dx, int dy, int level)
{
int ix = SIGN(dx);
int iy = SIGN(dy);
int ax;
dx = ABS(dx);
dy = ABS(dy);
ax = dx/2;
for (;;) {
display_point (x, y, level, 0);
if (y == y2)
break;
if (ax > 0) {
x += ix;
ax -= dy;
}
ax += dx;
y += iy;
}
}
void
display_line(int x1, /* 0..xpixels (unscaled) */
int y1, /* 0..ypixels (unscaled) */
int x2, /* 0..xpixels (unscaled) */
int y2, /* 0..ypixels (unscaled) */
int level) /* DISPLAY_INT_xxx */
{
int dx = x2 - x1;
int dy = y2 - y1;
if (ABS (dx) > ABS(dy))
xline (x1, y1, x2, dx, dy, level);
else
yline (x1, y1, y2, dx, dy, level);
} /* display_line */
/*
* calculate decay color table for a phosphor mixture
* must be called AFTER refresh_rate initialized!

View file

@ -112,6 +112,13 @@ extern int display_is_blank(void);
*/
extern int display_point(int,int,int,int);
/*
* plot a line; arguments are start and end x, y, intensity
*
* Display initialized on first call.
*/
extern void display_line(int,int,int,int,int);
/*
* force window system to output bits to screen;
* call after adding points, or aging the screen