CreateBrushGradientLinearEx

Syntax

Brush = CreateBrushGradientLinearEx(StartX.d, StartY.d, EndX.d, EndY.d, *gradientStops.PG_GradientStop, gradientStopCount.i)

Description

Creates a linear gradient brush that blends multiple colors along a straight line defined by start and end points. Color stops defining the colors, opacities, and positions are provided via an array of `PG_GradientStop` structures.

Parameters

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

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

*gradientStops.PG_GradientStop
A pointer to the first element of an array of `PG_GradientStop` structures. Each structure defines a color, opacity, and position for a stop in the gradient.

gradientStopCount.i
The number of elements in the `*gradientStops` array.

The PG_GradientStop structure has the following fields:

Structure PG_GradientStop
  position.f ; Position along the gradient line (0.0 to 1.0)
  color.l ; RGB color value for this stop
  opacity.f ; Opacity for this stop (0.0 to 1.0)
EndStructure

Return Value

Returns a handle to the newly created linear gradient brush object if successful, or #Null if the brush could not be created (e.g., invalid parameters).

Remarks

The gradient transitions smoothly between the specified color stops along the line defined by (`StartX`, `StartY`) and (`EndX`, `EndY`). The `position` field in `PG_GradientStop` must be between 0.0 and 1.0, inclusive, and the stops should generally be ordered by position. The extend mode (BrushSetExtendMode) determines behavior outside the 0.0-1.0 range. The brush can be transformed. Remember to free the brush using FreeBrush().

Example

IncludeFile "ProGUI_PB.pbi"

Global MyGradient

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
  DrawClear(RGB(240, 240, 240), 1)
  DrawBoxFill(50, 50, 300, 200, MyGradient)
EndProcedure

StartProGUI()

MyWindow = CreateWindow(0, 0, 400, 300, "Multi-Stop Linear Gradient")

If MyWindow
  ; Define the color stops for a rainbow-like gradient
  Dim MyStops.PG_GradientStop(3)
  MyStops(0)\position = 0.0 : MyStops(0)\color = RGB(255, 0, 0) : MyStops(0)\opacity = 1.0 ; Red
  MyStops(1)\position = 0.3 : MyStops(1)\color = RGB(255, 255, 0) : MyStops(1)\opacity = 1.0 ; Yellow
  MyStops(2)\position = 0.7 : MyStops(2)\color = RGB(0, 255, 0) : MyStops(2)\opacity = 1.0 ; Green
  MyStops(3)\position = 1.0 : MyStops(3)\color = RGB(0, 0, 255) : MyStops(3)\opacity = 1.0 ; Blue

  ; Create a vertical gradient from top (y=50) to bottom (y=250)
  MyGradient = CreateBrushGradientLinearEx(0, 50, 0, 250, @MyStops(), 4)

  If MyGradient
    
    AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
    WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

    Repeat
        Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow

    FreeBrush(MyGradient) ; Free the brush

  EndIf
EndIf

StopProGUI()

See Also

CreateBrushGradientLinear, BrushGradientAddColor, BrushGradientLinearSetPoints, BrushSetExtendMode, DrawBoxFill, FreeBrush

Supported OS

Windows, Linux