DrawPath

Syntax

DrawPath(Color.l, Opacity.f=1, Flags=#Null)

Description

Fills the shape defined by the current path using the specified solid color and opacity. The path must define a closed shape (implicitly or explicitly via PathClose()) for the fill to be meaningful.

Parameters

Color.l
The fill color in RGB format (e.g., using RGB(r, g, b)).

Opacity.f (optional)
The opacity of the fill, ranging from 0.0 (fully transparent) to 1.0 (fully opaque). Default is 1.0.

Flags (optional)
Flags modifying the behavior:

#PG_Path_Preserve : Keeps the path geometry defined after this drawing command is executed. Without this flag, the path is consumed and reset.
#PG_Path_Winding  : Uses the winding fill mode to determine which areas are inside the path (useful for complex self-intersecting paths). Default is alternate fill mode.

Return Value

This command does not return a value. It returns internally if Opacity is zero or less, or if the path is empty.

Remarks

This function must be called between BeginDraw() and EndDraw(), after defining a path using commands like PathMoveTo(), PathAddLine(), etc. It uses an internal solid color brush. To fill with gradients or images, use DrawPathFill(). By default, the path geometry is cleared after drawing; use #PG_Path_Preserve if you need to draw the same path again (e.g., stroke it afterwards).

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

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

    ; Define a star-like path
    PathMoveTo(100, 10)
    PathAddLine(130, 80)
    PathAddLine(200, 80)
    PathAddLine(140, 130)
    PathAddLine(170, 200)
    PathAddLine(100, 150)
    PathAddLine(30, 200)
    PathAddLine(60, 130)
    PathAddLine(0, 80)
    PathAddLine(70, 80)
    PathClose()

    ; Fill the path with semi-transparent red
    DrawPath(RGB(255, 0, 0), 0.7, #PG_Path_Preserve | #PG_Path_Winding) ; Preserve path for stroke

    ; Stroke the same path in blue
    DrawSetStroke(2)
    DrawPathStroke(RGB(0, 0, 255)) ; Path was preserved

    DrawSetStroke(1)
EndProcedure

MyWindow = CreateWindow(0, 0, 220, 220, "DrawPath 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

DrawPathFill, DrawPathStroke, PathMoveTo, PathAddLine, PathClose, BeginDraw, EndDraw

Supported OS

Windows (Direct2D only), Linux (Cairo only)