Requires: Direct2D.lg32
Creates a polygon geometry.
Set geoObj = D2DefPoly( n, x(), y() [xOff,yOff] [,fWinding?] )
n | : iexp |
x(), y() | : avar floating-point array |
xOff, yOff | : floating-point expression |
fWinding? | : boolean exp |
geoObj | : Object |
D2DefPoly creates a geometry with connected lines with n corners. The 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. If the polygon is to be filled the fWinding? parameter can be use to specify the fillmode. The default filling mode is alternate, pass True to entirely fill the polygon. The return value is a Direct2D geometry object that can be drawn using D2DrawGeometry and/or D2FillGeometry in the rendering procedure (Form_Paint event). D2DrawGeometry draws the outlines of the polygon. 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. D2FillGeometry only draws the fill pattern, either the pattern set with D2DefFill or the optional fill brush.
Before using D2DrawGeometry and/or D2FillGeometry the polygon drawing position can be set using D2Transform(Add).
'
' 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
D2DefPoly is used to create and cache polygons before they are actually drawn. D2PolyLine can safely be used in the rendering procedure, but D2PolyFill creates a geometry on the fly each time. Geometries are device independent resources and are handled by the CPU rather than the GPU. They, therefore, lack a certain performance. It is better to create and cache (for the duration of the program) a geometry before it is drawn.
D2DrawGeometry, D2FillGeometry, D2PolyLine, D2PolyFill, D2PathGeometry, D2Sink_AddLines
{Created by Sjouke Hamstra; Last updated: 07/03/2021 by James Gaite}