Syntax
Success = BrushGradientAddColor(Brush, Position.f, Color.l, Opacity.f)
Description
Adds an intermediate color stop to an existing linear or radial gradient brush. This allows for creating gradients with more than two colors.
Parameters
Brush
The handle of the existing linear or radial gradient brush to modify.
Position.f
The relative position (0.0 to 1.0) along the gradient line (for
linear) or radius (for radial) where this color stop should be placed.
Color.l
The color (RGB value) for this stop.
Opacity.f
The opacity (0.0 to 1.0) for this stop.
Return Value
Returns #True if the color stop was successfully added, or #False if the brush
handle was invalid or not a gradient brush.
Remarks
This function modifies the existing gradient brush by adding a new color transition point. The underlying graphics resources for the brush are typically recreated. Positions should ideally be added in increasing order, although the underlying system might sort them. Adding stops allows for complex color blends.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
Global MyGradient
Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
DrawClear(RGB(240, 240, 240), 1)
DrawBoxFill(50, 50, 300, 200, MyGradient)
EndProcedure
MyWindow = CreateWindow(0, 0, 400, 300, "Adding Gradient Stops")
If MyWindow
; Create a simple 2-color gradient first
MyGradient = CreateBrushGradientLinear(50, 0, 350, 0, RGB(255, 0, 0), 1.0, RGB(0, 0, 255), 1.0) ; Red to Blue
If MyGradient
; Add a yellow stop in the middle
BrushGradientAddColor(MyGradient, 0.5, RGB(255, 255, 0), 1.0)
; Add a cyan stop
BrushGradientAddColor(MyGradient, 0.8, RGB(0, 255, 255), 0.7) ; Semi-transparent cyan
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, CreateBrushGradientLinearEx, CreateBrushGradientRadial, CreateBrushGradientRadialEx, FreeBrush
Supported OS
Windows, Linux