DrawLine

Syntax

DrawLine(x1.d, y1.d, x2.d, y2.d, Color.l, Opacity.f=1)

Description

Draws a line between two points using the specified color and opacity. The appearance of the line (width, dash style, caps) is determined by the current stroke settings defined by DrawSetStroke().

Parameters

x1.d
The horizontal coordinate of the line's starting point in device-independent pixels (DIPs).

y1.d
The vertical coordinate of the line's starting point in DIPs.

x2.d
The horizontal coordinate of the line's ending point in DIPs.

y2.d
The vertical coordinate of the line's ending point in DIPs.

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

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

Return Value

This command does not return a value.

Remarks

The coordinates are specified in DIPs but are converted internally to physical pixels based on the current output's DPI before drawing. The line is drawn using an internal solid color brush. Use DrawSetStroke() before calling this function to customize the line's appearance.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

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

    ; Draw a simple red diagonal line (default 1px stroke)
    DrawLine(10, 10, 110, 110, RGB(255, 0, 0))

    ; Set stroke to 4px wide, dotted
    DrawSetStroke(4, #PG_Stroke_Dot)
    ; Draw a thick dotted blue horizontal line with 50% opacity
    DrawLine(10, 130, 210, 130, RGB(0, 0, 255), 0.5)

    ; Restore default stroke
    DrawSetStroke(1)

EndProcedure

MyWindow = CreateWindow(0, 0, 230, 160, "DrawLine 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

DrawLineFill, DrawSetStroke, PathAddLine, BeginDraw, EndDraw, RGB()

Supported OS

Windows, Linux