Requires: Direct2D.lg32
Draws a (filled) polygon in the current render target.
D2PolyLine n, x(), y() [xOff,yOff] [,D2Brush]
D2PolyFill n, x(), y() [xOff,yOff] [,fWinding?] [,D2Brush]
n | : integer expression |
x(), y():avar | : floating-point array |
xOff, yOff | : floating-point expression |
fWinding? | : boolean expression |
D2Brush | : Object |
D2PolyLine n, x(),y() draws connected lines with n corners. The x,y coordinates of the corner points are in arrays x() and y(). The first corner point is defined in x(0),y(0) and the last in x(n-1),y(n-1). The first and last corner points are automatically connected.
Optionally, a horizontal and/or vertical offset (xOff or yOff) can be added to these coordinates. However, the drawing position is according to the current transform setting.
The lines are drawn using the style and width set with D2DefLine and a solid color brush based on the foreground color or the color brush specified with the optional D2Brush.
D2Polyfill works in the same way and fills the drawn polygon with the pattern defined by D2DefFill or the with the optional D2Brush. The outline of the polygon will be drawn using a solid color brush based on the current foreground color.
The fWinding? parameter specifies the D2PolyFill's fill mode, default is alternate mode (fWinding? = False), the same fill mode as GB's PolyFill uses. By passing True for fWinding? the polygon will be filled entirely. The drawing position is according to the current transform setting.
Rather than drawing a polygon directly you could use D2DefPoly to cache a polygon geometry and draw the geometry using D2DrawGeometry or D2FillGeometry. The examples show both methods (D2Poly* and D2DefPoly).
The polygon drawing position can be set using D2Transform(Add).
D2Polyline:
'
' D2PolyLine/D2DefPoly sample (dpi-unaware)
'
$Library "direct2d"
Global Object Win1RT, geoPoly
Global Float x(2), y(2)
// Define a triangle
Data 120,120,170,170,70,170
Local i%
For i% = 0 To 2
Read x(i%), y(i%)
Next i%
OpenW 1, 0, 0, 320, 260, ~15
Set Win1RT = D2GetRT() ' DC render target
Set geoPoly = D2DefPoly(3, x(), y())
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2BeginDraw Win1RT, D2C_Wheat
D2Color D2C_DarkBlue ' color of the line
D2PolyLine 3, x(), y() ' draw triangle
D2Transform D2TF_MOVE, 100, 0 ' translate 100, 0
D2DrawGeometry geoPoly ' draw geometry
D2EndDraw
EndSub
Sub Win_1_ReSize
D2ResizeRT Win1RT, _X, _Y
EndSub
D2PolyFill:
'
' D2PolyFill/D2DefPoly sample (dpi-unaware)
' Defines a star.
$Library "direct2d"
Global Object Win1RT, pf1
Global Float x(4), y(4) ' Draw a triangle
Data 0,30, 50, 110, 40,10, 0,90, 70,60
Local i%
For i% = 0 To 4
Read x(i%), y(i%)
Next i%
OpenW 1, 0, 0, 320, 260, ~15
Set Win1RT = D2GetRT() ' DC render target
' Define a global polygon geometry with an offset (130,0)
Set pf1 = D2DefPoly( 5, x(), y(), 130, 0) ' alternate filled (default)
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2BeginDraw Win1RT, D2C_Wheat
D2DefFill D2C_AliceBlue ' solid color brush
D2PolyFill 5, x(), y(), , , True ' entirely fills polygon
D2DefLine , 0 ' no outline
D2PolyFill 5, x(), y(), 0, 100 ' alternate filling
D2DefLine ' restore to default, solid and 1 dpi
' Use a D2DefPoly geometry
D2FillGeometry pf1 ' interior of polygon
D2DrawGeometry pf1 ' polygon outline
D2EndDraw
EndSub
Sub Win_1_ReSize
D2ResizeRT Win1RT, _X, _Y
EndSub
The D2PolyLine command draws lines directly on the rendertarget and performs as fast as D2Line. On the other hand, the D2PolyFill command creates a geometry on the fly and draws the polygon in the geometry. Geometries are device independent resources and suffer from a lack of performance. When an application uses more than only a few filled polygons it is advised to use D2DefPoly to cache the geometries.
D2DefPoly, D2Transform, D2TransformAdd, D2PathGeometry, D2Sink_AddLines.
{Created by James Gaite; Last updated: 04/03/2021 by James Gaite}