DrawRoundBox

Syntax

DrawRoundBox(x.d, y.d, Width.d, Height.d, RadiusX.d, RadiusY.d, Color.l, Opacity.f=1, NoRadiusDPIScaling.b=#False)

Description

Draws a solid-filled rectangle with rounded corners at the specified position and size using the given color and opacity. The roundness is defined by horizontal (RadiusX) and vertical (RadiusY) radii.

Parameters

x.d
The horizontal coordinate of the rectangle's top-left corner in device-independent pixels (DIPs).

y.d
The vertical coordinate of the rectangle's top-left corner in DIPs.

Width.d
The width of the rectangle in DIPs.

Height.d
The height of the rectangle in DIPs.

RadiusX.d
The horizontal radius for the corners in DIPs. This value is clamped internally so it cannot exceed half the rectangle's width.

RadiusY.d
The vertical radius for the corners in DIPs. This value is clamped internally so it cannot exceed half the rectangle's height.

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.

NoRadiusDPIScaling.b (optional)
If set to #True, the RadiusX and RadiusY values are treated as physical pixels and are not scaled by the current DPI. Default is #False (radii are treated as DIPs and scaled).

Return Value

This command does not return a value. It returns internally if Width, Height, or Opacity are zero or less.

Remarks

The coordinates, dimensions, and radii (unless NoRadiusDPIScaling is #True) are specified in DIPs but are converted internally to physical pixels based on the current output's DPI before drawing. The function uses an internal solid color brush. If RadiusX or RadiusY are zero or negative, a standard rectangle (like DrawBox()) might be drawn.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

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

    ; Draw a rounded box with equal radii (pill shape horizontally)
    DrawRoundBox(20, 20, 150, 60, 30, 30, RGB(255, 0, 0))

    ; Draw a rounded box with different radii and semi-opacity
    DrawRoundBox(20, 100, 150, 80, 20, 40, RGB(0, 0, 255), 0.7)

    ; Draw a box with only top-left corner rounded (approximated)
    ; Note: ProGUI doesn't directly support individual corner radii for DrawRoundBox variants.
    ; This example shows using small radii for other corners.
    ; Use Path commands or Borders for precise per-corner control.
    DrawRoundBox(200, 20, 100, 100, 50, 50, RGB(0, 128, 0), 1) ; This will round all corners equally

EndProcedure

MyWindow = CreateWindow(0, 0, 330, 200, "DrawRoundBox 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

DrawRoundBoxFill, DrawRoundBoxStroke, DrawBox, BeginDraw, EndDraw

Supported OS

Windows, Linux