BrushSetRotation

Syntax

Success = BrushSetRotation(Brush, Rotation.d, CenterPx.d, CenterPy.d)

Description

Sets the rotation angle and center point for the specified brush's transformation. The brush pattern (image or gradient) will be rotated around the specified center point when drawn.

Parameters

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

Rotation.d
The rotation angle in degrees (clockwise).

CenterPx.d, CenterPy.d
The coordinates (in DIPs relative to the brush's untransformed origin) around which the rotation should occur.

Return Value

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

Remarks

The rotation is applied in conjunction with scaling (BrushSetScale) and translation (BrushSetPosition). The `CenterPx` and `CenterPy` define the pivot point within the brush's own coordinate system before other transformations are applied. Use BrushReset() to reset all transformations, including rotation.

Example

IncludeFile "ProGUI_PB.pbi"

Global MyBrush, Angle.d

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
  DrawClear(RGB(240, 240, 240), 1)

  ; Draw using the rotated brush
  DrawBoxFill(50, 50, 300, 200, MyBrush)
EndProcedure

Procedure AnimationUpdate(Window, EventType, *EventData.PG_EventAnimate)
  Angle + 1
  If Angle >= 360 : Angle = 0 : EndIf
  ; Rotate the brush around its center (25, 25 for a 50x50 image)
  BrushSetRotation(MyBrush, Angle, 25, 25)
  WindowRedraw(Window)
EndProcedure

StartProGUI()

MyWindow = CreateWindow(0, 0, 400, 300, "Brush Rotation Animation")
MyImage = CreateImg(50, 50, RGB(0, 255, 0)) ; Green 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, BrushSetScale, BrushReset

Supported OS

Windows, Linux