diff --git a/Greenshot/Helpers/AnimationHelper.cs b/Greenshot/Helpers/AnimationHelper.cs
index 89a5bba1d..320e20df1 100644
--- a/Greenshot/Helpers/AnimationHelper.cs
+++ b/Greenshot/Helpers/AnimationHelper.cs
@@ -37,46 +37,81 @@ namespace Greenshot.Helpers {
protected double frames;
protected double currentFrame = 0;
+ ///
+ /// The amount of frames
+ ///
public double Frames {
get { return frames; }
}
+ ///
+ /// Current frame number
+ ///
public double CurrentFrame {
get { return currentFrame; }
}
+ ///
+ /// First animation value
+ ///
public T First {
get { return first; }
}
+ ///
+ /// Last animation value
+ ///
public T Last {
get { return last; }
}
- public void ChangeDestination(T last) {
- ChangeDestination(last, frames);
+ ///
+ /// This restarts the current animation and changes the last frame
+ ///
+ ///
+ public void ChangeDestination(T newDestination) {
+ ChangeDestination(newDestination, frames);
}
+ ///
+ /// This restarts the current animation and changes the last frame
+ ///
+ ///
+ ///
+ public void ChangeDestination(T newDestination, double frames) {
+ this.first = current;
+ this.currentFrame = 0;
+ this.frames = frames;
+ this.last = newDestination;
+ }
+
+ ///
+ /// Queue the destination, it will be used after the current animation is finished
+ ///
+ ///
public void QueueDestination(T queuedDestination) {
queue.Enqueue(queuedDestination);
}
- public void ChangeDestination(T last, double frames) {
- this.first = current;
- this.currentFrame = 0;
- this.frames = frames;
- this.last = last;
- }
-
+ ///
+ /// The EasingType to use for the animation
+ ///
public EasingType EasingType {
get;
set;
}
+
+ ///
+ /// The EasingMode to use for the animation
+ ///
public EasingMode EasingMode {
get;
set;
}
+ ///
+ /// Get the easing value, which is from 0-1 and depends on the frame
+ ///
protected double EasingValue {
get {
switch (EasingMode) {
@@ -91,6 +126,14 @@ namespace Greenshot.Helpers {
}
}
+ ///
+ /// Constructor
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public AnimatorBase(T first, T last, int frames, EasingType easingType, EasingMode easingMode) {
this.first = first;
this.last = last;
@@ -99,18 +142,19 @@ namespace Greenshot.Helpers {
this.EasingType = easingType;
this.EasingMode = easingMode;
}
-
- public virtual void Reset() {
- currentFrame = 0;
- current = first;
- }
+ ///
+ /// Get the current (previous) frame object
+ ///
public virtual T Current {
get {
return current;
}
}
+ ///
+ /// Returns if there are any frame left, and if this is the case than the frame is increaded.
+ ///
public virtual bool NextFrame {
get {
if (currentFrame < frames) {
@@ -127,6 +171,9 @@ namespace Greenshot.Helpers {
}
}
+ ///
+ /// Are there more frames to animate?
+ ///
public virtual bool hasNext {
get {
if (currentFrame < frames) {
@@ -136,6 +183,10 @@ namespace Greenshot.Helpers {
}
}
+ ///
+ /// Get the next animation frame value object
+ ///
+ ///
public abstract T Next();
}
@@ -156,6 +207,10 @@ namespace Greenshot.Helpers {
: base(first, last, frames, easingType, easingMode) {
}
+ ///
+ /// Calculate the next frame object
+ ///
+ /// Rectangle
public override Rectangle Next() {
if (NextFrame) {
double easingValue = EasingValue;
@@ -188,6 +243,11 @@ namespace Greenshot.Helpers {
public PointAnimator(Point first, Point last, int frames, EasingType easingType, EasingMode easingMode)
: base(first, last, frames, easingType, easingMode) {
}
+
+ ///
+ /// Calculate the next frame value
+ ///
+ /// Point
public override Point Next() {
if (NextFrame) {
double easingValue = EasingValue;
@@ -217,6 +277,10 @@ namespace Greenshot.Helpers {
: base(first, last, frames, easingType, easingMode) {
}
+ ///
+ /// Calculate the next frame values
+ ///
+ /// Size
public override Size Next() {
if (NextFrame) {
double easingValue = EasingValue;
@@ -236,9 +300,10 @@ namespace Greenshot.Helpers {
public static class Easing {
// Adapted from http://www.robertpenner.com/easing/penner_chapter7_tweening.pdf
- public static float Ease(double linearStep, float acceleration, EasingType type) {
- double easedStep = acceleration > 0 ? EaseIn(linearStep, type) : acceleration < 0 ? EaseOut(linearStep, type) : (float)linearStep;
- return MathHelper.Lerp(linearStep, easedStep, Math.Abs(acceleration));
+ public static double Ease(double linearStep, double acceleration, EasingType type) {
+ double easedStep = acceleration > 0 ? EaseIn(linearStep, type) : acceleration < 0 ? EaseOut(linearStep, type) : (double)linearStep;
+ // Lerp:
+ return ((easedStep - linearStep) * Math.Abs(acceleration) + linearStep);
}
public static double EaseIn(double linearStep, EasingType type) {
@@ -246,7 +311,7 @@ namespace Greenshot.Helpers {
case EasingType.Step:
return linearStep < 0.5 ? 0 : 1;
case EasingType.Linear:
- return (double)linearStep;
+ return linearStep;
case EasingType.Sine:
return Sine.EaseIn(linearStep);
case EasingType.Quadratic:
@@ -266,7 +331,7 @@ namespace Greenshot.Helpers {
case EasingType.Step:
return linearStep < 0.5 ? 0 : 1;
case EasingType.Linear:
- return (double)linearStep;
+ return linearStep;
case EasingType.Sine:
return Sine.EaseOut(linearStep);
case EasingType.Quadratic:
@@ -290,7 +355,7 @@ namespace Greenshot.Helpers {
case EasingType.Step:
return linearStep < 0.5 ? 0 : 1;
case EasingType.Linear:
- return (float)linearStep;
+ return linearStep;
case EasingType.Sine:
return Sine.EaseInOut(linearStep);
case EasingType.Quadratic:
@@ -307,34 +372,37 @@ namespace Greenshot.Helpers {
static class Sine {
public static double EaseIn(double s) {
- return (double)Math.Sin(s * MathHelper.HalfPi - MathHelper.HalfPi) + 1;
+ return Math.Sin(s * (Math.PI / 2) - (Math.PI / 2)) + 1;
}
public static double EaseOut(double s) {
- return (double)Math.Sin(s * MathHelper.HalfPi);
+ return Math.Sin(s * (Math.PI / 2));
}
public static double EaseInOut(double s) {
- return (double)(Math.Sin(s * MathHelper.Pi - MathHelper.HalfPi) + 1) / 2;
+ return Math.Sin(s * Math.PI - (Math.PI / 2) + 1) / 2;
}
}
static class Power {
public static double EaseIn(double s, int power) {
- return (double)Math.Pow(s, power);
+ return Math.Pow(s, power);
}
public static double EaseOut(double s, int power) {
var sign = power % 2 == 0 ? -1 : 1;
- return (double)(sign * (Math.Pow(s - 1, power) + sign));
+ return sign * (Math.Pow(s - 1, power) + sign);
}
public static double EaseInOut(double s, int power) {
s *= 2;
if (s < 1)
return EaseIn(s, power) / 2;
var sign = power % 2 == 0 ? -1 : 1;
- return (float)(sign / 2.0 * (Math.Pow(s - 2, power) + sign * 2));
+ return (sign / 2.0 * (Math.Pow(s - 2, power) + sign * 2));
}
}
}
+ ///
+ /// This defines the way the animation works
+ ///
public enum EasingType {
Step,
Linear,
@@ -350,13 +418,4 @@ namespace Greenshot.Helpers {
EaseOut,
EaseInOut
}
-
- public static class MathHelper {
- public const float Pi = (float)Math.PI;
- public const float HalfPi = (float)(Math.PI / 2);
-
- public static float Lerp(double from, double to, double step) {
- return (float)((to - from) * step + from);
- }
- }
}