Class AnimationManager

GoDiagram®
v10.0.12
by Northwoods Software®

AnimationManager handles animations in a Northwoods.Go.AnimationManager.Diagram. Each Diagram has one, AnimationManager.

Inheritance
AnimationManager
Namespace: Northwoods.Go
Assembly: Northwoods.GoDiagram.WinForms.dll
Syntax
public class AnimationManager
Remarks

Setting the Model, performing a Layout, Group expansion and Tree expansion automatically start animations through the DefaultAnimation. Animations can be manually started by creating Animations, which are associated with an AnimationManager.

Animation is enabled by default, setting the IsEnabled property to false will turn off animations for a Diagram.

When the DefaultAnimation begins it raises AnimationStarting, upon completion it raises the AnimationFinished.

The DefaultAnimation, if running, will stop if a new transaction is started, if an undo or redo is called, if a layout is invalidated, or if a model is replaced. When an Animation is stopped, the Diagram immediately finishes the animation and draws the final state. Animations can be stopped programatically with the methods StopAnimation(bool) or Stop().

Constructors

AnimationManager()

Constructs an AnimationManager. You should not need to call this.

Declaration
public AnimationManager()

Properties

ActiveAnimations

Gets the set of currently animating Animations being managed by this AnimationManager, including any running DefaultAnimation.

Declaration
public IEnumerable<Animation> ActiveAnimations { get; }
Property Value
Type Description
IEnumerable<Animation>

DefaultAnimation

This read-only property gets the Animation that carries out the default built-in GoDiagram animations. This animation is usually only referenced to modify default animation properties, such as the Easing or Duration.

Declaration
public Animation DefaultAnimation { get; }
Property Value
Type Description
Animation
Remarks

You should not add anything to or start the default animation, GoDiagram does so automatically, internally. When the default animation begins it raises AnimationStarting, upon completion it raises AnimationFinished. You should not modify the properties RunCount or Reversible on the default animation.

See the Introduction Page on Animations for more detail.

Duration

Gets or sets the default duration, in milliseconds, used as the duration for the DefaultAnimation and for animations that have their Duration set to -1.

Declaration
public int Duration { get; set; }
Property Value
Type Description
int
Remarks

Typically these values are short. The default value is 600 milliseconds. The value must be an int greater than or equal to 1. Setting this property does not raise any events.

See Also

InitialAnimationStyle

Gets or sets the initial animation style that is set up by the DefaultAnimation.

Declaration
public AnimationStyle InitialAnimationStyle { get; set; }
Property Value
Type Description
AnimationStyle
Remarks

This can be Default, AnimateLocations, or None.

  • If set to Default, the initial animation will "fade up" the Diagram's contents by animating the Position and Opacity.
  • If set to AnimateLocations, the initial animation will animate Part locations from (0, 0) to their values.
  • If set to None, no initial animation will happen by default, which this allows you to specify your own initial animation by defining a InitialAnimationStarting handler.

An example custom initial animation, which zooms the Diagram into view:

myDiagram.AnimationManager.InitialAnimationStyle = AnimationStyle.None;
myDiagram.InitialAnimationStarting += (s, e) => {
  var animation = e.Subject.DefaultAnimation;
  animation.Easing = Animation.EaseOutExpo;
  animation.Duration = 900;
  animation.Add(e.Diagram, "Scale", 0.1, 1);
  animation.Add(e.Diagram, "Opacity", 0, 1);
};

IsAnimating

This read-only property is true when the animation manager is currently animating any animation, including the DefaultAnimation.

Declaration
public bool IsAnimating { get; }
Property Value
Type Description
bool
Remarks

This value cannot be set, but animation can be stopped by calling StopAnimation(bool), and it can be prevented by setting IsEnabled.

IsEnabled

Gets or sets whether this AnimationManager operates.

Declaration
public bool IsEnabled { get; set; }
Property Value
Type Description
bool
Remarks

The default value is true. Setting this to false does not stop an animation, it only stops future animations. To stop any ongoing animation, use StopAnimation(bool). To disable only the default animations, set CanStart(string) to a function that always returns false.

If any indefinite animations (animations with RunCount set to int.MaxValue) were running when this is set to false, they will be resumed when this is set to true.

Setting this property does not raise any events.

See Also

IsInitial

Gets or sets whether a default animation is performed on an initial layout.

Declaration
public bool IsInitial { get; set; }
Property Value
Type Description
bool
Remarks

The default value is true. Changing the value does not affect any ongoing animation. Setting this property does not raise any events.

IsTicking

This read-only property is true when the animation manager is in the middle of an animation tick.

Declaration
public bool IsTicking { get; }
Property Value
Type Description
bool
Remarks

Animation only operates on GraphObjects during ticks, but code outside of AnimationManager's control may execute between ticks.

IsTicking can only be true when IsAnimating is also true.

Methods

CanStart(string)

This method is passed the reason a default animation is to begin, and must return true or false based on whether or not the animation is to be allowed. Returning true means the animation will occur, returning false will stop the animation's setup.

Declaration
public virtual bool CanStart(string reason)
Parameters
Type Name Description
string reason

Reason for starting the animation

Returns
Type Description
bool
Remarks

By default, this method always returns true. Setting this to a function that always returns false will disable all default animations, but allow other animations, such as AnimationTriggers, to run.

These are the possible reasons GoDiagram will begin an animation:

Called by CommandHandler:

  • "Collapse SubGraph"
  • "Expand SubGraph"
  • "Collapse Tree"
  • "Expand Tree"
  • "Scroll To Part"
  • "Zoom To Fit" Called by Diagram:
  • "Model"
  • "Layout" Called by AnimationTriggers:
  • "Trigger"

Example usage:

// disallow expand/collapse animations, but allow all other default animations:
public override bool CanStart(string reason) {
  if (reason === "Expand Tree") return false;
  return true;
}

// disallow all default animations:
public override bool CanStart(string reason) {
  return false;
}

DefineAnimationEffect(string, AnimationFunction)

Defines a new named effect to be used in animation, along with a function that tells the AnimationManager how to modify that property.

Declaration
public static void DefineAnimationEffect(string effectName, AnimationFunction animationFunction)
Parameters
Type Name Description
string effectName

Named effect to animate

AnimationFunction animationFunction

Function that transforms the property values. It takes the animated object, start value, end value, easing function (the Easing), current time, duration, and animation state. It should modify one or more properties on the object.

Remarks

Effect names do not need to reflect GraphObject properties, and you can define an effect with a function that modifies several properties for convenience.

For example, one could define an animation effect named "MoveAndSpin" which modifies the object's Position and Angle.

Most commonly, an effect is defined with one GraphObject property in mind to be animated, and the function uses the start and end values, an easing function, and the times to determine a new value for each tick of animation. Here is an example for animating the fill of GraphObjects:

// This presumes the object to be animated is a Shape
AnimationManager.DefineAnimationEffect("Fill", (obj, startValue, endValue, easing, currentTime, duration, animation) => {
  var hueValue = easing(currentTime, (int)startValue, (int)endValue - (int)startValue, duration);
  (obj as Shape).Fill = "hsl(" + hueValue + ", 100%, 80%)";
});

StopAnimation(bool)

Stops the DefaultAnimation and updates the Diagram to its final state.

Declaration
public void StopAnimation(bool stopsAllAnimations = false)
Parameters
Type Name Description
bool stopsAllAnimations

Whether to stop all animations, instead of just the DefaultAnimation. Default false.

Remarks

If the argument is true, this stops all running animations. If an Animation was about to begin, it will be cancelled.

If the DefaultAnimation is running, this will raise AnimationFinished.