Syntax
Success = BrushSetImg(Brush, Img)
Description
Changes the image associated with an existing image brush. The brush will subsequently use the content of the new image when filling or stroking.
Parameters
Brush
The handle of the image brush (CreateBrushImg) to modify.
Img
The handle of the new ProGUI image object to associate with the brush.
Return Value
Returns #True if the image was successfully associated with the brush, or
#False if either handle was invalid or the brush was not an image brush.
Remarks
This function updates the internal graphics resources of the brush to use the new image. The reference count of the previously associated image is decremented (potentially freeing it via FreeImg), and the reference count of the new image is incremented. This is useful for changing textures or patterns dynamically without recreating the brush object itself.
Example
IncludeFile "ProGUI_PB.pbi"
Global MyBrush, Img1, Img2, CurrentImg
Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
DrawClear(RGB(240, 240, 240), 1)
DrawBoxFill(50, 50, 300, 200, MyBrush)
EndProcedure
Procedure AnimationUpdate(Window, EventType, *EventData.PG_EventAnimate)
Static toggle
toggle = 1 - toggle
If toggle
BrushSetImg(MyBrush, Img2)
Else
BrushSetImg(MyBrush, Img1)
EndIf
WindowRedraw(Window)
EndProcedure
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Switching Brush Image")
Img1 = CreateImg(50, 50, RGB(255, 0, 0)) ; Red
Img2 = CreateImg(50, 50, RGB(0, 0, 255)) ; Blue
If MyWindow And Img1 And Img2
MyBrush = CreateBrushImg(Img1) ; Start with Img1
If MyBrush
BrushSetExtendMode(MyBrush, #PG_Brush_ExtendMode_Repeat, #PG_Brush_ExtendMode_Repeat)
AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
AddEventHandler(MyWindow, #PG_Event_Animate, @AnimationUpdate())
StartAnimation(MyWindow, 1, 5000, 1) ; Animate for 5 seconds at 1 FPS
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
FreeBrush(MyBrush)
EndIf
FreeImg(Img1)
FreeImg(Img2)
EndIf
StopProGUI()
See Also
CreateBrushImg, CreateImg, LoadImg, FreeBrush, FreeImg
Supported OS
Windows, Linux