Syntax
DrawBox(x.d, y.d, Width.d, Height.d, Color.l, Opacity.f=1)
Description
Draws a solid-filled rectangle at the specified position and size using the given color and opacity.
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.
Color.l
The color of the rectangle in RGB format (e.g., using
RGB(r, g, b)).
Opacity.f (optional)
The opacity of the rectangle, ranging from 0.0 (fully
transparent) to 1.0 (fully opaque). Default is 1.0.
Return Value
This command does not return a value. It returns internally if Width, Height, or Opacity are zero or less.
Remarks
The coordinates and dimensions are specified in DIPs but are converted internally to physical pixels based on the current output's DPI and aligned to the pixel grid before drawing. The function uses an internal solid color brush for efficiency.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData)
DrawClear(RGB(255, 255, 255), 1) ; White background
; Draw a solid red box
DrawBox(20, 20, 100, 80, RGB(255, 0, 0))
; Draw a semi-transparent blue box overlapping the red one
DrawBox(70, 50, 100, 80, RGB(0, 0, 255), 0.5)
EndProcedure
MyWindow = CreateWindow(0, 0, 250, 150, "DrawBox 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
DrawBoxFill, DrawBoxStroke, DrawRoundBox, BeginDraw, EndDraw, RGB()
Supported OS
Windows, Linux