Class FadeTransition

  • All Implemented Interfaces:
    Transition

    public class FadeTransition
    extends Object
    implements Transition
    A transition that fades the incoming content in over the outgoing one.

    Each frame draws the incoming content in place, at an opacity that follows an easing Function (a quadratic ease-out by default) from fully transparent to fully opaque. The outgoing content is the frame left on the display, so what the blend dissolves from is simply what was already there.

    Fading needs the incoming content as an image, so this transition depends on the snapshots: when an application disables them through Transition.SNAPSHOTS_CONSTANT, there is nothing to blend and getDuration() reports 0, turning the fade into an instant page change.

    Since:
    0.2.0
    • Constructor Detail

      • FadeTransition

        public FadeTransition()
        Creates a fade with the default duration and easing.
      • FadeTransition

        public FadeTransition​(int duration)
        Creates a fade with the given duration and the default easing.
        Parameters:
        duration - the fade duration, in milliseconds; must be strictly positive.
        Throws:
        IllegalArgumentException - if the given duration is not strictly positive.
      • FadeTransition

        public FadeTransition​(int duration,
                              Function easing)
        Creates a fade with the given duration and easing.
        Parameters:
        duration - the fade duration, in milliseconds; must be strictly positive.
        easing - the function shaping the opacity over the duration.
        Throws:
        IllegalArgumentException - if the given duration is not strictly positive.
        Since:
        2.0.0
    • Method Detail

      • getDuration

        public int getDuration()
        Description copied from interface: Transition
        Returns how long this transition lasts, in milliseconds.

        A duration of 0 or less makes the page change instant: the navigator shows the incoming content immediately, without starting this transition and without drawing a single frame.

        Specified by:
        getDuration in interface Transition
        Returns:
        the duration in milliseconds.
      • start

        public void start​(TransitionContext context)
        Description copied from interface: Transition
        Prepares this transition for the page change described by the given context.

        Called once per navigation, before the first frame, and only when Transition.getDuration() is strictly positive. The incoming content is already captured, so an implementation may read the content area size and the navigation kind here. Nothing is drawn during this call.

        Specified by:
        start in interface Transition
        Parameters:
        context - the context of the page change about to be animated.
      • render

        public void render​(GraphicsContext g,
                           TransitionContext context,
                           float progress)
        Description copied from interface: Transition
        Draws one frame of this transition.

        The given graphics context is translated and clipped to the content area, and already holds the pixels of the previous frame — the outgoing content. An implementation draws the incoming content over them through the given context.

        Specified by:
        render in interface Transition
        Parameters:
        g - the graphics context to draw the frame with, translated and clipped to the content area.
        context - the context of the page change being animated.
        progress - how far the transition has advanced: the elapsed time divided by the duration, at least 0 and strictly less than 1.