Package limn.graphics

Record Class BackdropEffect.Blur

java.lang.Object
java.lang.Record
limn.graphics.BackdropEffect.Blur
Record Components:
tint - colour over the blurred backdrop; usually clear on the first of a pair, so the tint is not laid down twice
radius - how far the blur reaches, in points. 0 is no blur at all, and the pass is then exactly identity
axis - which way this pass smears; see the class note on why it is one at a time
All Implemented Interfaces:
BackdropEffect
Enclosing interface:
BackdropEffect

public static record BackdropEffect.Blur(Color tint, float radius, BackdropEffect.Blur.Axis axis) extends Record implements BackdropEffect
The backdrop blurred along one axis. Two of these, crossed, are a full blur.

Separable on purpose, and it is why this is affordable at all. A true two-dimensional blur of radius r costs r² samples per pixel; the same blur run horizontally and then vertically costs 2r and is indistinguishable. So this variant does one axis and the caller draws it twice, which works because a backdrop effect reads the framebuffer and writes the framebuffer: the second pass samples what the first one left.


 // frosted glass: refract, then blur across, then down
 canvas.fillBackdropRoundRect(shape, new BackdropEffect.Clear(tint, 20, 0.3f));
 canvas.fillBackdropRoundRect(shape, new BackdropEffect.Blur(Color.TRANSPARENT, 8, Axis.X));
 canvas.fillBackdropRoundRect(shape, new BackdropEffect.Blur(Color.TRANSPARENT, 8, Axis.Y));
 

Stacking is the general mechanism here, not a trick for this variant: any of these effects composes with any other by being drawn over it, at one flush and one copy each.

  • Constructor Details

    • Blur

      public Blur(Color tint, float radius, BackdropEffect.Blur.Axis axis)
      Creates an instance of a Blur record class.
      Parameters:
      tint - the value for the tint record component
      radius - the value for the radius record component
      axis - the value for the axis record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • tint

      public Color tint()
      Returns the value of the tint record component.
      Specified by:
      tint in interface BackdropEffect
      Returns:
      the value of the tint record component
    • radius

      public float radius()
      Returns the value of the radius record component.
      Returns:
      the value of the radius record component
    • axis

      public BackdropEffect.Blur.Axis axis()
      Returns the value of the axis record component.
      Returns:
      the value of the axis record component