Syntax
Brush = CreateBrushGradientRadialEx(CenterX.d, CenterY.d, OriginOffsetX.d, OriginOffsetY.d, RadiusX.d, RadiusY.d, *gradientStops.PG_GradientStop, gradientStopCount.i)
Description
Creates a radial gradient brush that blends multiple colors outwards from an origin point within an ellipse defined by a center point and radii. Color stops defining the colors, opacities, and positions are provided via an array of `PG_GradientStop` structures.
Parameters
CenterX.d, CenterY.d
The coordinates (in DIPs relative to the drawing origin) of
the center of the gradient ellipse.
OriginOffsetX.d, OriginOffsetY.d
The offset (in DIPs) of the gradient origin
relative to the `CenterX`, `CenterY`. The first color stop effectively begins at this origin point.
RadiusX.d, RadiusY.d
The horizontal and vertical radii (in DIPs) of the gradient
ellipse.
*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 radius (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 radial 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 radiating outwards from the origin. 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 ellipse. 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)
; No need to set position here as coordinates are absolute for the fill area
DrawBoxFill(0, 0, 400, 300, MyGradient)
EndProcedure
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Multi-Stop Radial Gradient")
If MyWindow
; Define the color stops for a target-like gradient
Dim MyStops.PG_GradientStop(2)
MyStops(0)\position = 0.0 : MyStops(0)\color = RGB(255, 0, 0) : MyStops(0)\opacity = 1.0 ; Red center
MyStops(1)\position = 0.5 : MyStops(1)\color = RGB(255, 255, 255) : MyStops(1)\opacity = 1.0 ; White ring
MyStops(2)\position = 1.0 : MyStops(2)\color = RGB(0, 0, 255) : MyStops(2)\opacity = 1.0 ; Blue edge
; Create a circular radial gradient centered at (200, 150) with radius 100
MyGradient = CreateBrushGradientRadialEx(200, 150, 0, 0, 100, 100, @MyStops(), 3)
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
CreateBrushGradientRadial, BrushGradientAddColor, BrushGradientRadialSetPoints, BrushSetExtendMode, DrawBoxFill, FreeBrush
Supported OS
Windows, Linux