How to paint line according to line type

zhaozj2021-02-16  62

Under WinNT, you can create brush in the following way

Logbrush brush;

Brush.lbcolor = drawcolor;

Brush.lbstyle = BS_SOLID;

Mpen.createpen (PS_GEOMETRIC | PS_USERSTYLE | PS_ENDCAP_FLAT, (INT) LINEWIDE, & BrUSH, I, PENSTYLE

In WIN98, the appropriate pen width is set to DC, select the solid line, the following function can be drawn straight line according to the PenStyle array. If you draw a curve or a fold line, you need to discrete the curve into a straight segment. According to the last line return value, determine the starting value of this line, you can

#include "math.h"

DWORD PENSTYLE [16] = {0, 0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0, 0, 0, 0};

Typedef struct xyz {

Double X;

Double Y;

Double Z;

} XYZ, * PXYZ, ** PPXYZ;

// Painted a straight line from P1 points to P2 according to PenStyle []

//, for example, PenStyle [0] = 5, PENSTYLE [1] = 2 Indicates a line type line pattern formed by a spacing of a solid having a length of 5

// _____ _____ _______

/ / And specify where to draw from the line type, such as iStart = 6 starts from the second space at PenStyle [1]

// iStart value ranges from 0 to a total length of line type - 1

// Return value: The difference between the length of the line type and the remainder of the last line, indicating where the next picture should be specified from the beginning

INT Drawlinea (CDC * PDC, Point P1, Point P2, ISTART)

{

INT i = 0;

INT IEND = 0; // Return value, indicating the length of the last incomplete line segment

/ / Calculate the length of the line

Double DDistance = SQRT ((p2.x-p1.x) * (p2.x-p1.x) (p2.y-p1.y));

INT iLINETYPE = 0; // Leading length

IF (DDISTANCE <2)

{

For (i = 0; i <16; i )

{

IF (PenStyle [i] == 0) Break;

ILINETYPE = PenStyle [I];

}

IEND = (ISTART-DDISTANCE)% ILINETYPE;

IEND = ILINETYPE;

Return IEND;

}

Double DDLTX [16] = {0,0,0,0, // Each line type X distance

0, 0, 0, 0,

0, 0, 0, 0,

0,0,0,0};

Double DDLTY [16] = {0,0,0,0, // Each line type Y distance

0, 0, 0, 0,

0, 0, 0, 0,

0,0,0,0};

Double dxscale = (p2.x-p1.x) / ddistance; // x direction length and total length ratio

Double Dyscale = (P2.Y-P1.Y) / DDISTANCE; // Y direction length and total length ratio

// Calculate each line type X, Y distance and linear length

For (i = 0; i <16; i )

{

IF (PenStyle [i] == 0) Break;

DDLTX [I] = PenStyle [i] * dxscale;

DDLTY [I] = PenStyle [i] * dyscale;

ILINETYPE = PenStyle [I];

}

IEND = (INT (DDISTANCE ISTART))% ILINETYPE; IN (IEND <0) IEND = ILINETYPE;

XYZ PP = {0,0,0}; // The full line type start point before the first paragraph

PDC-> MoveTo (P1);

INT iLENGTH = -istart; // The length of the line segment has been drawn

pp.x = ingngthth * dxscale p1.x;

PP.Y = ILENGTH * DYSCALE P1.Y;

For (;;)

{

For (i = 0; i <16; i )

{

IF (PenStyle [i] == 0) Break;

PP.X = DDLTX [i];

PP.Y = DDLTY [I];

ilength = PenStyle [i];

IF (i% 2 == 0)

{

IF (ilength> 0)

{

If (iLength

{

PDC-> LineTo (pp.x, pp.y);

}

Else

{

PDC-> LineTo (P2);

Return IEND;

}

}

Else

{

IF (ilength> 0)

{

If (iLength

{

PDC-> MoveTo (pp.x, pp.y);

}

Else

{

PDC-> MoveTo (P2);

Return IEND;

}

}

}

}

}

Return IEND;

}

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

New Post(0)