Class GlassLensBlend

java.lang.Object
com.codename1.ui.plaf.GlassLensBlend

public final class GlassLensBlend extends Object

Reference implementation of Graphics.glassLensRegion: the optics of a raised Liquid Glass lens (the lifted iOS 27 tab selection) laid over what is already painted. Ports without a native path run this; the Metal shader cn1_fs_glass_lens mirrors it.

The lens is a rounded rectangle (a capsule for a negative corner radius) whose rim is a circular bevel of height bevel: a pixel s inside the rim shows the surface displaced OUTWARDS along the rim's normal by D(s) = (h - s) / sqrt(1 - ((h - s) / h)^2) (h = bevel, zero beyond it) -- the refraction of a glass edge, which pulls whatever lies just outside the lens (the edge of the bar it floats over, the backdrop) into its rim. The three channels are displaced by D * (1 - dispersion), D and D * (1 + dispersion), which fringes the rim. On top of that the surface:

  • brightens by brightness inside;
  • darkens by up to endShade in a band endShadeWidth wide along the rim, weighted by how horizontal the rim's normal is (the rounded ends);
  • is multiplied by 1 - outline on a ring outlineWidth wide just inside the rim;
  • gains a highlight of rimLight + rimLightVertical * |ny| right inside that ring, decaying as exp(-d / rimWidth) with the depth d past it;
  • casts a soft shadow of depth shadow around its lower half, a band that peaks shadowWidth outside the rim and has the same width.

Lengths are in pixels, brightness levels in 0..1 units. Everything is mixed with the untouched surface by amount.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
    Number of optics parameters.
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    apply(int[] src, int sw, int sh, int[] dst, int ox, int oy, int ow, int oh, float lx, float ly, float lw, float lh, float cornerRadius, float[] optics, float amount)
    Applies the lens.
    static float
    displacement(float s, float h, float max)
    Outward displacement of a point s pixels inside a rim of bevel height h.
    static int
    margin(float[] optics)
    How far outside the lens rectangle the effect reaches (the shadow and the outline ring), in pixels.
    static int
    reach(float[] optics)
    How far outside the painted area the refraction may sample, in pixels.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • margin

      public static int margin(float[] optics)
      How far outside the lens rectangle the effect reaches (the shadow and the outline ring), in pixels.
    • reach

      public static int reach(float[] optics)
      How far outside the painted area the refraction may sample, in pixels.
    • displacement

      public static float displacement(float s, float h, float max)
      Outward displacement of a point s pixels inside a rim of bevel height h.
    • apply

      public static void apply(int[] src, int sw, int sh, int[] dst, int ox, int oy, int ow, int oh, float lx, float ly, float lw, float lh, float cornerRadius, float[] optics, float amount)

      Applies the lens.

      Parameters
      • src: the surface, sw * sh ARGB pixels, read only

      • sw: source width

      • sh: source height

      • dst: receives the result for the output area, ow * oh pixels

      • ox: the output area's left edge inside src

      • oy: the output area's top edge inside src

      • ow: output width

      • oh: output height

      • lx: the lens rectangle's left edge inside src (may be fractional)

      • ly: the lens rectangle's top edge inside src

      • lw: lens width

      • lh: lens height

      • cornerRadius: corner radius in pixels, negative for a capsule

      • optics: COUNT parameters, see the constants

      • amount: overall strength 0..1