Class Motion

java.lang.Object
limn.animation.Motion

public final class Motion extends Object
How long the toolkit's motion takes, given what the user asked the system for. While SystemPreferences.reduceMotion() is set, motion finishes at once: a Transition jumps to its target, and popups, menus and dialogs open and close without fading, as native toolkits do for a user who asked every application for less motion.

An animation that drives its own clock reads this too. One whose motion carries information, such as a progress sweep or a busy spinner, keeps moving but steps: it moves a few times a second instead of every frame.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    How often a stepped animation moves, in seconds: four times a second.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    duration(double seconds)
     
    static double
    progress(double dt, double seconds)
    The share of a fade that one frame advances: dt / seconds, or all of it when the fade takes no time or motion is reduced.
    static boolean
     
    static double
    stepped(double dt, double held)
    Holds a stepped animation's time between steps: add each frame's length to held; the animation moves only when this answers more than zero, by the time it answers, while motion is reduced.

    Methods inherited from class java.lang.Object

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

    • STEP_SECONDS

      public static final double STEP_SECONDS
      How often a stepped animation moves, in seconds: four times a second.
      See Also:
  • Method Details

    • reduced

      public static boolean reduced()
      Returns:
      whether the user asked for less motion. Any thread
    • duration

      public static double duration(double seconds)
      Parameters:
      seconds - how long the motion takes when nothing is reduced
      Returns:
      seconds, or 0 while motion is reduced. Any thread
    • progress

      public static double progress(double dt, double seconds)
      The share of a fade that one frame advances: dt / seconds, or all of it when the fade takes no time or motion is reduced. Never NaN, even for a frame of zero length.
      Parameters:
      dt - the frame's length, in seconds
      seconds - how long the whole fade takes when nothing is reduced
      Returns:
      the share to add, 1 or more for a fade that ends now
    • stepped

      public static double stepped(double dt, double held)
      Holds a stepped animation's time between steps: add each frame's length to held; the animation moves only when this answers more than zero, by the time it answers, while motion is reduced. Otherwise every frame moves by its own length.
      
       double moved = Motion.stepped(dt, held);
       held = moved > 0 ? 0 : held + dt;
       if (moved > 0) { phase += moved / period; invalidate(); }
       
      Parameters:
      dt - this frame's length, in seconds
      held - the time held since the last step, in seconds
      Returns:
      the time to move by now, or 0 to hold this frame