Syntax
Success = BrushSetScale(Brush, ScaleX.d, ScaleY.d, CenterPx.d=0, CenterPy.d=0)
Description
Sets the horizontal and vertical scaling factors and the center point for the specified brush's transformation. The brush pattern (image or gradient) will be scaled relative to the specified center point when drawn.
Parameters
Brush
The handle of the brush whose scale is to be set.
ScaleX.d
The horizontal scaling factor. 1.0 means no scaling, 2.0 means double
width, 0.5 means half width.
ScaleY.d
The vertical scaling factor. 1.0 means no scaling.
CenterPx.d (optional)
The X coordinate (in DIPs relative to the brush's
untransformed origin) of the center point for scaling. Default is 0.
CenterPy.d (optional)
The Y coordinate (in DIPs relative to the brush's
untransformed origin) of the center point for scaling. Default is 0.
Return Value
Returns #True if the scale was successfully set, or #False if the brush handle
was invalid.
Remarks
Scaling is applied around the `CenterPx`, `CenterPy` coordinate within the brush's local space. This transformation is combined with translation (BrushSetPosition) and rotation (BrushSetRotation). Use BrushReset() to reset all transformations, including scale. The interpolation mode (BrushSetInterpolationMode) affects the quality of scaled image brushes.
Example
IncludeFile "ProGUI_PB.pbi"
Global MyBrush, ScaleFactor.d = 1.0, Dir = 1
Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
DrawClear(RGB(240, 240, 240), 1)
; Scale the brush around its center (25, 25 for a 50x50 image)
BrushSetScale(MyBrush, ScaleFactor, ScaleFactor, 25, 25)
DrawBoxFill(50, 50, 300, 200, MyBrush)
EndProcedure
Procedure AnimationUpdate(Window, EventType, *EventData.PG_EventAnimate)
ScaleFactor + (0.02 * Dir)
If ScaleFactor >= 2.0 Or ScaleFactor <= 0.5 : Dir * -1 : EndIf
WindowRedraw(Window)
EndProcedure
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Brush Scale Animation")
MyImage = CreateImg(50, 50, RGB(255, 0, 255)) ; Magenta square
BeginDraw(OutputImg(MyImage))
DrawBox(0, 0, 25, 50, RGB(255, 0, 0)) ; Red half
EndDraw()
If MyWindow And MyImage
MyBrush = CreateBrushImg(MyImage)
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, 0, 60) ; Animate at 60 FPS
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
FreeBrush(MyBrush)
EndIf
FreeImg(MyImage)
EndIf
StopProGUI()
See Also
BrushSetPosition, BrushSetRotation, BrushReset, BrushSetInterpolationMode
Supported OS
Windows, Linux