DrawBoxFill

Syntax

DrawBoxFill(x.d, y.d, Width.d, Height.d, Brush, OpacityBrush=#Null)

Description

Draws a filled rectangle at the specified position and size using the provided brush. An optional opacity brush can be used to apply an alpha mask to the fill.

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.

Brush
The handle of the brush (created with CreateBrushImg(), CreateBrushGradientLinear(), etc.) used to fill the rectangle.

OpacityBrush (optional)
A brush handle (usually created from an image with an alpha channel) whose alpha channel acts as a mask for the main Brush. Default is #Null (no mask).

Return Value

This command does not return a value. It returns internally if Width, Height, or the Brush handle are invalid/zero.

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 appearance of the fill depends on the brush type (image, gradient) and its properties (position, scale, rotation, extend mode, opacity). If an OpacityBrush is provided, its alpha values modulate the opacity of the main Brush.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Create an image brush
Global MyImage = CreateImg(50, 50, RGB(200, 200, 255)) ; Light blue image
If BeginDraw(OutputImg(MyImage))
  DrawLine(0,0,50,50,RGB(0,0,0)) ; Draw a line on it
  EndDraw()
EndIf
Global ImageBrush = CreateBrushImg(MyImage)
BrushSetExtendMode(ImageBrush, #PG_Brush_ExtendMode_Repeat, #PG_Brush_ExtendMode_Repeat) ; Tile the image

; Create a gradient brush
Global GradientBrush = CreateBrushGradientLinear(0, 0, 0, 150, RGB(255, 0, 0), 1, RGB(0, 255, 0), 0.5) ; Red to semi-transparent green

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData)

    DrawClear(RGB(255, 255, 255), 1) ; White background

    ; Fill a box with the repeating image brush
    DrawBoxFill(20, 20, 150, 100, ImageBrush)

    ; Fill a box with the gradient brush
    DrawBoxFill(200, 20, 100, 150, GradientBrush)

EndProcedure

MyWindow = CreateWindow(0, 0, 350, 200, "DrawBoxFill Example")

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

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

FreeBrush(ImageBrush)
FreeBrush(GradientBrush)
FreeImg(MyImage)
StopProGUI()

See Also

DrawBox, DrawBoxStrokeFill, CreateBrushImg, CreateBrushGradientLinear, CreateBrushGradientRadial, BeginDraw, EndDraw

Supported OS

Windows, Linux