const virtual class vaseGraphics::Gradient
sys::Obj vaseGraphics::Gradient : vaseGraphics::Brush
@Js
@Serializable { simple=true }
Fills a shape with a linear or radial color gradient.
NOTE: SWT only supports linear two stop gradients with no angle using the Graphics.fillRect method.
- equals
-
virtual override Bool equals(Obj? obj)
Equality is based on fields.
- fromStr
-
static Gradient? fromStr(Str str, Bool checked := true)
Parse a gradient from string (see
toStr
). If invalid and checked is true then throw ParseErr otherwise return null:<gradient> := <linear> | <radial> | <impliedLinear> <linear> := "linear(" <args> ")" <radial> := "radial(" <args> ")" <impliedLinear> := <args> <args> := <start> "," <end> ("," <stop>)* <start> := <pos> <pos> <end> := <pos> <pos> <pos> := <int> <unit> // no space allowed between <stop> := <color> [<float>] // 0f..1f <color> := #AARRGGBB, #RRGGBB, #RGB <unit> := "px" | "%"
The general format is a start and end position followed by a comma list of gradient stops. The start and end positions are x, y coordinates (% or pixel). The stops are a color followed by a position in the range (0..1). If the position is omitted it is calcaulated as percentage:
#000, #fff => #000 0.0, #fff 1.0 #000, #abc, #fff => #000 0.0, #000 0.5, #fff 1.0
Examples:
Gradient("linear(0% 0%, 100% 100%, #f00, #00f)") => linear(0% 0%, 100% 100%, #ff0000 0.0, #0000ff 1.0) Gradient("5px 3px, 25px 30px, #f00, #00f") => linear(5px 3px, 25px 30px, #ff0000 0.0, #0000ff 1.0) Gradient("0% 50%, 100% 50%, #f00 0.1, #00f 0.9") => linear(0% 50%, 100% 50%, #ff0000 0.1, #0000ff 0.9)
- hash
-
virtual override Int hash()
Hash the fields.
- make
-
new make(Func<Void,This>? f := null)
Construct for it-block. Throw ArgErr if any units are invalid or less than 2 stops.
- mode
-
const GradientMode mode := GradientMode.linear
Mode is linear or radial
- percent
-
const static Str percent := "%"
Percent unit constant
- pixel
-
const static Str pixel := "px"
Pixel unit constant
- stops
-
const List<GradientStop> stops := defStops
List of gradient stops, default is "white 0.0" to "black 1.0".
- toStr
-
virtual override Str toStr()
Return
"[point1:color1; point2:color2]"
. This string format is subject to change. - x1
-
const Int x1 := 0
Starting point x coordinate with unit defined by
x1Unit
- x1Unit
-
const Str x1Unit := pixel
- x2
-
const Int x2 := 100
Ending point x coordinate with unit defined by
x2Unit
- x2Unit
-
const Str x2Unit := pixel
- y1
-
const Int y1 := 0
Starting point y coordinate with unit defined by
y1Unit
- y1Unit
-
const Str y1Unit := pixel
- y2
-
const Int y2 := 100
Ending point y coordinate with unit defined by
y2Unit
- y2Unit
-
const Str y2Unit := pixel