DrawRestore

Syntax

DrawRestore()

Description

Restores the drawing state (including transformations, clipping regions, layers, anti-alias mode, blend mode, stroke settings, and current path) that was previously saved by the most recent call to DrawSave() within the current drawing context.

Parameters

This command takes no parameters.

Return Value

This command does not return a value.

Remarks

Every call to DrawSave() should be matched by a call to DrawRestore() to avoid leaving the drawing context in an unexpected state. It effectively pops the last saved state off an internal stack.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData)
  
    DrawClear(RGB(255, 255, 255), 1)

    ; Draw an initial blue box
    DrawBox(10, 10, 50, 50, RGB(0, 0, 255))

    ; Save the current state (default transform, no clip)
    DrawSave()

    ; Apply a transformation (translate) and clipping
    SetTranslation(70, 70) ; Move origin
    BeginClipBox(0, 0, 100, 100) ; Clip relative to new origin
    DrawBox(0, 0, 150, 150, RGB(255, 0, 0)) ; Draw red box (clipped)

    EndClip() ; Remove clip applied *within* the saved state

    ; Restore the state saved before translation and clipping
    DrawRestore()

    ; Draw another blue box - should appear at (10, 70) because
    ; the coordinate system is back to what it was before DrawSave()
    DrawBox(10, 70, 50, 50, RGB(0, 0, 255))

EndProcedure

MyWindow = CreateWindow(0, 0, 250, 250, "DrawSave/Restore Example")

If MyWindow
  AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

StopProGUI()

See Also

DrawSave, BeginDraw, EndDraw, SetTranslation, BeginClipBox, EndClip

Supported OS

Windows, Linux