Requires: Direct2D.lg32
Saves and restores a render target's transformation setting.
D2TransformSave D2TransformRestore
D2TransformSave saves the current transformation setting. D2TransformRestore restores the previously saved transformation setting. These commands should be within the D2BeginDraw and D2EndDraw commands. Saving and restoring the current (complex) setting will prevent the recalculation of a complex transformation later on. A D2TransformSave should always match a D2TransformRestore command, although D2BeginDraw resets D2TransformSave to the identity matrix.
'
' D2TransformSave/D2TransformRestore sample (dpi-unaware)
'
$Library "direct2d"
Global Object Win1RT
OpenW 1, 0, 0, 320, 300, ~15
Set Win1RT = D2GetRT()
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2BeginDraw Win1RT, D2C_White
' Show a rotation
D2DefLine 1 ' dotted line
D2ForeColor = D2C_Brown
D2TransformSave ' pushes current state to a stack
D2Text 40, 10, "Rotation"
D2Box 40, 40, 100, 100 ' original rectangle
D2Transform D2TF_ROTATE, 60, 70, 70 ' rotate 45 degrees around 70,70
D2DefLine 0 ' straight line
D2Box 40, 40, 100, 100 ' original rectangle, rotated
D2TransformRestore ' pops most recent state form stack
' Add an offset to restored state
D2TransformAdd D2TF_MOVE, 90, 0 ' Add offset (to restored matrix)
D2Text 40, 10, "Translated"
D2Box 40, 40, 100, 100 ' original rectangle
D2EndDraw
EndSub
Sub Win_1_ReSize
D2ResizeRT Win1RT, _X, _Y
D2TransformSave and D2TransformRestore call the ID2D1RenderTarget's transform methods. See D2Transform for more information.
D2Transform, D2TransformAdd, D2TransformOffset, D2GetRT, D2BeginDraw, D2EndDraw.
{Created by James Gaite; Last updated: 04/03/2021 by James Gaite}