D2Sink_AddLine and D2Sink_AddLines

Requires: Direct2D.lg32

Purpose

Add line or lines to the geometry sink object.

Syntax

D2Sink_AddLine geoSink, point2F
D2Sink_AddLines geoSink, arpoints2F(), countpoints

geoSink: Object created with D2GeometrySink()
point2F: var of D2D1_POINT_2F
arpoints2F: avar of D2D1_POINT_2F

Description

D2Sink_AddLine adds a line from the current position to the position in point2F (of type D2D1_POINT_2F).

D2Sink_AddLines adds lines from the points() array of type D2D1_POINT_2F to the sink object.

Example

'

' D2Sink_AddLines sample (dpi-unaware)

'

$Library "direct2d"

Global Object Win1RT, geoStar1, geoStar2

OpenW 1, 0, 0, 320, 260, ~15

Set Win1RT = D2GetRT()   ' DC render target

Set geoStar1 DefStarGeo(False)       ' alternate filling

Set geoStar2 DefStarGeo(True)        ' complete filling

Do

Sleep

Until Me Is Nothing

 

Sub Win_1_Paint

D2BeginDraw Win1RT, D2C_Wheat

D2Color D2C_CornflowerBlue    ' line color

' Draw star 1, draw outline only

D2DrawGeometry geoStar1

' Draw outline and alternate filled star 1

D2DefFill D2C_AntiqueWhite    ' fill color brush

D2Transform D2TF_MOVE, 100, 0

D2FillGeometry geoStar1       ' filling

D2DrawGeometry geoStar1       ' outline

' Draw outline and fully filled star 2

D2Transform D2TF_MOVE, 200, 0

D2FillGeometry geoStar2       ' filling

D2DrawGeometry geoStar2       ' outline

D2EndDraw

EndSub

 

Sub Win_1_ReSize

D2ResizeRT Win1RT, _X, _Y

EndSub

 

Function DefStarGeo(fWinding?) As Object

Local Object geo, geoSink

Local i%, x1!, y1!, x2!, y2!

Local pts1(0 .. 1) As D2D1_POINT_2F, pts2(0 .. 1) As D2D1_POINT_2F

Star:

Data 40,0, 70,50, 10,50

Data 10,20, 70,20, 40,70

Restore Star

Read x1!, y1!                 ' starting point #1

For i% = 0 To 1               ' next 2 points

Read pts1(i).x, pts1(i).y

Next

Read x2!, y2!                 ' starting point #2

For i% = 0 To 1               ' next 2 points

Read pts2(i).x, pts2(i).y

Next

Set geo = D2PathGeometry()

Set geoSink = D2GeometrySink(geo)

' FillMode determines how D2FillGeomtery fills the entire geometry.

' It has no impact on D2DrawGeometry.

D2Sink_FillMode geoSink, fWinding ? D2D1_FILL_MODE_WINDING : D2D1_FILL_MODE_ALTERNATE

' Add figure triangle #1

D2Sink_BeginFigure geoSink, x1!, y1! ' first point, D2FillGeometry will fill

' D2Sink_SegmentFlags geoSink, 1

D2Sink_AddLines geoSink, pts1(), 2

D2Sink_EndFigure geoSink, 1

' Add figure triangle #2

D2Sink_BeginFigure geoSink, x2!, y2! ' first point, D2FillGeometry will fill

D2Sink_AddLines geoSink, pts2(), 2

D2Sink_EndFigure geoSink, D2D1_FIGURE_END_CLOSED ' close end and start point

D2Sink_Close geoSink

Set DefStarGeo = geo

EndFunc

Remarks

These are wrappers for the following interface methods:

ID2D1GeometrySink::AddLine (d2d1.h) - Win32 apps ;

ID2D1SimplifiedGeometrySink::AddLines (d2d1.h) - Win32 apps.

See Also

D2PathGeometry, D2GeometrySink, D2DrawGeometry, D2FillGeometry, D2Sink_BeginFigure, D2Sink_EndFigure, D2Sink_Close, D2Sink_Fillmode, D2Sink_AddArc, D2Sink_AddBezier, D2Sink_AddQuadraticBezier.

{Created by Sjouke Hamstra; Last updated: 11/03/2021 by James Gaite}