How to draw a straight line with arrows in Delphi (changed from a VB code of the online forum moderator)

xiaoxiao2021-03-06  63

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;

// Painted straight line

Acanvas.moveto (Ptstart.x, Ptstart.y);

Acanvas.lineto (Ptend.x, Ptend.y);

// Painted arrows

X0: = ptstart.x; // ptstart is the starting point of the arrow, Ptend is the end, all TPOINT type

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;

// If you select a focus rectangle, you can

IF fselected = true kilin

Acanvas.Rectangle (Ptstart.x - forcusRange),

(Ptstart.y - forcusrange),

(Ptstart.x forcusRange),

(PTStart.y forcusrange))));

Acanvas.Rectangle (Ptend.x - forcusRange),

(Ptend.y - forcusrange),

(Ptend.x forcusrange),

(Ptend.y forcusrange));

END;

END;

Canvas is any Canvas with a component with a brush. The specific geometry is not explained by the original author. However, after the bottom check. There are three characteristics.

1. Arrow two-wing endpoints and straight lines vertical (the gum of slope is equal to -1).

2. The length of the arrow is the same length. (Equal waist triangle)

3. Arrow two wings lengths and distance ratios between the two-wing ends. (Determined angle)

转载请注明原文地址:https://www.9cbs.com/read-85166.html

New Post(0)