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
| DATA | Type | Description |
|---|---|---|
aInks | Array | Array of TInk objects representing gradient color stops |
aGradOut | Array | Output gradient array: { { nPercent, nColorStart, nColorEnd }, ... } |
oInkOver | Object | The TInk currently under the mouse cursor |
lChanged | Logical | Whether the gradient has been modified |
bSelected | Code block | Evaluated when an ink is selected |
bChanged | Code block | Evaluated when the gradient is modified |
nMargin | Numeric | Left/right margin in pixels (default 10) |
TGSelector Methods
| Method | Description |
|---|---|
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.
| Method | Description |
|---|---|
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.
| DATA | Type | Description |
|---|---|---|
nPorcentClr | Numeric | Percentage position along the gradient (0.0 to 1.0) |
nColorStart | Numeric | Start color (left side of the stop) |
nColorEnd | Numeric | End color (right side of the stop) |
lSelected | Logical | Whether this ink is currently selected |
lMove | Logical | Whether the ink can be moved (false for boundary inks) |
lFirst | Logical | Whether this is the first (leftmost) ink in the gradient |
Free Function
| Function | Description |
|---|---|
ChooseGradient( aInit ) --> aGradOut | Opens 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
- The
ChooseGradient()function is the simplest entry point -- it opens a full dialog with RGB sliders, a color panel, and OK/Cancel buttons, then returns the resulting gradient array. - The gradient output array format is
{ { nPercent, nColorStart, nColorEnd }, ... }, which is directly usable byGradientFill()and other gradient drawing functions. - Right-clicking an interior ink removes it (merges its space with neighbors).
- Double-clicking an ink opens the Windows color picker (
ChooseColor()) to edit its color. - Inks can be dragged left/right to adjust their position in the gradient.