Package snap.gfx

Class GradientPaint

java.lang.Object
snap.gfx.GradientPaint
All Implemented Interfaces:
Cloneable, Paint, XMLArchiver.Archivable

public class GradientPaint extends Object implements Paint, Cloneable, XMLArchiver.Archivable
A Paint subclass to represent a gradient.
  • Field Details

  • Constructor Details

    • GradientPaint

      public GradientPaint()
      Creates a new GradientPaint.
    • GradientPaint

      public GradientPaint(double anAngle, GradientPaint.Stop[] theStops)
      Creates a new linear GradientPaint with given stops and roll.
    • GradientPaint

      public GradientPaint(Color aC1, Color aC2, double anAngle)
      Creates a new linear GradientPaint with given stops and roll.
    • GradientPaint

      public GradientPaint(double aSX, double aSY, double aEX, double aEY, GradientPaint.Stop[] theStops)
      Creates a new linear GradientPaint with given type, start/end points, stops.
    • GradientPaint

      public GradientPaint(GradientPaint.Type aType, double aSX, double aSY, double aEX, double aEY, GradientPaint.Stop[] theStops)
      Creates a new GradientPaint with given type, start/end points, stops.
    • GradientPaint

      public GradientPaint(GradientPaint.Type aType, double aSX, double aSY, double aEX, double aEY, GradientPaint.Stop[] theStops, boolean isAbs)
      Creates a new GradientPaint with given type, start/end points, stops and absolute flag.
  • Method Details

    • getType

      public GradientPaint.Type getType()
      Returns the type.
    • isLinear

      public boolean isLinear()
      Returns whether gradient is linear.
    • isRadial

      public boolean isRadial()
      Returns whether gradient is radial.
    • getStartX

      public double getStartX()
      Returns the start x.
    • getStartY

      public double getStartY()
      Returns the start y.
    • getEndX

      public double getEndX()
      Returns the end x.
    • getEndY

      public double getEndY()
      Returns the end y.
    • getStops

      public GradientPaint.Stop[] getStops()
      Returns the stops.
    • getRoll

      public double getRoll()
      Returns the roll.
    • setRoll

      protected void setRoll(double aRoll, Rect aRect)
      Sets the roll.
    • getStopCount

      public int getStopCount()
      Returns the number of stops.
    • getStop

      public GradientPaint.Stop getStop(int anIndex)
      Returns the stop at given index.
    • getStopColor

      public Color getStopColor(int anIndex)
      Returns the stop color at given index.
    • getStopOffset

      public double getStopOffset(int anIndex)
      Returns the stop offset at given index.
    • isAbsolute

      public boolean isAbsolute()
      Returns whether paint is defined in terms independent of primitive to be filled.
      Specified by:
      isAbsolute in interface Paint
    • isOpaque

      public boolean isOpaque()
      Returns whether paint is opaque.
      Specified by:
      isOpaque in interface Paint
    • getColor

      public Color getColor()
      Returns the closest color approximation of this paint.
      Specified by:
      getColor in interface Paint
    • copyForColor

      public GradientPaint copyForColor(Color aColor)
      Derives an instance of this class from given color.
      Specified by:
      copyForColor in interface Paint
    • copyForRect

      public GradientPaint copyForRect(Rect aRect)
      Returns an absolute paint for given bounds of primitive to be filled.
      Specified by:
      copyForRect in interface Paint
    • copyForPoints

      public GradientPaint copyForPoints(double aSX, double aSY, double aEX, double aEY)
      Returns a copy of this paint for new start/end points.
    • copyForStops

      public GradientPaint copyForStops(GradientPaint.Stop[] theStops)
      Returns a copy of this paint with stops from given array.
    • copyForType

      public GradientPaint copyForType(GradientPaint.Type aType)
      Returns a new gradient which is a copy of this gradient but of a different type.
    • copyForRoll

      public GradientPaint copyForRoll(double aRoll)
      Returns a new gradient which is a copy of this gradient but with a different roll value.
    • copyForReverseStops

      public GradientPaint copyForReverseStops()
      Reverse the order of the color stops
    • clone

      public GradientPaint clone()
      Returns a copy of this gradient paint.
      Overrides:
      clone in class Object
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Overrides:
      equals in class Object
    • toXML

      public XMLElement toXML(XMLArchiver anArchiver)
      XML archival.
      Specified by:
      toXML in interface XMLArchiver.Archivable
    • fromXML

      public Object fromXML(XMLArchiver anArchiver, XMLElement anElement)
      XML unarchival.
      Specified by:
      fromXML in interface XMLArchiver.Archivable
    • toString

      public String toString()
      Standard to string implementation.
      Overrides:
      toString in class Object
    • getStopsHaveAlpha

      public static boolean getStopsHaveAlpha(GradientPaint.Stop[] theStops)
      Returns true if any of the colors in the gradient have alpha
    • getStops

      public static GradientPaint.Stop[] getStops(double off1, Color col1, double off2, Color col2)
      Creates an array of stops.
    • getStops

      public static GradientPaint.Stop[] getStops(double off1, Color col1, double off2, Color col2, double off3, Color col3)
      Creates an array of stops.
    • getStops

      public static GradientPaint.Stop[] getStops(double o1, Color c1, double o2, Color c2, double o3, Color c3, double o4, Color c4)
      Creates an array of stops.
    • getStops

      public static GradientPaint.Stop[] getStops(double[] theOffs, Color... theColors)
      Adds stops to a stops array.