Requires: Direct2D.lg32
Sets the brush to be used for filling with drawing commands.
D2DefFill [argbCol | D2Brush]
argbCol | : integer expression |
D2Brush | : Object expression |
D2DefFill defines the brush used to draw and fill the interior of D2PBox, D2PRBox, D2PCircle, and D2PEllipse.
Using D2DefFill without passing an argument will create a solid color brush based on the current foreground color set with D2Color, D2RGBColor, or D2ForeColor. When argbCol is specified a solid color brush is based on the ARGB color passed.
When D2DefFill is passed a Direct2D brush the interiors are filled with that brush object.
The current D2DefFill brush is discarded (reset) in D2EndDraw.
'
' D2DefFill sample (dpi-unaware)
'
$Library "direct2d"
Global Object Win1RT
OpenW 1, 0, 0, 320, 260, ~15
Set Win1RT = D2GetRT(Me.hWnd, _X, _Y)
' Here: Create Win_1 render target resources
Global Object BrChoc, BrHatch
Set BrChoc = D2Brush(D2C_Chocolate)
Set BrHatch = D2Brush("Hatch0.bmp")
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2BeginDraw Win1RT, D2C_White
D2DefFill BrChoc ' use D2Brush object
D2PBox 0, 0, 100, 100
D2DefFill D2C_Beige ' creates a solid color brush
D2PBox 50, 50, 150, 150
D2ForeColor = D2C_CornflowerBlue
D2DefFill ' brush based on foreground color
D2PBox 100, 100, 200, 200
D2DefFill BrHatch ' use hatch brush
D2PBox 150, 150, 250, 250
D2EndDraw
EndSub
D2DefFill is only partly compatible with DefFill because it doesn't support predefined patterns. However, you can easily create a 8x8 pixel bitmap using MS Paint which can than be stored in the :Files section of the GB32 program. The bitmap can be loaded and converted to a D2Brush with the D2Brush() function.
The drawing commands require a D2Brush for drawing the shapes interior. The creation of a D2Brush solid color brush is a relative cheap operation. A solid color brush object is created by invoking ID2D1RenderTarget::CreateSolidColorBrush.
In general, a bitmap brush is best created using the D2Brush() function in the resource intialization part. The brush is stored on the GPU and remains for the live of the application. In addition, a brush should be created with the coordinates of the shape it is used for. This is less important if the brush is a simple pattern, as you might want to use to be compatible with GFA-BASIC's DefFill command.
D2DefFill must be placed between the D2BeginDraw and D2EndDraw commands.
D2DefLine, D2Brush, D2BrushGradient, D2PBox, D2PRBox, D2PCircle, D2PEllipse.
{Created by Sjouke Hamstra; Last updated: 21/03/2020 by James Gaite}