Skip to content

Commit fe27bbe

Browse files
committed
display: Add display_line API for vector strokes.
1 parent f424080 commit fe27bbe

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

display/display.c

+66
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,72 @@ display_point(int x, /* 0..xpixels (unscaled) */
809809
return lx*lx + ly*ly <= scaled_pen_radius_squared;
810810
} /* display_point */
811811

812+
#define ABS(_X) ((_X) >= 0 ? (_X) : -(_X))
813+
#define SIGN(_X) ((_X) >= 0 ? 1 : -1)
814+
815+
static void
816+
xline (int x, int y, int x2, int dx, int dy, int level)
817+
{
818+
int ix = SIGN(dx);
819+
int iy = SIGN(dy);
820+
int ay;
821+
822+
dx = ABS(dx);
823+
dy = ABS(dy);
824+
825+
ay = dy/2;
826+
for (;;) {
827+
display_point (x, y, level, 0);
828+
if (x == x2)
829+
break;
830+
if (ay > 0) {
831+
y += iy;
832+
ay -= dx;
833+
}
834+
ay += dy;
835+
x += ix;
836+
}
837+
}
838+
839+
static void
840+
yline (int x, int y, int y2, int dx, int dy, int level)
841+
{
842+
int ix = SIGN(dx);
843+
int iy = SIGN(dy);
844+
int ax;
845+
846+
dx = ABS(dx);
847+
dy = ABS(dy);
848+
849+
ax = dx/2;
850+
for (;;) {
851+
display_point (x, y, level, 0);
852+
if (y == y2)
853+
break;
854+
if (ax > 0) {
855+
x += ix;
856+
ax -= dy;
857+
}
858+
ax += dx;
859+
y += iy;
860+
}
861+
}
862+
863+
void
864+
display_line(int x1, /* 0..xpixels (unscaled) */
865+
int y1, /* 0..ypixels (unscaled) */
866+
int x2, /* 0..xpixels (unscaled) */
867+
int y2, /* 0..ypixels (unscaled) */
868+
int level) /* DISPLAY_INT_xxx */
869+
{
870+
int dx = x2 - x1;
871+
int dy = y2 - y1;
872+
if (ABS (dx) > ABS(dy))
873+
xline (x1, y1, x2, dx, dy, level);
874+
else
875+
yline (x1, y1, y2, dx, dy, level);
876+
} /* display_line */
877+
812878
/*
813879
* calculate decay color table for a phosphor mixture
814880
* must be called AFTER refresh_rate initialized!

display/display.h

+7
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ extern int display_is_blank(void);
112112
*/
113113
extern int display_point(int,int,int,int);
114114

115+
/*
116+
* plot a line; arguments are start and end x, y, intensity
117+
*
118+
* Display initialized on first call.
119+
*/
120+
extern void display_line(int,int,int,int,int);
121+
115122
/*
116123
* force window system to output bits to screen;
117124
* call after adding points, or aging the screen

0 commit comments

Comments
 (0)