BrushGradientLinearSetPoints

Syntax

Success = BrushGradientLinearSetPoints(Brush, StartX.d, StartY.d, EndX.d, EndY.d)

Description

Modifies the start and end points of an existing linear gradient brush, changing the direction and extent of the gradient.

Parameters

Brush
The handle of the existing linear gradient brush to modify.

StartX.d, StartY.d
The new coordinates (in DIPs relative to the drawing origin) for the starting point of the gradient line.

EndX.d, EndY.d
The new coordinates (in DIPs relative to the drawing origin) for the ending point of the gradient line.

Return Value

Returns #True if the points were successfully updated, or #False if the brush handle was invalid or not a linear gradient brush.

Remarks

This function allows dynamic changes to the gradient's orientation without recreating the entire brush object, which can be useful for animations or interactive effects. The color stops remain unchanged.

Example

IncludeFile "ProGUI_PB.pbi"

Global MyGradient

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
  Static angle.d = 0
  DrawClear(RGB(240, 240, 240), 1)

  ; Calculate new end points based on angle
  EndX.d = 150 + Cos(Radian(angle)) * 100
  EndY.d = 150 + Sin(Radian(angle)) * 100
  StartX.d = 150 - Cos(Radian(angle)) * 100
  StartY.d = 150 - Sin(Radian(angle)) * 100

  BrushGradientLinearSetPoints(MyGradient, StartX, StartY, EndX, EndY)

  DrawBoxFill(50, 50, 300, 200, MyGradient)
  angle = angle + 1 : If angle >= 360 : angle = 0 : EndIf
EndProcedure

Procedure AnimationUpdate(Window, EventType, *EventData.PG_EventAnimate)
  WindowRedraw(Window)
EndProcedure

StartProGUI()

MyWindow = CreateWindow(0, 0, 400, 300, "Rotating Gradient")

If MyWindow
  MyGradient = CreateBrushGradientLinear(50, 150, 250, 150, RGB(0, 0, 255), 1.0, RGB(0, 255, 0), 1.0) ; Initial Horizontal

  If MyGradient
    AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
    AddEventHandler(MyWindow, #PG_Event_Animate, @AnimationUpdate())
    StartAnimation(MyWindow) ; Start continuous animation

    WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

    Repeat
        Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow

    FreeBrush(MyGradient)
  EndIf
EndIf

StopProGUI()

See Also

CreateBrushGradientLinear, CreateBrushGradientLinearEx, FreeBrush

Supported OS

Windows, Linux