BrushSetExtendMode

Syntax

Success = BrushSetExtendMode(Brush, ExtendModeX, ExtendModeY)

Description

Sets how the content of an image or gradient brush is rendered outside its natural boundaries (the image dimensions or the 0.0-1.0 range for gradients) along the X and Y axes.

Parameters

Brush
The handle of the brush whose extend mode is to be set.

ExtendModeX
The extend mode to apply horizontally. Use one of the following constants:

#PG_Brush_ExtendMode_None  : (Clamping) The edge color/pixel is repeated indefinitely.
#PG_Brush_ExtendMode_Repeat: The brush pattern is tiled (repeated).
#PG_Brush_ExtendMode_Mirror: The brush pattern is tiled, with every other tile flipped (mirrored).
#PG_Brush_ExtendMode_Pad : (Cairo Only) Fills the area outside the brush with transparent black.

ExtendModeY
The extend mode to apply vertically. Uses the same constants as ExtendModeX.

Return Value

Returns #True if the extend mode was successfully set, or #False if the brush handle was invalid.

Remarks

This is particularly relevant for image brushes used to tile backgrounds or for gradients that don't cover the entire area being filled. The default behavior is typically clamping (`#PG_Brush_ExtendMode_None`). Note that `#PG_Brush_ExtendMode_Pad` might only be applicable when using the Cairo rendering backend.

Example

IncludeFile "ProGUI_PB.pbi"

Global MyBrush

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
  DrawClear(RGB(240, 240, 240), 1)
  ; Fill a larger area to see the extend modes in action
  DrawBoxFill(50, 50, 350, 100, MyBrush)
EndProcedure

StartProGUI()

MyWindow = CreateWindow(0, 0, 450, 200, "Brush Extend Modes")
MyImage = CreateImg(50, 50, RGB(0, 0, 255)) ; Blue square
BeginDraw(OutputImg(MyImage))
  DrawBox(5, 5, 40, 40, RGB(255, 255, 0)) ; Yellow inside
EndDraw()
  
If MyWindow And MyImage
  MyBrush = CreateBrushImg(MyImage)
  If MyBrush
    ; Set extend mode to repeat horizontally and mirror vertically
    BrushSetExtendMode(MyBrush, #PG_Brush_ExtendMode_Repeat, #PG_Brush_ExtendMode_Mirror)

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

    Repeat
        Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow

    FreeBrush(MyBrush)
  EndIf
FreeImg(MyImage)
EndIf

StopProGUI()

See Also

CreateBrushImg, CreateBrushGradientLinear, CreateBrushGradientRadial

Supported OS

Windows, Linux