TGSelector / TChooseGradient / TInk

Source: source/classes/tgselect.prg

TGSelector from TControl, TChooseGradient standalone dialog, TInk standalone

TGSelector is a gradient bar editor control that allows users to visually create and edit color gradients by adding, moving, and removing color stops ("inks") along a gradient bar. TChooseGradient provides a complete dialog wrapper around TGSelector with RGB sliders for precise color editing. TInk represents a single color stop within the gradient.

TGSelector

A TControl subclass that displays an interactive gradient bar with movable color stops.

Key DATA Members

DATATypeDescription
aInksArrayArray of TInk objects representing gradient color stops
aGradOutArrayOutput gradient array: { { nPercent, nColorStart, nColorEnd }, ... }
oInkOverObjectThe TInk currently under the mouse cursor
lChangedLogicalWhether the gradient has been modified
bSelectedCode blockEvaluated when an ink is selected
bChangedCode blockEvaluated when the gradient is modified
nMarginNumericLeft/right margin in pixels (default 10)

TGSelector Methods

MethodDescription
New( nTop, nLeft, nW, nH, oWnd, aInit )Create the gradient selector. aInit is an optional initial gradient array.
AddInk( nPct, nClr1, nClr2 )Add a new color stop at the given percentage with start/end colors
InsInk( n, nPct, nClr1, nClr2 )Insert a color stop at position n
SetColorInk( nClr )Change the color of the currently selected ink
BuildGradientArray()Build the output gradient array from current ink positions. Returns aGradOut.
BuildInkFromArray( aInit )Initialize inks from a gradient array

TChooseGradient

A complete modal dialog for editing gradients with visual feedback and RGB controls.

MethodDescription
New( aInit, bCode, bOnOK, bOnCancel )Open the gradient editor dialog. aInit is the initial gradient array. bCode is evaluated on change. bOnOK/bOnCancel are action blocks.

TInk

Represents a single color stop in the gradient.

DATATypeDescription
nPorcentClrNumericPercentage position along the gradient (0.0 to 1.0)
nColorStartNumericStart color (left side of the stop)
nColorEndNumericEnd color (right side of the stop)
lSelectedLogicalWhether this ink is currently selected
lMoveLogicalWhether the ink can be moved (false for boundary inks)
lFirstLogicalWhether this is the first (leftmost) ink in the gradient

Free Function

FunctionDescription
ChooseGradient( aInit ) --> aGradOutOpens the gradient picker dialog and returns the resulting gradient array. This is the simplest way to use the gradient editor.

Example

#include "FiveWin.ch"

function Main()

   local aGrad

   // Initial gradient: black to white
   local aInit := { { 1, 0, nRGB( 255, 255, 255 ) } }

   // Open the gradient picker dialog
   aGrad := ChooseGradient( aInit )

   if ! Empty( aGrad )
      // Use the gradient: e.g., fill a window background
      MsgInfo( "Gradient created with " + Str( Len( aGrad ) ) + " stops" )
   endif

return nil

Notes

See Also