Requires: Direct2D.lg32
Draws and fills the outline of the specified geometry.
D2DrawGeometry geoObj [,D2Brush]
D2FillGeometry geoObj [,D2Brush] [,opacityD2Brush]
geoObj | : Geometry Object |
D2Brush, opacityD2Brush | : D2Brush Object |
D2DrawGeometry geoObj [,D2Brush] draws the outline of a geometry. The lines are drawn using the style and width set with D2DefLine and a solid color brush based on the current foreground color, or the color brush specified with the optional D2Brush.
D2FillGeometry geoObj [,D2Brush] fills the geometry (doesn't draw the outline) using the pattern defined by D2DefFill, or with the optional D2Brush. The D2Sink_BeginFigure command determines the fill behavior for D2FillGeometry; if it sets the figure to hollow D2FillGeometry won't fill the figure. Optionally, the application may specify an opacity brush, a D2Brush object created from a D2Bitmap using the D2Brush() function where fUseDef = True. See D2Brush topic.
These commands draw to the render target and are placed between D2BeginDraw and D2EndDraw commands.
To create a geometry see the D2PathGeometry() function.
'
' D2DrawGeometry/D2FillGeometry sample (dpi-unaware)
' GB32 implementation of
' https://docs.microsoft.com/en-us/windows/win32/Direct2D/how-to-draw-and-fill-a-complex-shape
'
' If you know how to draw the inner line, let me know: gfabasic32@gmail.com
'
$Library "direct2d"
Global Object Win1RT, geo, GrBrush
OpenW 1, 0, 0, 420, 360, ~15
Set Win1RT = D2GetRT() ' DC render target
' Create a pathgeometry and a gradientbrush for geometry
DefComplexGeo()
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2BeginDraw Win1RT, D2C_Wheat
D2Transform D2TF_MOVE, 100, 10' move it to 100,10
D2DefLine , 3 ' 3 dpi wide
D2FillGeometry geo, GrBrush ' gradient filling
D2DrawGeometry geo ' outline
D2EndDraw
EndSub
Sub Win_1_ReSize
D2ResizeRT Win1RT, _X, _Y
EndSub
Procedure DefComplexGeo() ' defines the hourglass
Local Object geoSink ' released when it goes out-of-scope
Local pt As D2D1_POINT_2F
Local bz As D2D1_BEZIER_SEGMENT
Set geo = D2PathGeometry() ' global, remeains in memory
Set geoSink = D2GeometrySink(geo)
D2Sink_BeginFigure geoSink, 0, 0 ' first point, D2FillGeometry will fill
' Add line
pt.x = 200, pt.y = 0
D2Sink_AddLine geoSink, pt
' Add bezier
bz.point1.x = 150, bz.point1.y = 50
bz.point2.x = 150, bz.point2.y = 150
bz.point3.x = 200, bz.point3.y = 200
D2Sink_AddBezier geoSink, bz
' Add line
pt.x = 0, pt.y = 200
D2Sink_AddLine geoSink, pt
' Add bezier
bz.point1.x = 50, bz.point1.y = 150
bz.point2.x = 50, bz.point2.y = 50
bz.point3.x = 0, bz.point3.y = 0
D2Sink_AddBezier geoSink, bz
D2Sink_EndFigure geoSink, D2D1_FIGURE_END_CLOSED
D2Sink_Close geoSink
' Create a GradientBrush for the complex shape
' the gradientbrush must have the 'same size' as the shape.
Local GS(1 .. 2) As D2Gradient ' the stop collection
GS(1).position = 0.0 ' beginning of gradient
GS(1).argbcolor = ARGB(0, 64, 255, 255) ' light blue
GS(2).position = 1.0 ' end of gradient is
GS(2).argbcolor = ARGB(0, 0, 0, 255) ' blue
' Create a gradientbrush that fits in the enclosing rectangle 0,0 - 200,200;
' threfor define axis's starting point (100,0) and endpoint (100,200).
Set GrBrush = D2BrushGradient(0, GS(), 2, 100, 0, 100, 200) ' gradient axis
EndProc
The example is a GFA-BASIC 32 implementation of the SDK example "How to draw and fill a complex shape" found at:
How to Draw and Fill a Complex Shape - Win32 apps | Microsoft Docs.
Note The GB example lacks the drawing of the inner line. If you know how to draw it, please let me know at gfabasic32@gmail.com.
These commands are wrappers for the following interface methods:
ID2D1RenderTarget::DrawGeometry (d2d1.h) - Win32 apps | Microsoft Docs;
ID2D1RenderTarget::FillGeometry (d2d1.h) - Win32 apps | Microsoft Docs.
D2Brush, D2BeginDraw, D2EndDraw, D2PathGeometry, D2Sink_BeginFigure, D2Sink_AddLine, D2Sink_AddBezier.
{Created by Sjouke Hamstra; Last updated: 11/03/2021 by James Gaite}