Requires: Direct2D.lg32
Draws a line in the the render target's drawing area.
D2Line x1!, y1!, x2!, y2! [,D2Brush]
x1!, y!, x2!, y2! | : float expression |
D2Brush | : Object expression |
Draws a line from x1,y1 to x2,y2 in device-independent pixels. By default, the line is drawn using a solid color brush created from the current foreground color D2ForeColor. If the application passes a D2Brush object, the stroke (line) is painted with that brush.
Use D2DefLine to alter the style and/or the width of the line.
'
' D2Line sample (dpi-unaware)
'
$Library "direct2d"
Global Object Win1RT
Global Float xLine = -1, yLine = -1
OpenW 1, 0, 0, 320, 260, ~15
Set Win1RT = D2GetRT() ' DC render target
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
Win1Render
EndSub
Sub Win1Render()
D2BeginDraw Win1RT, D2C_Wheat
D2Line xLine, 0, xLine, _Y
D2Line 0, yLine, _X, yLine
D2EndDraw
EndSub
Sub Win_1_ReSize
D2ResizeRT Win1RT, _X, _Y
Sub Win_1_MouseMove(Button&, Shift&, x!, y!)
xLine = x!
yLine = y!
Win1Render
EndSub
Sub Win_1_MessageProc(hWnd%, Mess%, wParam%, lParam%, retval%, ValidRet?)
If Mess% == WM_SETCURSOR ' set the mousecursor
If LoWord(lParam%) == HTCLIENT
~SetCursor(0) ' hide cursor
retval% = 1, ValidRet? = True
Else ' mouse left clientarea
xLine = -1 ' move lines outside
yLine = -1 ' the clientarea
Win1Render ' redraw render target
EndIf
EndIf
EndSub
Below is a second example, using a pre-defined form
'
' D2LineFrm sample
'
$Library "direct2d"
Global Object frm1RT
Global Float xLine = -1, yLine = -1
LoadForm frm1
Do
Sleep
Until Me Is Nothing
Sub frm1_Load
Set frm1RT = D2GetRT(Me.hWnd, _X, _Y)
Sub frm1_Paint
frm1Render
EndSub
Sub frm1_ReSize
D2ResizeRT frm1RT, _X, _Y
Sub frm1_MouseMove(Button&, Shift&, x!, y!)
xLine = x!
yLine = y!
frm1Render
EndSub
Sub frm1Render()
D2BeginDraw frm1RT, D2C_Wheat
D2Line xLine, 0, xLine, _Y
D2Line 0, yLine, _X, yLine
D2EndDraw
EndSub
Sub frm1_MessageProc(hWnd%, Mess%, wParam%, lParam%, retval%, ValidRet?)
If Mess% == WM_SETCURSOR ' set the mousecursor
If LoWord(lParam%) == HTCLIENT
~SetCursor(0) ' hide cursor
retval% = 1, ValidRet? = True
Else ' mouse left clientarea
xLine = -1 ' move lines outside
yLine = -1 ' the clientarea
frm1Render ' redraw render target
EndIf
EndIf
EndSub
NOTE: The above example will not run correctly as it relies on an embedded file which is not present in the syntax. The programme with full resources can be found in GFABASIC/Samples/Direct2D/D2LineFrm.G32.
Requires an active render target, either set with D2BeginDraw or D2SetRT.
All drawing commands must be placed between D2BeginDraw and D2EndDraw.
D2Box, D2PBox, D2RBox, D2PRBox, D2SetRT, D2ForeColor, D2Brush, D2BeginDraw
{Created by Sjouke Hamstra; Last updated: 19/03/2021 by James Gaite}