procedure tlineitem.draw(acanvas: tcanvas);
var
xa, ya, xb, yb: real;
d: real;
x1, y1, x0, y0: integer;
begin
acanvas.pen.style := pssolid;
acanvas.pen.color := clwhite;
//画直线
acanvas.moveto(ptstart.x, ptstart.y);
acanvas.lineto(ptend.x, ptend.y);
//画箭头
x0 := ptstart.x;//ptstart是箭头的起点,ptend是终点,都是tpoint型
y0 := ptstart.y;
x1 := ptend.x;
y1 := ptend.y;
d := sqrt((y1 - y0) * (y1 - y0) + (x1 - x0) * (x1 - x0));
if d > 0 then begin
xa := x1 + arrowlen * ((x0 - x1) + (y0 - y1) / 2) / d;
ya := y1 + arrowlen * ((y0 - y1) - (x0 - x1) / 2) / d;
xb := x1 + arrowlen * ((x0 - x1) - (y0 - y1) / 2) / d;
yb := y1 + arrowlen * ((y0 - y1) + (x0 - x1) / 2) / d;
acanvas.moveto(ptend.x, ptend.y);
acanvas.lineto(trunc(xa), trunc(ya));
acanvas.moveto(ptend.x, ptend.y);
acanvas.lineto(trunc(xb), trunc(yb));
end;
//如果选中画出焦点矩形,可以不要