BrushSetPosition

Syntax

Success = BrushSetPosition(Brush, x.d, y.d)

Description

Sets the translation offset for the specified brush. This affects where the brush pattern (image or gradient) begins relative to the origin of the shape being filled or stroked.

Parameters

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

x.d
The horizontal offset (in DIPs) to apply to the brush pattern.

y.d
The vertical offset (in DIPs) to apply to the brush pattern.

Return Value

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

Remarks

By default, brushes are positioned at (0,0) relative to the drawing operation. Setting the position effectively shifts the starting point of the brush pattern. This is combined with scaling (BrushSetScale) and rotation (BrushSetRotation) transformations. Use BrushReset() to reset all transformations.

Example

IncludeFile "ProGUI_PB.pbi"

Global MyBrush, OffsetX.d = 0

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

  ; Shift the brush pattern horizontally
  BrushSetPosition(MyBrush, OffsetX, 0)

  DrawBoxFill(50, 50, 300, 200, MyBrush)
EndProcedure

Procedure AnimationUpdate(Window, EventType, *EventData.PG_EventAnimate)
  OffsetX = OffsetX + 1
  If OffsetX > 50 : OffsetX = -50 : EndIf ; Wrap offset
  WindowRedraw(Window)
EndProcedure

StartProGUI()

MyWindow = CreateWindow(0, 0, 400, 300, "Brush Position Animation")
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
    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, 30) ; Animate at 30 FPS

    WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

    Repeat
        Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow

    FreeBrush(MyBrush)
  EndIf
  FreeImg(MyImage)
EndIf

StopProGUI()

See Also

BrushSetScale, BrushSetRotation, BrushReset

Supported OS

Windows, Linux