Syntax
Brush = CreateBrushGradientLinear(StartX.d, StartY.d, EndX.d, EndY.d, StartColor.l, StartOpacity.f, EndColor.l, EndOpacity.f, StartPosition.f=0, EndPosition.f=1)
Description
Creates a linear gradient brush that blends colors along a straight line defined by start and end points. This version creates a simple two-color gradient. For more complex gradients with multiple colors, use CreateBrushGradientLinearEx() or add stops with BrushGradientAddColor().
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.
StartColor.l
The color (RGB value) at the start of the gradient.
StartOpacity.f
The opacity (0.0 to 1.0) at the start of the gradient.
EndColor.l
The color (RGB value) at the end of the gradient.
EndOpacity.f
The opacity (0.0 to 1.0) at the end of the gradient.
StartPosition.f (optional)
The relative position (0.0 to 1.0) along the gradient
line where the `StartColor` is fully opaque. Default is 0.0 (the very beginning).
EndPosition.f (optional)
The relative position (0.0 to 1.0) along the gradient
line where the `EndColor` is fully opaque. Default is 1.0 (the very end).
Return Value
Returns a handle to the newly created linear gradient brush object if successful, or #Null
if the brush could not be created.
Remarks
The gradient transitions between `StartColor` (at `StartPosition`) and `EndColor` (at `EndPosition`) along the line defined by (`StartX`, `StartY`) and (`EndX`, `EndY`). The extend mode (BrushSetExtendMode) determines how the gradient behaves outside the defined start and end points. The brush can be transformed using BrushSetPosition(), BrushSetScale(), and BrushSetRotation(). 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)
; Fill a rectangle using the gradient brush
DrawBoxFill(50, 50, 300, 200, MyGradient)
EndProcedure
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Linear Gradient Brush")
If MyWindow
; Create a horizontal gradient from blue (left) to green (right)
; The gradient line goes from x=50 to x=350 at y=0 (relative to where it's drawn)
MyGradient = CreateBrushGradientLinear(50, 0, 350, 0, RGB(0, 0, 255), 1.0, RGB(0, 255, 0), 1.0)
If MyGradient
; Set extend mode to repeat (optional)
; BrushSetExtendMode(MyGradient, #PG_Brush_ExtendMode_Repeat, #PG_Brush_ExtendMode_Repeat)
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
CreateBrushGradientLinearEx, BrushGradientAddColor, BrushGradientLinearSetPoints, BrushSetExtendMode, DrawBoxFill, FreeBrush
Supported OS
Windows, Linux