const class gfx::Gradient

sys::Obj
  gfx::Gradient : gfx::Brush

@Js
@Serializable { simple=true }

Source

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)

Source

Equality is based on fields.

fromStr

static new fromStr(Str str, Bool checked := true)

Source

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()

Source

Hash the fields.

make

new make(|This|? f := null)

Source

Construct for it-block. Throw ArgErr if any units are invalid or less than 2 stops.

mode

const GradientMode mode := GradientMode.linear

Source

Mode is linear or radial

percent

const static Unit percent := ...

Source

Percent unit constant

pixel

const static Unit pixel := ...

Source

Pixel unit constant

stops

const GradientStop[] stops := defStops

Source

List of gradient stops, default is "white 0.0" to "black 1.0".

toStr

virtual override Str toStr()

Source

Return "[point1:color1; point2:color2]". This string format is subject to change.

x1

const Int x1 := 0

Source

Starting point x coordinate with unit defined by x1Unit

x1Unit

const Unit x1Unit := pixel

Source

Unit of x1 which must be percent or pixel

x2

const Int x2 := 100

Source

Ending point x coordinate with unit defined by x2Unit

x2Unit

const Unit x2Unit := pixel

Source

Unit of x2 which must be percent or pixel

y1

const Int y1 := 0

Source

Starting point y coordinate with unit defined by y1Unit

y1Unit

const Unit y1Unit := pixel

Source

Unit of y1 which must be percent or pixel

y2

const Int y2 := 100

Source

Ending point y coordinate with unit defined by y2Unit

y2Unit

const Unit y2Unit := pixel

Source

Unit of y2 which must be percent or pixel