Repository: falahati/WinFormAnimation
Branch: master
Commit: 326ec7812f96
Files: 50
Total size: 292.0 KB
Directory structure:
gitextract_akg5khpk/
├── .gitignore
├── LICENSE
├── README.md
├── WinFormAnimation/
│ ├── AnimationFunctions.cs
│ ├── Animator.cs
│ ├── Animator2D.cs
│ ├── Animator3D.cs
│ ├── AnimatorStatus.cs
│ ├── FPSLimiterKnownValues.cs
│ ├── FloatExtensions.cs
│ ├── IAnimator.cs
│ ├── KnownAnimationFunctions.cs
│ ├── Path.cs
│ ├── Path2D.cs
│ ├── Path2DExtensions.cs
│ ├── Path3D.cs
│ ├── Path3DExtensions.cs
│ ├── PathExtensions.cs
│ ├── SafeInvoker.cs
│ ├── SafeInvoker`1.cs
│ ├── Timer.cs
│ ├── WinFormAnimation.csproj
│ ├── float2D.cs
│ ├── float3D.cs
│ └── readme.txt
├── WinFormAnimation.Samples/
│ ├── Demo1.Designer.cs
│ ├── Demo1.cs
│ ├── Demo1.resx
│ ├── Demo2.Designer.cs
│ ├── Demo2.cs
│ ├── Demo2.resx
│ ├── Demo3.Designer.cs
│ ├── Demo3.cs
│ ├── Demo3.resx
│ ├── Demo4.Designer.cs
│ ├── Demo4.cs
│ ├── Demo4.resx
│ ├── MainForm.Designer.cs
│ ├── MainForm.cs
│ ├── MainForm.resx
│ ├── Program.cs
│ ├── Properties/
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── WinFormAnimation.Samples.csproj
│ └── app.config
├── WinFormAnimation.sln
└── WinFormAnimation.sln.DotSettings
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/
# mstest test results
TestResults
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.log
*.vspscc
*.vssscc
.builds
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Publish Web Output
*.Publish.xml
# NuGet Packages Directory
packages
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
[Bb]in
[Oo]bj
sql
TestResults
[Tt]est[Rr]esult*
*.Cache
ClientBin
[Ss]tyle[Cc]op.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
*.nupkg
/.vs/*
*.pfx
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2016 Soroush
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
#
WinForm Animation Library [.Net3.5+]
[](https://github.com/falahati/WinFormAnimation/blob/master/LICENSE)
[](https://github.com/falahati/WinFormAnimation/commits/master)
[](https://github.com/falahati/WinFormAnimation/issues)
A simple library for animating controls/values in .Net WinForm (.Net 3.5 and later). Key frame (Path) based and fully customizable.
*Please note that even though this library designed for WinForm but its usage is not limited to WinForm and can be used in other environments. Only reference of the library is to 'System.Drawing' name space.*
## How to get
[](https://www.nuget.org/packages/WinFormAnimation)
[](https://www.nuget.org/packages/WinFormAnimation)
This library is available as a NuGet package at [nuget.org](https://www.nuget.org/packages/WinFormAnimation/).
## Help me fund my own Death Star
[](https://www.coinpayments.net/index.php?cmd=_donate&reset=1&merchant=820707aded07845511b841f9c4c335cd&item_name=Donate¤cy=USD&amountf=20.00000000&allow_amount=1&want_shipping=0&allow_extra=1)
[](https://zarinp.al/@falahati)
[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ramin.graphix@gmail.com&lc=US&item_name=Donate&no_note=0&cn=&curency_code=USD&bn=PP-DonationsBF:btn_donateCC_LG.gif:NonHosted)
**--OR--**
You can always donate your time by contributing to the project or by introducing it to others..
## Documentation
* `Float2D`: A class containing two `float` values as Vertical and Horizontal coordinates representing a point in a 2D plane.
* `Float3D`: A class containing three `float` values as Vertical, Horizontal and Depth coordinates representing a point in a 3D plane.
* `Path`: A class containing a `float` starting and a `float` ending point for a single dimensional animation as well as duration and the function to control the animation.
* `Path2D`: A class containing a `Float2D` starting and a `Float2D` ending point for a two dimensional animation as well as duration and the function to control the animation.
* `Path3D`: A class containing a `Float3D` starting and a `Float3D` ending point for a three dimensional animation as well as duration and the function to control the animation.
* `Animator`: A class for animating an array of `Path` objects. This class is one of the main classes and starting points of a basic animation.
* `Animator2D`: A class for animating an array of `Path2D` objects. This class is one of the main classes and starting points of a basic animation.
* `Animator2D`: A class for animating an array of `Path3D` objects. This class is one of the main classes and starting points of a basic animation.
* `SafeInvoker`: A class holding a reference to a function to invoke in the correct thread, detected by a `Control` object passed to it. Useful for easier UI manipulations.
* `SafeInvoker`: Same as `SafeInvoker` class but with a generic argument for the function to invoke.
For full documentation of the classes and their members, please take a look at our doxygen page at [falahati.github.io](https://falahati.github.io/WinFormAnimation/doxygen).
## Basic examples
### ONE DIMENSIONAL ANIMATION OF A PROPERTY
Following code animates a property named `Value` of a `ProgressBar` named `pb_progress` in 5 seconds from zero to one hundred:
```C#
new Animator(new Path(0, 100, 5000))
.Play(pb_progress, Animator.KnownProperties.Value);
```
### TWO DIMENSIONAL ANIMATION OF A PROPERTY
Following code animates a `Form` in two paths. First one moves the `Form` from (0, -100) to (100, 200) and second path waits for 3 seconds and then moved the `Form` to its initial location in 2 seconds. (`this` is a `Form`)
```C#
new Animator2D(
new Path2D(0, 100, -100, 200, 5000).ContinueTo(this.Location.ToFloat2D(), 2000, 3000))
.Play(this, Animator2D.KnownProperties.Location);
```
### THREE DIMENSIONAL ANIMATION OF A PROPERTY
Following code animates a property named `CustomColor` of a `Control` named `c_customLabel` in 2 seconds and after a delay of 1 second using the `AnimationFunctions.CubicEaseIn` function and with maximum of 10 frames per second.
```C#
new Animator3D(
new Path3D(Color.Blue.ToFloat3D(), Color.Red.ToFloat3D(), 2000, 1000, AnimationFunctions.CubicEaseIn),
FPSLimiterKnownValues.LimitTen)
.Play(c_customLabel, "CustomColor");
```
### KEYFRAMES
There are extension methods for `Path`, `Path2D`, `Path3D` and their arrays to let you continue the path easily and define the key frames as fast as possible. For example, following code moves a `Control` named `c_control` in a rectangular path infinitely:
```C#
new Animator2D(
new Path2D(new Float2D(100, 100), new Float2D(200, 100), 1000)
.ContinueTo(new Float2D(200, 200), 1000)
.ContinueTo(new Float2D(100, 200), 1000)
.ContinueTo(new Float2D(100, 100), 1000))
{
Repeat = true
}.Play(c_control, Animator2D.KnownProperties.Location);
```
### CALLBACKS
It is possible to define a custom callback as frame handler as well as defining a call back to handle the end of the animation. Following example will call a method named `CustomSetMethod` for setting new values and handle the frames, and starts the animation in reverse path after its end for one more time:
```C#
var animator = new Animator(new Path(100, 200, 1000).ContinueTo(400, 500));
animator.Play(new SafeInvoker(CustomSetMethod), new SafeInvoker(() =>
{
animator.Paths = animator.Paths.Select(path => path.Reverse()).Reverse().ToArray();
animator.Play(new SafeInvoker(CustomSetMethod));
}));
```
## Demo
Check the 'WinFormAnimation.Samples' project for simple usage examples.

## License
The MIT License (MIT)
Copyright (c) 2016-2020 Soroush Falahati
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: WinFormAnimation/AnimationFunctions.cs
================================================
using System;
namespace WinFormAnimation
{
///
/// The functions gallery for animation
///
public static class AnimationFunctions
{
///
/// The base delegate for defining new animation functions.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public delegate float Function(float time, float beginningValue, float changeInValue, float duration);
///
/// Returns a function delegate based on the the passed known animation function
///
/// The animation function
/// Animation fucntion delegate
public static Function FromKnown(KnownAnimationFunctions knownFunction)
{
switch (knownFunction)
{
case KnownAnimationFunctions.CubicEaseIn:
return CubicEaseIn;
case KnownAnimationFunctions.CubicEaseInOut:
return CubicEaseInOut;
case KnownAnimationFunctions.CubicEaseOut:
return CubicEaseOut;
case KnownAnimationFunctions.Linear:
return Linear;
case KnownAnimationFunctions.CircularEaseInOut:
return CircularEaseInOut;
case KnownAnimationFunctions.CircularEaseIn:
return CircularEaseIn;
case KnownAnimationFunctions.CircularEaseOut:
return CircularEaseOut;
case KnownAnimationFunctions.QuadraticEaseIn:
return QuadraticEaseIn;
case KnownAnimationFunctions.QuadraticEaseOut:
return QuadraticEaseOut;
case KnownAnimationFunctions.QuadraticEaseInOut:
return QuadraticEaseInOut;
case KnownAnimationFunctions.QuarticEaseIn:
return QuarticEaseIn;
case KnownAnimationFunctions.QuarticEaseOut:
return QuarticEaseOut;
case KnownAnimationFunctions.QuarticEaseInOut:
return QuarticEaseInOut;
case KnownAnimationFunctions.QuinticEaseInOut:
return QuinticEaseInOut;
case KnownAnimationFunctions.QuinticEaseIn:
return QuinticEaseIn;
case KnownAnimationFunctions.QuinticEaseOut:
return QuinticEaseOut;
case KnownAnimationFunctions.SinusoidalEaseIn:
return SinusoidalEaseIn;
case KnownAnimationFunctions.SinusoidalEaseOut:
return SinusoidalEaseOut;
case KnownAnimationFunctions.SinusoidalEaseInOut:
return SinusoidalEaseInOut;
case KnownAnimationFunctions.ExponentialEaseIn:
return ExponentialEaseIn;
case KnownAnimationFunctions.ExponentialEaseOut:
return ExponentialEaseOut;
case KnownAnimationFunctions.ExponentialEaseInOut:
return ExponentialEaseInOut;
default:
throw new ArgumentOutOfRangeException(nameof(knownFunction), knownFunction,
"The passed animation function is unknown.");
}
}
///
/// The cubic ease-in animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float CubicEaseIn(float t, float b, float c, float d)
{
t /= d;
return c*t*t*t + b;
}
///
/// The cubic ease-in and ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float CubicEaseInOut(float t, float b, float c, float d)
{
t /= d/2;
if (t < 1)
return c/2*t*t*t + b;
t -= 2;
return c/2*(t*t*t + 2) + b;
}
///
/// The cubic ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float CubicEaseOut(float t, float b, float c, float d)
{
t /= d;
t--;
return c*(t*t*t + 1) + b;
}
///
/// The linear animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float Linear(float t, float b, float c, float d)
{
return c*t/d + b;
}
///
/// The circular ease-in and ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float CircularEaseInOut(float t, float b, float c, float d)
{
t /= d/2;
if (t < 1)
return (float) (-c/2*(Math.Sqrt(1 - t*t) - 1) + b);
t -= 2;
return (float) (c/2*(Math.Sqrt(1 - t*t) + 1) + b);
}
///
/// The circular ease-in animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float CircularEaseIn(float t, float b, float c, float d)
{
t /= d;
return (float) (-c*(Math.Sqrt(1 - t*t) - 1) + b);
}
///
/// The circular ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float CircularEaseOut(float t, float b, float c, float d)
{
t /= d;
t--;
return (float) (c*Math.Sqrt(1 - t*t) + b);
}
///
/// The quadratic ease-in animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float QuadraticEaseIn(float t, float b, float c, float d)
{
t /= d;
return c*t*t + b;
}
///
/// The quadratic ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float QuadraticEaseOut(float t, float b, float c, float d)
{
t /= d;
return -c*t*(t - 2) + b;
}
///
/// The quadratic ease-in and ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float QuadraticEaseInOut(float t, float b, float c, float d)
{
t /= d/2;
if (t < 1) return c/2*t*t + b;
t--;
return -c/2*(t*(t - 2) - 1) + b;
}
///
/// The quartic ease-in animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float QuarticEaseIn(float t, float b, float c, float d)
{
t /= d;
return c*t*t*t*t + b;
}
///
/// The quartic ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float QuarticEaseOut(float t, float b, float c, float d)
{
t /= d;
t--;
return -c*(t*t*t*t - 1) + b;
}
///
/// The quartic ease-in and ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float QuarticEaseInOut(float t, float b, float c, float d)
{
t /= d/2;
if (t < 1) return c/2*t*t*t*t + b;
t -= 2;
return -c/2*(t*t*t*t - 2) + b;
}
///
/// The quintic ease-in and ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float QuinticEaseInOut(float t, float b, float c, float d)
{
t /= d/2;
if (t < 1) return c/2*t*t*t*t*t + b;
t -= 2;
return c/2*(t*t*t*t*t + 2) + b;
}
///
/// The quintic ease-in animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float QuinticEaseIn(float t, float b, float c, float d)
{
t /= d;
return c*t*t*t*t*t + b;
}
///
/// The quintic ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float QuinticEaseOut(float t, float b, float c, float d)
{
t /= d;
t--;
return c*(t*t*t*t*t + 1) + b;
}
///
/// The sinusoidal ease-in animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float SinusoidalEaseIn(float t, float b, float c, float d)
{
return (float) (-c*Math.Cos(t/d*(Math.PI/2)) + c + b);
}
///
/// The sinusoidal ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float SinusoidalEaseOut(float t, float b, float c, float d)
{
return (float) (c*Math.Sin(t/d*(Math.PI/2)) + b);
}
///
/// The sinusoidal ease-in and ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float SinusoidalEaseInOut(float t, float b, float c, float d)
{
return (float) (-c/2*(Math.Cos(Math.PI*t/d) - 1) + b);
}
///
/// The exponential ease-in animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float ExponentialEaseIn(float t, float b, float c, float d)
{
return (float) (c*Math.Pow(2, 10*(t/d - 1)) + b);
}
///
/// The exponential ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float ExponentialEaseOut(float t, float b, float c, float d)
{
return (float) (c*(-Math.Pow(2, -10*t/d) + 1) + b);
}
///
/// The exponential ease-in and ease-out animation function.
///
///
/// The time of the animation.
///
///
/// The starting value.
///
///
/// The different between starting and ending value.
///
///
/// The duration of the animations.
///
///
/// The calculated current value of the animation
///
public static float ExponentialEaseInOut(float t, float b, float c, float d)
{
t /= d/2;
if (t < 1)
return (float) (c/2*Math.Pow(2, 10*(t - 1)) + b);
t--;
return (float) (c/2*(-Math.Pow(2, -10*t) + 2) + b);
}
}
}
================================================
FILE: WinFormAnimation/Animator.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace WinFormAnimation
{
///
/// The one dimensional animator class, useful for animating raw values
///
public class Animator : IAnimator
{
///
/// The known one dimensional properties of WinForm controls
///
public enum KnownProperties
{
///
/// The property named 'Value' of the object
///
Value,
///
/// The property named 'Text' of the object
///
Text,
///
/// The property named 'Caption' of the object
///
Caption,
///
/// The property named 'BackColor' of the object
///
BackColor,
///
/// The property named 'ForeColor' of the object
///
ForeColor,
///
/// The property named 'Opacity' of the object
///
Opacity
}
private readonly List _paths = new List();
private readonly List _tempPaths = new List();
private readonly Timer _timer;
private bool _tempReverseRepeat;
///
/// The callback to get invoked at the end of the animation
///
protected SafeInvoker EndCallback;
///
/// The callback to get invoked at each frame
///
protected SafeInvoker FrameCallback;
///
/// The target object to change the property of
///
protected object TargetObject;
///
/// Initializes a new instance of the class.
///
public Animator()
: this(new Path[] {})
{
}
///
/// Initializes a new instance of the class.
///
///
/// Limits the maximum frames per seconds
///
public Animator(FPSLimiterKnownValues fpsLimiter)
: this(new Path[] {}, fpsLimiter)
{
}
///
/// Initializes a new instance of the class.
///
///
/// The path of the animation
///
public Animator(Path path)
: this(new[] {path})
{
}
///
/// Initializes a new instance of the class.
///
///
/// The path of the animation
///
///
/// Limits the maximum frames per seconds
///
public Animator(Path path, FPSLimiterKnownValues fpsLimiter)
: this(new[] {path}, fpsLimiter)
{
}
///
/// Initializes a new instance of the class.
///
///
/// An array containing the list of paths of the animation
///
public Animator(Path[] paths) : this(paths, FPSLimiterKnownValues.LimitThirty)
{
}
///
/// Initializes a new instance of the class.
///
///
/// An array containing the list of paths of the animation
///
///
/// Limits the maximum frames per seconds
///
public Animator(Path[] paths, FPSLimiterKnownValues fpsLimiter)
{
CurrentStatus = AnimatorStatus.Stopped;
_timer = new Timer(Elapsed, fpsLimiter);
Paths = paths;
}
///
/// Gets or sets an array containing the list of paths of the animation
///
/// Animation is running
public Path[] Paths
{
get { return _paths.ToArray(); }
set
{
if (CurrentStatus == AnimatorStatus.Stopped)
{
_paths.Clear();
_paths.AddRange(value);
}
else
{
throw new InvalidOperationException("Animation is running.");
}
}
}
///
/// Gets the currently active path.
///
public Path ActivePath { get; private set; }
///
/// Gets or sets a value indicating whether animator should repeat the animation after its ending
///
public virtual bool Repeat { get; set; }
///
/// Gets or sets a value indicating whether animator should repeat the animation in reverse after its ending.
///
public virtual bool ReverseRepeat { get; set; }
///
/// Gets the current status of the animation
///
public virtual AnimatorStatus CurrentStatus { get; private set; }
///
/// Pause the animation
///
public virtual void Pause()
{
if (CurrentStatus != AnimatorStatus.OnHold && CurrentStatus != AnimatorStatus.Playing)
return;
_timer.Stop();
CurrentStatus = AnimatorStatus.Paused;
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The name of the property to change
///
public virtual void Play(object targetObject, string propertyName)
{
Play(targetObject, propertyName, null);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The name of the property to change
///
///
/// The callback to get invoked at the end of the animation
///
public virtual void Play(object targetObject, string propertyName, SafeInvoker endCallback)
{
TargetObject = targetObject;
var prop = TargetObject.GetType()
.GetProperty(
propertyName,
BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance |
BindingFlags.SetProperty);
if (prop == null) return;
Play(
new SafeInvoker(
value => prop.SetValue(TargetObject, Convert.ChangeType(value, prop.PropertyType), null),
TargetObject),
endCallback);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The expression that represents the property of the target object
///
///
/// Any object containing a property
///
public virtual void Play(T targetObject, Expression> propertySetter)
{
Play(targetObject, propertySetter, null);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The expression that represents the property of the target object
///
///
/// The callback to get invoked at the end of the animation
///
///
/// Any object containing a property
///
public virtual void Play(T targetObject, Expression> propertySetter, SafeInvoker endCallback)
{
if (propertySetter == null)
return;
TargetObject = targetObject;
var property =
((propertySetter.Body as MemberExpression) ??
(((UnaryExpression) propertySetter.Body).Operand as MemberExpression))?.Member as PropertyInfo;
if (property == null)
{
throw new ArgumentException(nameof(propertySetter));
}
Play(
new SafeInvoker(
value => property.SetValue(TargetObject, Convert.ChangeType(value, property.PropertyType), null),
TargetObject),
endCallback);
}
///
/// Resume the animation from where it paused
///
public virtual void Resume()
{
if (CurrentStatus == AnimatorStatus.Paused)
{
_timer.Resume();
}
}
///
/// Stops the animation and resets its status, resume is no longer possible
///
public virtual void Stop()
{
_timer.Stop();
lock (_tempPaths)
{
_tempPaths.Clear();
}
ActivePath = null;
CurrentStatus = AnimatorStatus.Stopped;
_tempReverseRepeat = false;
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The property to change
///
public virtual void Play(object targetObject, KnownProperties property)
{
Play(targetObject, property, null);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The property to change
///
///
/// The callback to get invoked at the end of the animation
///
public virtual void Play(object targetObject, KnownProperties property, SafeInvoker endCallback)
{
Play(targetObject, property.ToString(), endCallback);
}
///
/// Starts the playing of the animation
///
///
/// The callback to get invoked at each frame
///
public virtual void Play(SafeInvoker frameCallback)
{
Play(frameCallback, (SafeInvoker) null);
}
///
/// Starts the playing of the animation
///
///
/// The callback to get invoked at each frame
///
///
/// The callback to get invoked at the end of the animation
///
public virtual void Play(SafeInvoker frameCallback, SafeInvoker endCallback)
{
Stop();
FrameCallback = frameCallback;
EndCallback = endCallback;
_timer.ResetClock();
lock (_tempPaths)
{
_tempPaths.AddRange(_paths);
}
_timer.Start();
}
private void Elapsed(ulong millSinceBeginning = 0)
{
while (true)
{
lock (_tempPaths)
{
if (_tempPaths != null && ActivePath == null && _tempPaths.Count > 0)
{
while (ActivePath == null)
{
if (_tempReverseRepeat)
{
ActivePath = _tempPaths.LastOrDefault();
_tempPaths.RemoveAt(_tempPaths.Count - 1);
}
else
{
ActivePath = _tempPaths.FirstOrDefault();
_tempPaths.RemoveAt(0);
}
_timer.ResetClock();
millSinceBeginning = 0;
}
}
var ended = ActivePath == null;
if (ActivePath != null)
{
if (!_tempReverseRepeat && millSinceBeginning < ActivePath.Delay)
{
CurrentStatus = AnimatorStatus.OnHold;
return;
}
if (millSinceBeginning - (!_tempReverseRepeat ? ActivePath.Delay : 0) <= ActivePath.Duration)
{
if (CurrentStatus != AnimatorStatus.Playing)
{
CurrentStatus = AnimatorStatus.Playing;
}
var value = ActivePath.Function(_tempReverseRepeat ? ActivePath.Duration - millSinceBeginning : millSinceBeginning - ActivePath.Delay, ActivePath.Start, ActivePath.Change, ActivePath.Duration);
FrameCallback.Invoke(value);
return;
}
if (CurrentStatus == AnimatorStatus.Playing)
{
if (_tempPaths.Count == 0)
{
// For the last path, we make sure that control is in end point
FrameCallback.Invoke(_tempReverseRepeat ? ActivePath.Start : ActivePath.End);
ended = true;
}
else
{
if ((_tempReverseRepeat && ActivePath.Delay > 0) || !_tempReverseRepeat && _tempPaths.FirstOrDefault()?.Delay > 0)
{
// Or if the next path or this one in revese order has a delay
FrameCallback.Invoke(_tempReverseRepeat ? ActivePath.Start : ActivePath.End);
}
}
}
if (_tempReverseRepeat && (millSinceBeginning - ActivePath.Duration) < ActivePath.Delay)
{
CurrentStatus = AnimatorStatus.OnHold;
return;
}
ActivePath = null;
}
if (!ended)
{
return;
}
}
if (Repeat)
{
lock (_tempPaths)
{
_tempPaths.AddRange(_paths);
_tempReverseRepeat = ReverseRepeat && !_tempReverseRepeat;
}
millSinceBeginning = 0;
continue;
}
Stop();
EndCallback?.Invoke();
break;
}
}
}
}
================================================
FILE: WinFormAnimation/Animator2D.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace WinFormAnimation
{
///
/// The two dimensional animator class, useful for animating values
/// created from two underlying values
///
public class Animator2D : IAnimator
{
///
/// The known two dimensional properties of WinForm controls
///
public enum KnownProperties
{
///
/// The property named 'Size' of the object
///
Size,
///
/// The property named 'Location' of the object
///
Location
}
private readonly List _paths = new List();
///
/// The callback to get invoked at the end of the animation
///
protected SafeInvoker EndCallback;
///
/// The callback to get invoked at each frame
///
protected SafeInvoker FrameCallback;
///
/// A boolean value indicating if the EndInvoker already invoked
///
protected bool IsEnded;
///
/// The target object to change the property of
///
protected object TargetObject;
///
/// The latest horizontal value
///
protected float? XValue;
///
/// The latest vertical value
///
protected float? YValue;
///
/// Initializes a new instance of the class.
///
public Animator2D()
: this(new Path2D[] {})
{
}
///
/// Initializes a new instance of the class.
///
///
/// Limits the maximum frames per seconds
///
public Animator2D(FPSLimiterKnownValues fpsLimiter)
: this(new Path2D[] {}, fpsLimiter)
{
}
///
/// Initializes a new instance of the class.
///
///
/// The path of the animation
///
public Animator2D(Path2D path)
: this(new[] {path})
{
}
///
/// Initializes a new instance of the class.
///
///
/// The path of the animation
///
///
/// Limits the maximum frames per seconds
///
public Animator2D(Path2D path, FPSLimiterKnownValues fpsLimiter)
: this(new[] {path}, fpsLimiter)
{
}
///
/// Initializes a new instance of the class.
///
///
/// An array containing the list of paths of the animation
///
public Animator2D(Path2D[] paths) : this(paths, FPSLimiterKnownValues.LimitThirty)
{
}
///
/// Initializes a new instance of the class.
///
///
/// An array containing the list of paths of the animation
///
///
/// Limits the maximum frames per seconds
///
public Animator2D(Path2D[] paths, FPSLimiterKnownValues fpsLimiter)
{
HorizontalAnimator = new Animator(fpsLimiter);
VerticalAnimator = new Animator(fpsLimiter);
Paths = paths;
}
///
/// Gets the currently active path.
///
public Path2D ActivePath => new Path2D(HorizontalAnimator.ActivePath, VerticalAnimator.ActivePath);
///
/// Gets the horizontal animator.
///
public Animator HorizontalAnimator { get; protected set; }
///
/// Gets the vertical animator.
///
public Animator VerticalAnimator { get; protected set; }
///
/// Gets or sets an array containing the list of paths of the animation
///
/// Animation is running
public Path2D[] Paths
{
get { return _paths.ToArray(); }
set
{
if (CurrentStatus == AnimatorStatus.Stopped)
{
_paths.Clear();
_paths.AddRange(value);
var pathsH = new List();
var pathsV = new List();
foreach (var p in value)
{
pathsH.Add(p.HorizontalPath);
pathsV.Add(p.VerticalPath);
}
HorizontalAnimator.Paths = pathsH.ToArray();
VerticalAnimator.Paths = pathsV.ToArray();
}
else
{
throw new InvalidOperationException("Animation is running.");
}
}
}
///
/// Gets or sets a value indicating whether animator should repeat the animation after its ending
///
public virtual bool Repeat
{
get { return HorizontalAnimator.Repeat && VerticalAnimator.Repeat; }
set { HorizontalAnimator.Repeat = VerticalAnimator.Repeat = value; }
}
///
/// Gets or sets a value indicating whether animator should repeat the animation in reverse after its ending.
///
public virtual bool ReverseRepeat
{
get { return HorizontalAnimator.ReverseRepeat && VerticalAnimator.ReverseRepeat; }
set { HorizontalAnimator.ReverseRepeat = VerticalAnimator.ReverseRepeat = value; }
}
///
/// Gets the current status of the animation
///
public virtual AnimatorStatus CurrentStatus
{
get
{
if (HorizontalAnimator.CurrentStatus == AnimatorStatus.Stopped
&& VerticalAnimator.CurrentStatus == AnimatorStatus.Stopped)
{
return AnimatorStatus.Stopped;
}
if (HorizontalAnimator.CurrentStatus == AnimatorStatus.Paused
&& VerticalAnimator.CurrentStatus == AnimatorStatus.Paused)
{
return AnimatorStatus.Paused;
}
if (HorizontalAnimator.CurrentStatus == AnimatorStatus.OnHold
&& VerticalAnimator.CurrentStatus == AnimatorStatus.OnHold)
{
return AnimatorStatus.OnHold;
}
return AnimatorStatus.Playing;
}
}
///
/// Pause the animation
///
public virtual void Pause()
{
if (CurrentStatus == AnimatorStatus.OnHold || CurrentStatus == AnimatorStatus.Playing)
{
HorizontalAnimator.Pause();
VerticalAnimator.Pause();
}
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The name of the property to change
///
public virtual void Play(object targetObject, string propertyName)
{
Play(targetObject, propertyName, null);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The name of the property to change
///
///
/// The callback to get invoked at the end of the animation
///
public virtual void Play(object targetObject, string propertyName, SafeInvoker endCallback)
{
TargetObject = targetObject;
var prop = TargetObject.GetType()
.GetProperty(
propertyName,
BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance |
BindingFlags.SetProperty);
if (prop == null) return;
Play(
new SafeInvoker(
value =>
prop.SetValue(TargetObject, Convert.ChangeType(value, prop.PropertyType), null),
TargetObject),
endCallback);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The expression that represents the property of the target object
///
///
/// Any object containing a property
///
public virtual void Play(T targetObject, Expression> propertySetter)
{
Play(targetObject, propertySetter, null);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The expression that represents the property of the target object
///
///
/// The callback to get invoked at the end of the animation
///
///
/// Any object containing a property
///
public virtual void Play(T targetObject, Expression> propertySetter, SafeInvoker endCallback)
{
if (propertySetter == null)
return;
TargetObject = targetObject;
var property =
((propertySetter.Body as MemberExpression) ??
(((UnaryExpression) propertySetter.Body).Operand as MemberExpression))?.Member as PropertyInfo;
if (property == null)
{
throw new ArgumentException(nameof(propertySetter));
}
Play(
new SafeInvoker(
value =>
property.SetValue(TargetObject, Convert.ChangeType(value, property.PropertyType), null),
TargetObject),
endCallback);
}
///
/// Resume the animation from where it paused
///
public virtual void Resume()
{
if (CurrentStatus == AnimatorStatus.Paused)
{
HorizontalAnimator.Resume();
VerticalAnimator.Resume();
}
}
///
/// Stops the animation and resets its status, resume is no longer possible
///
public virtual void Stop()
{
HorizontalAnimator.Stop();
VerticalAnimator.Stop();
XValue = YValue = null;
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The property to change
///
public void Play(object targetObject, KnownProperties property)
{
Play(targetObject, property, null);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The property to change
///
///
/// The callback to get invoked at the end of the animation
///
public void Play(object targetObject, KnownProperties property, SafeInvoker endCallback)
{
Play(targetObject, property.ToString(), endCallback);
}
///
/// Starts the playing of the animation
///
///
/// The callback to get invoked at each frame
///
public void Play(SafeInvoker frameCallback)
{
Play(frameCallback, (SafeInvoker) null);
}
///
/// Starts the playing of the animation
///
///
/// The callback to get invoked at each frame
///
///
/// The callback to get invoked at the end of the animation
///
public void Play(SafeInvoker frameCallback, SafeInvoker endCallback)
{
Stop();
FrameCallback = frameCallback;
EndCallback = endCallback;
HorizontalAnimator.Play(
new SafeInvoker(
value =>
{
XValue = value;
InvokeSetter();
}),
new SafeInvoker(InvokeFinisher));
VerticalAnimator.Play(
new SafeInvoker(
value =>
{
YValue = value;
InvokeSetter();
}),
new SafeInvoker(InvokeFinisher));
}
private void InvokeFinisher()
{
if (EndCallback != null && !IsEnded)
{
lock (EndCallback)
{
if (CurrentStatus == AnimatorStatus.Stopped)
{
IsEnded = true;
EndCallback.Invoke();
}
}
}
}
private void InvokeSetter()
{
if (XValue != null && YValue != null)
{
FrameCallback.Invoke(new Float2D(XValue.Value, YValue.Value));
}
}
}
}
================================================
FILE: WinFormAnimation/Animator3D.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace WinFormAnimation
{
///
/// The three dimensional animator class, useful for animating values
/// created from three underlying values
///
public class Animator3D : IAnimator
{
///
/// The known three dimensional properties of WinForm controls
///
public enum KnownProperties
{
///
/// The property named 'BackColor' of the object
///
BackColor,
///
/// The property named 'ForeColor' of the object
///
ForeColor
}
private readonly List _paths = new List();
///
/// The callback to get invoked at the end of the animation
///
protected SafeInvoker EndCallback;
///
/// The callback to get invoked at each frame
///
protected SafeInvoker FrameCallback;
///
/// A boolean value indicating if the EndInvoker already invoked
///
protected bool IsEnded;
///
/// The target object to change the property of
///
protected object TargetObject;
///
/// The latest horizontal value
///
protected float? XValue;
///
/// The latest vertical value
///
protected float? YValue;
///
/// The latest depth value
///
protected float? ZValue;
///
/// Initializes a new instance of the class.
///
public Animator3D()
: this(new Path3D[] {})
{
}
///
/// Initializes a new instance of the class.
///
///
/// Limits the maximum frames per seconds
///
public Animator3D(FPSLimiterKnownValues fpsLimiter)
: this(new Path3D[] {}, fpsLimiter)
{
}
///
/// Initializes a new instance of the class.
///
///
/// The path of the animation
///
public Animator3D(Path3D path)
: this(new[] {path})
{
}
///
/// Initializes a new instance of the class.
///
///
/// The path of the animation
///
///
/// Limits the maximum frames per seconds
///
public Animator3D(Path3D path, FPSLimiterKnownValues fpsLimiter)
: this(new[] {path}, fpsLimiter)
{
}
///
/// Initializes a new instance of the class.
///
///
/// An array containing the list of paths of the animation
///
public Animator3D(Path3D[] paths) : this(paths, FPSLimiterKnownValues.LimitThirty)
{
}
///
/// Initializes a new instance of the class.
///
///
/// An array containing the list of paths of the animation
///
///
/// Limits the maximum frames per seconds
///
public Animator3D(Path3D[] paths, FPSLimiterKnownValues fpsLimiter)
{
HorizontalAnimator = new Animator(fpsLimiter);
VerticalAnimator = new Animator(fpsLimiter);
DepthAnimator = new Animator(fpsLimiter);
Paths = paths;
}
///
/// Gets the currently active path.
///
public Path3D ActivePath => new Path3D(
HorizontalAnimator.ActivePath,
VerticalAnimator.ActivePath,
DepthAnimator.ActivePath);
///
/// Gets the horizontal animator.
///
public Animator HorizontalAnimator { get; protected set; }
///
/// Gets the vertical animator.
///
public Animator VerticalAnimator { get; protected set; }
///
/// Gets the depth animator.
///
public Animator DepthAnimator { get; protected set; }
///
/// Gets or sets an array containing the list of paths of the animation
///
/// Animation is running
public Path3D[] Paths
{
get { return _paths.ToArray(); }
set
{
if (CurrentStatus == AnimatorStatus.Stopped)
{
_paths.Clear();
_paths.AddRange(value);
var pathsX = new List();
var pathsY = new List();
var pathsZ = new List();
foreach (var p in value)
{
pathsX.Add(p.HorizontalPath);
pathsY.Add(p.VerticalPath);
pathsZ.Add(p.DepthPath);
}
HorizontalAnimator.Paths = pathsX.ToArray();
VerticalAnimator.Paths = pathsY.ToArray();
DepthAnimator.Paths = pathsZ.ToArray();
}
else
{
throw new NotSupportedException("Animation is running.");
}
}
}
///
/// Gets or sets a value indicating whether animator should repeat the animation after its ending
///
public virtual bool Repeat
{
get { return HorizontalAnimator.Repeat && VerticalAnimator.Repeat && DepthAnimator.Repeat; }
set { HorizontalAnimator.Repeat = VerticalAnimator.Repeat = DepthAnimator.Repeat = value; }
}
///
/// Gets or sets a value indicating whether animator should repeat the animation in reverse after its ending.
///
public virtual bool ReverseRepeat
{
get
{
return HorizontalAnimator.ReverseRepeat && VerticalAnimator.ReverseRepeat
&& DepthAnimator.ReverseRepeat;
}
set
{
HorizontalAnimator.ReverseRepeat =
VerticalAnimator.ReverseRepeat = DepthAnimator.ReverseRepeat = value;
}
}
///
/// Gets the current status of the animation
///
public virtual AnimatorStatus CurrentStatus
{
get
{
if (HorizontalAnimator.CurrentStatus == AnimatorStatus.Stopped
&& VerticalAnimator.CurrentStatus == AnimatorStatus.Stopped
&& DepthAnimator.CurrentStatus == AnimatorStatus.Stopped)
{
return AnimatorStatus.Stopped;
}
if (HorizontalAnimator.CurrentStatus == AnimatorStatus.Paused
&& VerticalAnimator.CurrentStatus == AnimatorStatus.Paused
&& DepthAnimator.CurrentStatus == AnimatorStatus.Paused)
{
return AnimatorStatus.Paused;
}
if (HorizontalAnimator.CurrentStatus == AnimatorStatus.OnHold
&& VerticalAnimator.CurrentStatus == AnimatorStatus.OnHold
&& DepthAnimator.CurrentStatus == AnimatorStatus.OnHold)
{
return AnimatorStatus.OnHold;
}
return AnimatorStatus.Playing;
}
}
///
/// Pause the animation
///
public virtual void Pause()
{
if (CurrentStatus == AnimatorStatus.OnHold || CurrentStatus == AnimatorStatus.Playing)
{
HorizontalAnimator.Pause();
VerticalAnimator.Pause();
DepthAnimator.Pause();
}
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The name of the property to change
///
public virtual void Play(object targetObject, string propertyName)
{
Play(targetObject, propertyName, null);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The name of the property to change
///
///
/// The callback to get invoked at the end of the animation
///
public virtual void Play(object targetObject, string propertyName, SafeInvoker endCallback)
{
TargetObject = targetObject;
var prop = TargetObject.GetType()
.GetProperty(
propertyName,
BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance |
BindingFlags.SetProperty);
if (prop == null) return;
Play(
new SafeInvoker(
value =>
prop.SetValue(TargetObject, Convert.ChangeType(value, prop.PropertyType), null),
TargetObject),
endCallback);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The expression that represents the property of the target object
///
///
/// Any object containing a property
///
public virtual void Play(T targetObject, Expression> propertySetter)
{
Play(targetObject, propertySetter, null);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The expression that represents the property of the target object
///
///
/// The callback to get invoked at the end of the animation
///
///
/// Any object containing a property
///
public virtual void Play(T targetObject, Expression> propertySetter, SafeInvoker endCallback)
{
if (propertySetter == null)
return;
TargetObject = targetObject;
var property =
((propertySetter.Body as MemberExpression) ??
(((UnaryExpression) propertySetter.Body).Operand as MemberExpression))?.Member as PropertyInfo;
if (property == null)
{
throw new ArgumentException(nameof(propertySetter));
}
Play(
new SafeInvoker(
value =>
property.SetValue(TargetObject, Convert.ChangeType(value, property.PropertyType), null),
TargetObject),
endCallback);
}
///
/// Resume the animation from where it paused
///
public virtual void Resume()
{
if (CurrentStatus == AnimatorStatus.Paused)
{
HorizontalAnimator.Resume();
VerticalAnimator.Resume();
DepthAnimator.Resume();
}
}
///
/// Stops the animation and resets its status, resume is no longer possible
///
public virtual void Stop()
{
HorizontalAnimator.Stop();
VerticalAnimator.Stop();
DepthAnimator.Stop();
XValue = YValue = ZValue = null;
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The property to change
///
public void Play(object targetObject, KnownProperties property)
{
Play(targetObject, property, null);
}
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The property to change
///
///
/// The callback to get invoked at the end of the animation
///
public void Play(object targetObject, KnownProperties property, SafeInvoker endCallback)
{
Play(targetObject, property.ToString(), endCallback);
}
///
/// Starts the playing of the animation
///
///
/// The callback to get invoked at each frame
///
public void Play(SafeInvoker frameCallback)
{
Play(frameCallback, (SafeInvoker) null);
}
///
/// Starts the playing of the animation
///
///
/// The callback to get invoked at each frame
///
///
/// The callback to get invoked at the end of the animation
///
public void Play(SafeInvoker frameCallback, SafeInvoker endCallback)
{
Stop();
FrameCallback = frameCallback;
EndCallback = endCallback;
IsEnded = false;
HorizontalAnimator.Play(
new SafeInvoker(
value =>
{
XValue = value;
InvokeSetter();
}),
new SafeInvoker(InvokeFinisher));
VerticalAnimator.Play(
new SafeInvoker(
value =>
{
YValue = value;
InvokeSetter();
}),
new SafeInvoker(InvokeFinisher));
DepthAnimator.Play(
new SafeInvoker(
value =>
{
ZValue = value;
InvokeSetter();
}),
new SafeInvoker(InvokeFinisher));
}
private void InvokeFinisher()
{
if (EndCallback != null && !IsEnded)
{
lock (EndCallback)
{
if (CurrentStatus == AnimatorStatus.Stopped)
{
IsEnded = true;
EndCallback.Invoke();
}
}
}
}
private void InvokeSetter()
{
if (XValue != null && YValue != null && ZValue != null)
{
FrameCallback.Invoke(new Float3D(XValue.Value, YValue.Value, ZValue.Value));
}
}
}
}
================================================
FILE: WinFormAnimation/AnimatorStatus.cs
================================================
namespace WinFormAnimation
{
///
/// The possible statuses for an animator instance
///
public enum AnimatorStatus
{
///
/// Animation is stopped
///
Stopped,
///
/// Animation is now playing
///
Playing,
///
/// Animation is now on hold for path delay, consider this value as playing
///
OnHold,
///
/// Animation is paused
///
Paused
}
}
================================================
FILE: WinFormAnimation/FPSLimiterKnownValues.cs
================================================
namespace WinFormAnimation
{
///
/// FPS limiter known values
///
public enum FPSLimiterKnownValues
{
///
/// Limits maximum frames per second to 10fps
///
LimitTen = 10,
///
/// Limits maximum frames per second to 20fps
///
LimitTwenty = 20,
///
/// Limits maximum frames per second to 30fps
///
LimitThirty = 30,
///
/// Limits maximum frames per second to 60fps
///
LimitSixty = 60,
///
/// Limits maximum frames per second to 100fps
///
LimitOneHundred = 100,
///
/// Limits maximum frames per second to 200fps
///
LimitTwoHundred = 200,
///
/// Adds no limit to the number of frames per second
///
NoFPSLimit = -1
}
}
================================================
FILE: WinFormAnimation/FloatExtensions.cs
================================================
using System.Drawing;
namespace WinFormAnimation
{
///
/// Contains public extension methods about Float2D and Fload3D classes
///
public static class FloatExtensions
{
///
/// Creates and returns a new instance of the class from this instance
///
/// The object to create the instance from
/// The newly created instance
public static Float2D ToFloat2D(this Point point)
{
return Float2D.FromPoint(point);
}
///
/// Creates and returns a new instance of the class from this instance
///
/// The object to create the instance from
/// The newly created instance
public static Float2D ToFloat2D(this PointF point)
{
return Float2D.FromPoint(point);
}
///
/// Creates and returns a new instance of the class from this instance
///
/// The object to create the instance from
/// The newly created instance
public static Float2D ToFloat2D(this Size size)
{
return Float2D.FromSize(size);
}
///
/// Creates and returns a new instance of the class from this instance
///
/// The object to create the instance from
/// The newly created instance
public static Float2D ToFloat2D(this SizeF size)
{
return Float2D.FromSize(size);
}
///
/// Creates and returns a new instance of the class from this instance
///
/// The object to create the instance from
/// The newly created instance
public static Float3D ToFloat3D(this Color color)
{
return Float3D.FromColor(color);
}
}
}
================================================
FILE: WinFormAnimation/IAnimator.cs
================================================
using System;
using System.Linq.Expressions;
namespace WinFormAnimation
{
///
/// The base interface for any Animator class, custom or build-in
///
public interface IAnimator
{
///
/// Gets the current status of the animation
///
AnimatorStatus CurrentStatus { get; }
///
/// Gets or sets a value indicating whether animator should repeat the animation after its ending
///
bool Repeat { get; set; }
///
/// Gets or sets a value indicating whether animator should repeat the animation in reverse after its ending.
///
bool ReverseRepeat { get; set; }
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The name of the property to change
///
void Play(object targetObject, string propertyName);
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The name of the property to change
///
///
/// The callback to get invoked at the end of the animation
///
void Play(object targetObject, string propertyName, SafeInvoker endCallback);
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The expression that represents the property of the target object
///
///
/// Any object containing a property
///
void Play(T targetObject, Expression> propertySetter);
///
/// Starts the playing of the animation
///
///
/// The target object to change the property
///
///
/// The expression that represents the property of the target object
///
///
/// The callback to get invoked at the end of the animation
///
///
/// Any object containing a property
///
void Play(T targetObject, Expression> propertySetter, SafeInvoker endCallback);
///
/// Resume the animation from where it paused
///
void Resume();
///
/// Stops the animation and resets its status, resume is no longer possible
///
void Stop();
///
/// Pause the animation
///
void Pause();
}
}
================================================
FILE: WinFormAnimation/KnownAnimationFunctions.cs
================================================
namespace WinFormAnimation
{
///
/// Contains a list of all known animation functions
///
public enum KnownAnimationFunctions
{
///
/// No known animation function
///
None,
///
/// The cubic ease-in animation function.
///
CubicEaseIn,
///
/// The cubic ease-in and ease-out animation function.
///
CubicEaseInOut,
///
/// The cubic ease-out animation function.
///
CubicEaseOut,
///
/// The linear animation function.
///
Linear,
///
/// The circular ease-in and ease-out animation function.
///
CircularEaseInOut,
///
/// The circular ease-in animation function.
///
CircularEaseIn,
///
/// The circular ease-out animation function.
///
CircularEaseOut,
///
/// The quadratic ease-in animation function.
///
QuadraticEaseIn,
///
/// The quadratic ease-out animation function.
///
QuadraticEaseOut,
///
/// The quadratic ease-in and ease-out animation function.
///
QuadraticEaseInOut,
///
/// The quartic ease-in animation function.
///
QuarticEaseIn,
///
/// The quartic ease-out animation function.
///
QuarticEaseOut,
///
/// The quartic ease-in and ease-out animation function.
///
QuarticEaseInOut,
///
/// The quintic ease-in and ease-out animation function.
///
QuinticEaseInOut,
///
/// The quintic ease-in animation function.
///
QuinticEaseIn,
///
/// The quintic ease-out animation function.
///
QuinticEaseOut,
///
/// The sinusoidal ease-in animation function.
///
SinusoidalEaseIn,
///
/// The sinusoidal ease-out animation function.
///
SinusoidalEaseOut,
///
/// The sinusoidal ease-in and ease-out animation function.
///
SinusoidalEaseInOut,
///
/// The exponential ease-in animation function.
///
ExponentialEaseIn,
///
/// The exponential ease-out animation function.
///
ExponentialEaseOut,
///
/// The exponential ease-in and ease-out animation function.
///
ExponentialEaseInOut
}
}
================================================
FILE: WinFormAnimation/Path.cs
================================================
using System;
namespace WinFormAnimation
{
///
/// The Path class is a representation of a line in a 1D plane and the
/// speed in which the animator plays it
///
public class Path
{
///
/// Initializes a new instance of the class.
///
public Path() : this(default(float), default(float), default(ulong), 0, null)
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting value
///
///
/// The ending value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// Duration is less than zero
///
public Path(float start, float end, ulong duration) : this(start, end, duration, 0, null)
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting value
///
///
/// The ending value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path(float start, float end, ulong duration, AnimationFunctions.Function function)
: this(start, end, duration, 0, function)
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting value
///
///
/// The ending value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// Duration is less than zero
///
public Path(float start, float end, ulong duration, ulong delay) : this(start, end, duration, delay, null)
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting value
///
///
/// The ending value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path(float start, float end, ulong duration, ulong delay, AnimationFunctions.Function function)
{
Start = start;
End = end;
Function = function ?? AnimationFunctions.Linear;
Duration = duration;
Delay = delay;
}
///
/// Gets the difference of starting and ending values
///
public float Change => End - Start;
///
/// Gets or sets the starting delay
///
public ulong Delay { get; set; }
///
/// Gets or sets the duration in milliseconds
///
public ulong Duration { get; set; }
///
/// Gets or sets the ending value
///
public float End { get; set; }
///
/// Gets or sets the animation function
///
public AnimationFunctions.Function Function { get; set; }
///
/// Gets or sets the starting value
///
public float Start { get; set; }
///
/// Creates and returns a new based on the current path but in reverse order
///
///
/// A new which is the reverse of the current
///
public Path Reverse()
{
return new Path(End, Start, Duration, Delay, Function);
}
}
}
================================================
FILE: WinFormAnimation/Path2D.cs
================================================
using System;
namespace WinFormAnimation
{
///
/// The Path2D class is a representation of a line in a 2D plane and the
/// speed in which the animator plays it
///
public class Path2D
{
///
/// Initializes a new instance of the class.
///
///
/// The starting horizontal value
///
///
/// The ending horizontal value
///
///
/// The starting vertical value
///
///
/// The ending vertical value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path2D(
float startX,
float endX,
float startY,
float endY,
ulong duration,
ulong delay,
AnimationFunctions.Function function)
: this(new Path(startX, endX, duration, delay, function), new Path(startY, endY, duration, delay, function))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting horizontal value
///
///
/// The ending horizontal value
///
///
/// The starting vertical value
///
///
/// The ending vertical value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// Duration is less than zero
///
public Path2D(
float startX,
float endX,
float startY,
float endY,
ulong duration,
ulong delay)
: this(new Path(startX, endX, duration, delay), new Path(startY, endY, duration, delay))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting horizontal value
///
///
/// The ending horizontal value
///
///
/// The starting vertical value
///
///
/// The ending vertical value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path2D(
float startX,
float endX,
float startY,
float endY,
ulong duration,
AnimationFunctions.Function function)
: this(new Path(startX, endX, duration, function), new Path(startY, endY, duration, function))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting horizontal value
///
///
/// The ending horizontal value
///
///
/// The starting vertical value
///
///
/// The ending vertical value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// Duration is less than zero
///
public Path2D(
float startX,
float endX,
float startY,
float endY,
ulong duration)
: this(new Path(startX, endX, duration), new Path(startY, endY, duration))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting point or location
///
///
/// The ending point or location
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path2D(Float2D start, Float2D end, ulong duration, ulong delay, AnimationFunctions.Function function)
: this(
new Path(start.X, end.X, duration, delay, function),
new Path(start.Y, end.Y, duration, delay, function))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting point or location
///
///
/// The ending point or location
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// Duration is less than zero
///
public Path2D(Float2D start, Float2D end, ulong duration, ulong delay)
: this(
new Path(start.X, end.X, duration, delay),
new Path(start.Y, end.Y, duration, delay))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting point or location
///
///
/// The ending point or location
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path2D(Float2D start, Float2D end, ulong duration, AnimationFunctions.Function function)
: this(
new Path(start.X, end.X, duration, function),
new Path(start.Y, end.Y, duration, function))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting point or location
///
///
/// The ending point or location
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// Duration is less than zero
///
public Path2D(Float2D start, Float2D end, ulong duration)
: this(
new Path(start.X, end.X, duration),
new Path(start.Y, end.Y, duration))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The horizontal path.
///
///
/// The vertical path.
///
public Path2D(Path x, Path y)
{
HorizontalPath = x;
VerticalPath = y;
}
///
/// Gets the horizontal path
///
public Path HorizontalPath { get; }
///
/// Gets the vertical path
///
public Path VerticalPath { get; }
///
/// Gets the starting point of the path
///
public Float2D Start => new Float2D(HorizontalPath.Start, VerticalPath.Start);
///
/// Gets the ending point of the path
///
public Float2D End => new Float2D(HorizontalPath.End, VerticalPath.End);
///
/// Creates and returns a new based on the current path but in reverse order
///
///
/// A new which is the reverse of the current
///
public Path2D Reverse()
{
return new Path2D(HorizontalPath.Reverse(), VerticalPath.Reverse());
}
}
}
================================================
FILE: WinFormAnimation/Path2DExtensions.cs
================================================
using System.Linq;
namespace WinFormAnimation
{
///
/// Contains public extensions methods about Path2D class
///
public static class Path2DExtensions
{
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D[] paths, Float2D end, ulong duration)
{
return paths.Concat(new[] {new Path2D(paths.Last().End, end, duration)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D[] paths, Float2D end, ulong duration,
AnimationFunctions.Function function)
{
return paths.Concat(new[] {new Path2D(paths.Last().End, end, duration, function)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D[] paths, Float2D end, ulong duration, ulong delay)
{
return paths.Concat(new[] {new Path2D(paths.Last().End, end, duration, delay)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D[] paths, Float2D end, ulong duration, ulong delay,
AnimationFunctions.Function function)
{
return paths.Concat(new[] {new Path2D(paths.Last().End, end, duration, delay, function)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D[] paths, float endX, float endY, ulong duration)
{
return paths.Concat(new[] {new Path2D(paths.Last().End, new Float2D(endX, endY), duration)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D[] paths, float endX, float endY, ulong duration,
AnimationFunctions.Function function)
{
return
paths.Concat(new[] {new Path2D(paths.Last().End, new Float2D(endX, endY), duration, function)})
.ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D[] paths, float endX, float endY, ulong duration, ulong delay)
{
return
paths.Concat(new[] {new Path2D(paths.Last().End, new Float2D(endX, endY), duration, delay)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D[] paths, float endX, float endY, ulong duration, ulong delay,
AnimationFunctions.Function function)
{
return
paths.Concat(new[] {new Path2D(paths.Last().End, new Float2D(endX, endY), duration, delay, function)})
.ToArray();
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D path, Float2D end, ulong duration)
{
return path.ToArray().ContinueTo(end, duration);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D path, Float2D end, ulong duration,
AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(end, duration, function);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D path, Float2D end, ulong duration, ulong delay)
{
return path.ToArray().ContinueTo(end, duration, delay);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D path, Float2D end, ulong duration, ulong delay,
AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(end, duration, delay, function);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D path, float endX, float endY, ulong duration)
{
return path.ToArray().ContinueTo(endX, endY, duration);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D path, float endX, float endY, ulong duration,
AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(endX, endY, duration, function);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D path, float endX, float endY, ulong duration, ulong delay)
{
return path.ToArray().ContinueTo(endX, endY, duration, delay);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path2D[] ContinueTo(this Path2D path, float endX, float endY, ulong duration, ulong delay,
AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(endX, endY, duration, delay, function);
}
///
/// Continue the path array with a new ones
///
/// Array of paths
/// An array of new paths to adds
/// An array of paths including the new ones
public static Path2D[] ContinueTo(this Path2D[] paths, params Path2D[] newPaths)
{
return paths.Concat(newPaths).ToArray();
}
///
/// Continue the path with a new ones
///
/// The path to continue
/// An array of new paths to adds
/// An array of paths including the new ones
public static Path2D[] ContinueTo(this Path2D path, params Path2D[] newPaths)
{
return path.ToArray().ContinueTo(newPaths);
}
///
/// Contains a single path in an array
///
/// The path to add to the array
/// An array of paths including the new ones
public static Path2D[] ToArray(this Path2D path)
{
return new[] {path};
}
}
}
================================================
FILE: WinFormAnimation/Path3D.cs
================================================
using System;
namespace WinFormAnimation
{
///
/// The Path3D class is a representation of a line in a 3D plane and the
/// speed in which the animator plays it
///
public class Path3D
{
///
/// Initializes a new instance of the class.
///
///
/// The starting horizontal value
///
///
/// The ending horizontal value
///
///
/// The starting vertical value
///
///
/// The ending vertical value
///
///
/// The starting depth value
///
///
/// The ending depth value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path3D(
float startX,
float endX,
float startY,
float endY,
float startZ,
float endZ,
ulong duration,
ulong delay,
AnimationFunctions.Function function)
: this(
new Path(startX, endX, duration, delay, function),
new Path(startY, endY, duration, delay, function),
new Path(startZ, endZ, duration, delay, function))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting horizontal value
///
///
/// The ending horizontal value
///
///
/// The starting vertical value
///
///
/// The ending vertical value
///
///
/// The starting depth value
///
///
/// The ending depth value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// Duration is less than zero
///
public Path3D(
float startX,
float endX,
float startY,
float endY,
float startZ,
float endZ,
ulong duration,
ulong delay)
: this(
new Path(startX, endX, duration, delay),
new Path(startY, endY, duration, delay),
new Path(startZ, endZ, duration, delay))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting horizontal value
///
///
/// The ending horizontal value
///
///
/// The starting vertical value
///
///
/// The ending vertical value
///
///
/// The starting depth value
///
///
/// The ending depth value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path3D(
float startX,
float endX,
float startY,
float endY,
float startZ,
float endZ,
ulong duration,
AnimationFunctions.Function function)
: this(
new Path(startX, endX, duration, function),
new Path(startY, endY, duration, function),
new Path(startZ, endZ, duration, function))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting horizontal value
///
///
/// The ending horizontal value
///
///
/// The starting vertical value
///
///
/// The ending vertical value
///
///
/// The starting depth value
///
///
/// The ending depth value
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// Duration is less than zero
///
public Path3D(
float startX,
float endX,
float startY,
float endY,
float startZ,
float endZ,
ulong duration)
: this(new Path(startX, endX, duration), new Path(startY, endY, duration), new Path(startZ, endZ, duration))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting point in a 3D plane
///
///
/// The ending point in a 3D plane
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path3D(Float3D start, Float3D end, ulong duration, ulong delay, AnimationFunctions.Function function)
: this(
new Path(start.X, end.X, duration, delay, function),
new Path(start.Y, end.Y, duration, delay, function),
new Path(start.Z, end.Z, duration, delay, function))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting point in a 3D plane
///
///
/// The ending point in a 3D plane
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The time in miliseconds that the animator must wait before playing this path
///
///
/// Duration is less than zero
///
public Path3D(Float3D start, Float3D end, ulong duration, ulong delay)
: this(
new Path(start.X, end.X, duration, delay),
new Path(start.Y, end.Y, duration, delay),
new Path(start.Z, end.Z, duration, delay))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting point in a 3D plane
///
///
/// The ending point in a 3D plane
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// The animation function
///
///
/// Duration is less than zero
///
public Path3D(Float3D start, Float3D end, ulong duration, AnimationFunctions.Function function)
: this(
new Path(start.X, end.X, duration, function),
new Path(start.Y, end.Y, duration, function),
new Path(start.Z, end.Z, duration, function))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The starting point in a 3D plane
///
///
/// The ending point in a 3D plane
///
///
/// The time in miliseconds that the animator must play this path
///
///
/// Duration is less than zero
///
public Path3D(Float3D start, Float3D end, ulong duration)
: this(
new Path(start.X, end.X, duration),
new Path(start.Y, end.Y, duration),
new Path(start.Z, end.Z, duration))
{
}
///
/// Initializes a new instance of the class.
///
///
/// The horizontal path.
///
///
/// The vertical path.
///
///
/// The depth path.
///
public Path3D(Path x, Path y, Path z)
{
HorizontalPath = x;
VerticalPath = y;
DepthPath = z;
}
///
/// Gets the horizontal path
///
public Path HorizontalPath { get; }
///
/// Gets the vertical path
///
public Path VerticalPath { get; }
///
/// Gets the depth path
///
public Path DepthPath { get; }
///
/// Gets the starting point of the path
///
public Float3D Start => new Float3D(HorizontalPath.Start, VerticalPath.Start, DepthPath.Start);
///
/// Gets the ending point of the path
///
public Float3D End => new Float3D(HorizontalPath.End, VerticalPath.End, DepthPath.End);
///
/// Creates and returns a new based on the current path but in reverse order
///
///
/// A new which is the reverse of the current
///
public Path3D Reverse()
{
return new Path3D(HorizontalPath.Reverse(), VerticalPath.Reverse(), DepthPath.Reverse());
}
}
}
================================================
FILE: WinFormAnimation/Path3DExtensions.cs
================================================
using System.Linq;
namespace WinFormAnimation
{
///
/// Contains public extensions methods about Path3D class
///
public static class Path3DExtensions
{
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D[] paths, Float3D end, ulong duration)
{
return paths.Concat(new[] {new Path3D(paths.Last().End, end, duration)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D[] paths, Float3D end, ulong duration,
AnimationFunctions.Function function)
{
return paths.Concat(new[] {new Path3D(paths.Last().End, end, duration, function)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D[] paths, Float3D end, ulong duration, ulong delay)
{
return paths.Concat(new[] {new Path3D(paths.Last().End, end, duration, delay)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D[] paths, Float3D end, ulong duration, ulong delay,
AnimationFunctions.Function function)
{
return paths.Concat(new[] {new Path3D(paths.Last().End, end, duration, delay, function)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Depth value of the next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D[] paths, float endX, float endY, float endZ, ulong duration)
{
return paths.Concat(new[] {new Path3D(paths.Last().End, new Float3D(endX, endY, endZ), duration)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Depth value of the next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D[] paths, float endX, float endY, float endZ, ulong duration,
AnimationFunctions.Function function)
{
return
paths.Concat(new[] {new Path3D(paths.Last().End, new Float3D(endX, endY, endZ), duration, function)})
.ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Depth value of the next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D[] paths, float endX, float endY, float endZ, ulong duration,
ulong delay)
{
return
paths.Concat(new[] {new Path3D(paths.Last().End, new Float3D(endX, endY, endZ), duration, delay)})
.ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Depth value of the next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D[] paths, float endX, float endY, float endZ, ulong duration,
ulong delay,
AnimationFunctions.Function function)
{
return
paths.Concat(new[]
{new Path3D(paths.Last().End, new Float3D(endX, endY, endZ), duration, delay, function)})
.ToArray();
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D path, Float3D end, ulong duration)
{
return path.ToArray().ContinueTo(end, duration);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D path, Float3D end, ulong duration,
AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(end, duration, function);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D path, Float3D end, ulong duration, ulong delay)
{
return path.ToArray().ContinueTo(end, duration, delay);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D path, Float3D end, ulong duration, ulong delay,
AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(end, duration, delay, function);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Depth value of the next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D path, float endX, float endY, float endZ, ulong duration)
{
return path.ToArray().ContinueTo(endX, endY, endZ, duration);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Depth value of the next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D path, float endX, float endY, float endZ, ulong duration,
AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(endX, endY, endZ, duration, function);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Depth value of the next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D path, float endX, float endY, float endZ, ulong duration,
ulong delay)
{
return path.ToArray().ContinueTo(endX, endY, endZ, duration, delay);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Horizontal value of the next point to follow
/// Vertical value of the next point to follow
/// Depth value of the next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path3D[] ContinueTo(this Path3D path, float endX, float endY, float endZ, ulong duration,
ulong delay,
AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(endX, endY, endZ, duration, delay, function);
}
///
/// Continue the path array with a new ones
///
/// Array of paths
/// An array of new paths to adds
/// An array of paths including the new ones
public static Path3D[] ContinueTo(this Path3D[] paths, params Path3D[] newPaths)
{
return paths.Concat(newPaths).ToArray();
}
///
/// Continue the path with a new ones
///
/// The path to continue
/// An array of new paths to adds
/// An array of paths including the new ones
public static Path3D[] ContinueTo(this Path3D path, params Path3D[] newPaths)
{
return path.ToArray().ContinueTo(newPaths);
}
///
/// Contains a single path in an array
///
/// The path to add to the array
/// An array of paths including the new ones
public static Path3D[] ToArray(this Path3D path)
{
return new[] {path};
}
}
}
================================================
FILE: WinFormAnimation/PathExtensions.cs
================================================
using System.Linq;
namespace WinFormAnimation
{
///
/// Contains public extensions methods about Path class
///
public static class PathExtensions
{
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path[] ContinueTo(this Path[] paths, float end, ulong duration)
{
return paths.Concat(new[] {new Path(paths.Last().End, end, duration)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path[] ContinueTo(this Path[] paths, float end, ulong duration,
AnimationFunctions.Function function)
{
return paths.Concat(new[] {new Path(paths.Last().End, end, duration, function)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path[] ContinueTo(this Path[] paths, float end, ulong duration, ulong delay)
{
return paths.Concat(new[] {new Path(paths.Last().End, end, duration, delay)}).ToArray();
}
///
/// Continue the last paths with a new one
///
/// Array of paths
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path[] ContinueTo(this Path[] paths, float end, ulong duration, ulong delay,
AnimationFunctions.Function function)
{
return paths.Concat(new[] {new Path(paths.Last().End, end, duration, delay, function)}).ToArray();
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// An array of paths including the newly created one
public static Path[] ContinueTo(this Path path, float end, ulong duration)
{
return path.ToArray().ContinueTo(end, duration);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// Animation controller function
/// An array of paths including the newly created one
public static Path[] ContinueTo(this Path path, float end, ulong duration, AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(end, duration, function);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// An array of paths including the newly created one
public static Path[] ContinueTo(this Path path, float end, ulong duration, ulong delay)
{
return path.ToArray().ContinueTo(end, duration, delay);
}
///
/// Continue the path with a new one
///
/// The path to continue
/// Next point to follow
/// Duration of the animation
/// Starting delay
/// Animation controller function
/// An array of paths including the newly created one
public static Path[] ContinueTo(this Path path, float end, ulong duration, ulong delay,
AnimationFunctions.Function function)
{
return path.ToArray().ContinueTo(end, duration, delay, function);
}
///
/// Continue the path array with a new ones
///
/// Array of paths
/// An array of new paths to adds
/// An array of paths including the new ones
public static Path[] ContinueTo(this Path[] paths, params Path[] newPaths)
{
return paths.Concat(newPaths).ToArray();
}
///
/// Continue the path with a new ones
///
/// The path to continue
/// An array of new paths to adds
/// An array of paths including the new ones
public static Path[] ContinueTo(this Path path, params Path[] newPaths)
{
return path.ToArray().ContinueTo(newPaths);
}
///
/// Contains a single path in an array
///
/// The path to add to the array
/// An array of paths including the new ones
public static Path[] ToArray(this Path path)
{
return new[] {path};
}
}
}
================================================
FILE: WinFormAnimation/SafeInvoker.cs
================================================
using System;
using System.Reflection;
using System.Threading;
namespace WinFormAnimation
{
///
/// The safe invoker class is a delegate reference holder that always
/// execute them in the correct thread based on the passed control.
///
public class SafeInvoker
{
private MethodInfo _invokeMethod;
private PropertyInfo _invokeRequiredProperty;
private object _targetControl;
///
/// Initializes a new instance of the SafeInvoker class.
///
///
/// The callback to be invoked
///
///
/// The control to be used to invoke the callback in UI thread
///
public SafeInvoker(Action action, object targetControl) : this((Delegate) action, targetControl)
{
}
///
/// Initializes a new instance of the SafeInvoker class.
///
///
/// The callback to be invoked
///
///
/// The control to be used to invoke the callback in UI thread
///
protected SafeInvoker(Delegate action, object targetControl)
{
UnderlyingDelegate = action;
if (targetControl != null)
{
TargetControl = targetControl;
}
}
///
/// Initializes a new instance of the SafeInvoker class.
///
///
/// The callback to be invoked
///
public SafeInvoker(Action action) : this(action, null)
{
}
///
/// Gets or sets the reference to the control thats going to be used to invoke the callback in UI thread
///
protected object TargetControl
{
get { return _targetControl; }
set
{
_invokeRequiredProperty = value.GetType()
.GetProperty("InvokeRequired", BindingFlags.Instance | BindingFlags.Public);
_invokeMethod = value.GetType()
.GetMethod(
"Invoke",
BindingFlags.Instance | BindingFlags.Public,
Type.DefaultBinder,
new[] {typeof(Delegate)},
null);
if (_invokeRequiredProperty != null && _invokeMethod != null)
{
_targetControl = value;
}
}
}
///
/// Gets the reference to the callback to be invoked
///
protected Delegate UnderlyingDelegate { get; }
///
/// Invoke the contained callback
///
public virtual void Invoke()
{
Invoke(null);
}
///
/// Invoke the referenced callback
///
/// The argument to send to the callback
protected void Invoke(object value)
{
try
{
ThreadPool.QueueUserWorkItem(
state =>
{
try
{
if (TargetControl != null && (bool)_invokeRequiredProperty.GetValue(TargetControl, null))
{
_invokeMethod.Invoke(
TargetControl,
new object[]
{
new Action(
() => UnderlyingDelegate.DynamicInvoke(value != null ? new[] {value} : null))
});
return;
}
}
catch
{
// ignored
}
UnderlyingDelegate.DynamicInvoke(value != null ? new[] {value} : null);
});
}
catch
{
// ignored
}
}
}
}
================================================
FILE: WinFormAnimation/SafeInvoker`1.cs
================================================
using System;
namespace WinFormAnimation
{
///
/// The safe invoker class is a delegate reference holder that always
/// execute them in the correct thread based on the passed control.
///
public class SafeInvoker : SafeInvoker
{
///
/// Initializes a new instance of the SafeInvoker class.
///
///
/// The callback to be invoked
///
///
/// The control to be used to invoke the callback in UI thread
///
public SafeInvoker(Action action, object targetControl) : base(action, targetControl)
{
}
///
/// Initializes a new instance of the SafeInvoker class.
///
///
/// The callback to be invoked
///
public SafeInvoker(Action action) : this(action, null)
{
}
///
/// Invoke the contained callback with the specified value as the parameter
///
///
public void Invoke(T value)
{
Invoke((object) value);
}
}
}
================================================
FILE: WinFormAnimation/Timer.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace WinFormAnimation
{
///
/// The timer class, will execute your code in specific time frames
///
public class Timer
{
private static Thread _timerThread;
private static readonly object LockHandle = new object();
private static readonly long StartTimeAsMs = DateTime.Now.Ticks;
private static readonly List Subscribers = new List();
private readonly Action _callback;
///
/// Initializes a new instance of the class.
///
///
/// The callback to be executed at each tick
///
///
/// The max ticks per second
///
public Timer(Action callback, FPSLimiterKnownValues fpsKnownLimit = FPSLimiterKnownValues.LimitThirty)
: this(callback, (int) fpsKnownLimit)
{
}
///
/// Initializes a new instance of the class.
///
///
/// The callback to be executed at each tick
///
///
/// The max ticks per second
///
public Timer(Action callback, int fpsLimit)
{
if (callback == null)
{
throw new ArgumentNullException(nameof(callback));
}
_callback = callback;
FrameLimiter = fpsLimit;
lock (LockHandle)
{
if (_timerThread == null)
{
(_timerThread = new Thread(ThreadCycle) {IsBackground = true}).Start();
}
}
}
///
/// Gets the time of the last frame/tick related to the global-timer start reference
///
public long LastTick { get; private set; }
///
/// Gets or sets the maximum frames/ticks per second
///
public int FrameLimiter { get; set; }
///
/// Gets the time of the first frame/tick related to the global-timer start reference
///
public long FirstTick { get; private set; }
private void Tick()
{
if ((1000/FrameLimiter) < (GetTimeDifferenceAsMs() - LastTick))
{
LastTick = GetTimeDifferenceAsMs();
_callback((ulong) (LastTick - FirstTick));
}
}
private static long GetTimeDifferenceAsMs()
{
return (DateTime.Now.Ticks - StartTimeAsMs)/10000;
}
private static void ThreadCycle()
{
while (true)
{
try
{
bool hibernate;
lock (Subscribers)
{
hibernate = Subscribers.Count == 0;
if (!hibernate)
{
foreach (var t in Subscribers.ToList())
{
t.Tick();
}
}
}
Thread.Sleep(hibernate ? 50 : 1);
}
catch
{
// ignored
}
}
// ReSharper disable once FunctionNeverReturns
}
///
/// The method to reset the time of the starting frame/tick
///
public void ResetClock()
{
FirstTick = GetTimeDifferenceAsMs();
}
///
/// The method to resume the timer after stopping it
///
public void Resume()
{
lock (Subscribers)
if (!Subscribers.Contains(this))
{
FirstTick += GetTimeDifferenceAsMs() - LastTick;
Subscribers.Add(this);
}
}
///
/// The method to start the timer from the beginning
///
public void Start()
{
lock (Subscribers)
if (!Subscribers.Contains(this))
{
FirstTick = GetTimeDifferenceAsMs();
Subscribers.Add(this);
}
}
///
/// The method to stop the timer from generating any new ticks/frames
///
public void Stop()
{
lock (Subscribers)
if (Subscribers.Contains(this))
{
Subscribers.Remove(this);
}
}
}
}
================================================
FILE: WinFormAnimation/WinFormAnimation.csproj
================================================
net4
WinFormAnimation
1.6.0.4
Soroush Falahati
A simple library for animating controls/values in .Net using key-frames.
https://github.com/falahati/WinFormAnimation/blob/master/LICENSE
https://falahati.github.io/WinFormAnimation/
https://github.com/falahati/WinFormAnimation/blob/master/WinFormAnimation/Icon.png?raw=true
https://github.com/falahati/WinFormAnimatio
true
true
en-US
Copyright (c) 2019 Soroush Falahati
AnyCPU
Key-Frame Based Animation Library (.Net 4+)
OpenSourceStrongNameSignKey.pfx
all
runtime; build; native; contentfiles; analyzers
true
\
true
\
..\Debug
True
true
..\Release
true
================================================
FILE: WinFormAnimation/float2D.cs
================================================
using System;
using System.Drawing;
namespace WinFormAnimation
{
///
/// The Float2D class contains two values and
/// represents a point in a 2D plane
///
public class Float2D : IConvertible, IEquatable, IEquatable, IEquatable, IEquatable,
IEquatable
{
///
/// Initializes a new instance of the class.
///
///
/// The horizontal value
///
///
/// The vertical value
///
public Float2D(float x, float y)
{
X = x;
Y = y;
}
///
/// Initializes a new instance of the class.
///
public Float2D() : this(default(float), default(float))
{
}
///
/// Gets the horizontal value of the point
///
public float X { get; set; }
///
/// Gets the vertical value of the point
///
public float Y { get; set; }
///
/// Returns the for this instance.
///
///
/// The enumerated constant that is the of the class or value type that implements
/// this interface.
///
public TypeCode GetTypeCode()
{
return TypeCode.Object;
}
///
/// Converts the value of this instance to an equivalent Boolean value using the specified culture-specific formatting
/// information.
///
///
/// A Boolean value equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public bool ToBoolean(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified culture-specific
/// formatting information.
///
///
/// An 8-bit unsigned integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public byte ToByte(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent Unicode character using the specified culture-specific
/// formatting information.
///
///
/// A Unicode character equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public char ToChar(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent using the specified
/// culture-specific formatting information.
///
///
/// A instance equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public DateTime ToDateTime(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent number using the specified
/// culture-specific formatting information.
///
///
/// A number equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public decimal ToDecimal(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent double-precision floating-point number using the specified
/// culture-specific formatting information.
///
///
/// A double-precision floating-point number equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public double ToDouble(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 16-bit signed integer using the specified culture-specific
/// formatting information.
///
///
/// An 16-bit signed integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public short ToInt16(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 32-bit signed integer using the specified culture-specific
/// formatting information.
///
///
/// An 32-bit signed integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public int ToInt32(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 64-bit signed integer using the specified culture-specific
/// formatting information.
///
///
/// An 64-bit signed integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public long ToInt64(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture-specific
/// formatting information.
///
///
/// An 8-bit signed integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public sbyte ToSByte(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent single-precision floating-point number using the specified
/// culture-specific formatting information.
///
///
/// A single-precision floating-point number equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public float ToSingle(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified culture-specific
/// formatting information.
///
///
/// An 16-bit unsigned integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public ushort ToUInt16(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified culture-specific
/// formatting information.
///
///
/// An 32-bit unsigned integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public uint ToUInt32(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified culture-specific
/// formatting information.
///
///
/// An 64-bit unsigned integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public ulong ToUInt64(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent using the specified
/// culture-specific formatting information.
///
///
/// A instance equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
public string ToString(IFormatProvider provider)
{
return ToString();
}
///
/// Converts the value of this instance to an of the specified
/// that has an equivalent value, using the specified culture-specific formatting
/// information.
///
///
/// An instance of type whose value is equivalent to
/// the value of this instance.
///
/// The to which the value of this instance is converted.
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
public object ToType(Type conversionType, IFormatProvider provider)
{
if (conversionType == typeof (Point))
{
return (Point) this;
}
if (conversionType == typeof (Size))
{
return (Size) this;
}
if (conversionType == typeof (PointF))
{
return (PointF) this;
}
if (conversionType == typeof (SizeF))
{
return (SizeF) this;
}
throw new InvalidCastException();
}
///
/// Indicates whether the current object is equal to another object of the same type.
///
///
/// true if the current object is equal to the parameter; otherwise, false.
///
/// An object to compare with this object.
public bool Equals(Float2D other)
{
return this == other;
}
///
/// Indicates whether the current object is equal to a object.
///
///
/// true if the current object is equal to the parameter; otherwise, false.
///
/// An object to compare with this object.
public bool Equals(Point other)
{
return this == other;
}
///
/// Indicates whether the current object is equal to a object.
///
///
/// true if the current object is equal to the parameter; otherwise, false.
///
/// An object to compare with this object.
public bool Equals(PointF other)
{
return this == other;
}
///
/// Indicates whether the current object is equal to a object.
///
///
/// true if the current object is equal to the parameter; otherwise, false.
///
/// An object to compare with this object.
public bool Equals(Size other)
{
return this == other;
}
///
/// Indicates whether the current object is equal to a object.
///
///
/// true if the current object is equal to the parameter; otherwise, false.
///
/// An object to compare with this object.
public bool Equals(SizeF other)
{
return this == other;
}
///
/// Determines whether the specified is equal to the current
/// .
///
///
/// true if the specified is equal to the current ;
/// otherwise, false.
///
/// The to compare with the current .
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
var conversionType = obj.GetType();
if (conversionType == typeof (Point))
{
return this == (Point) obj;
}
if (conversionType == typeof (PointF))
{
return this == (PointF) obj;
}
if (conversionType == typeof (Size))
{
return this == (Size) obj;
}
if (conversionType == typeof (SizeF))
{
return this == (SizeF) obj;
}
return obj.GetType() == GetType() && Equals((Float2D) obj);
}
///
/// Serves as a hash function for a particular type. This code will change of the values of the X and Y changes. Make
/// sure to not change the values while stored in a hash dependent data structure.
///
///
/// A hash code for the current .
///
public override int GetHashCode()
{
unchecked
{
// ReSharper disable NonReadonlyMemberInGetHashCode
return (X.GetHashCode()*397) ^ Y.GetHashCode();
// ReSharper restore NonReadonlyMemberInGetHashCode
}
}
///
/// Compares two objects for equality
///
/// Left object
/// Right object
/// true if both objects are equal, otherwise false
public static bool operator ==(Float2D left, Float2D right)
{
if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return ReferenceEquals(left, null) && ReferenceEquals(right, null);
}
// ReSharper disable CompareOfFloatsByEqualityOperator
return ReferenceEquals(left, right) || ((double) (left.X) == right.X && (double) (left.Y) == right.Y);
// ReSharper restore CompareOfFloatsByEqualityOperator
}
///
/// Compares two objects for in-equality
///
/// Left object
/// Right object
/// false if both objects are equal, otherwise true
public static bool operator !=(Float2D left, Float2D right)
{
return !(left == right);
}
///
/// Represents the values as an instance of the class
///
///
/// The class to convert
///
///
/// A new instance of the class representing the values in the instance
///
public static implicit operator Size(Float2D float2D)
{
return new Size((int) float2D.X, (int) float2D.Y);
}
///
/// Represents the values as an instance of the class
///
///
/// The class to convert
///
///
/// A new instance of the class representing the values in the instance
///
public static implicit operator Point(Float2D float2D)
{
return new Point((int) float2D.X, (int) float2D.Y);
}
///
/// Represents the values as an instance of the class
///
///
/// The class to convert
///
///
/// A new instance of the class representing the values in the instance
///
public static implicit operator SizeF(Float2D float2D)
{
return new SizeF(float2D.X, float2D.Y);
}
///
/// Represents the values as an instance of the class
///
///
/// The class to convert
///
///
/// A new instance of the class representing the values in the instance
///
public static implicit operator PointF(Float2D float2D)
{
return new PointF(float2D.X, float2D.Y);
}
///
/// Returns a string that represents the current .
///
///
/// A string that represents the current .
///
public override string ToString()
{
return "(" + X.ToString("0.00") + "," + Y.ToString("0.00") + ")";
}
///
/// Creates and returns a new instance of the class from a instance
///
/// The object to create the instance from
/// The newly created instance
public static Float2D FromPoint(Point point)
{
return new Float2D(point.X, point.Y);
}
///
/// Creates and returns a new instance of the class from a instance
///
/// The object to create the instance from
/// The newly created instance
public static Float2D FromPoint(PointF point)
{
return new Float2D(point.X, point.Y);
}
///
/// Creates and returns a new instance of the class from a instance
///
/// The object to create the instance from
/// The newly created instance
public static Float2D FromSize(Size size)
{
return new Float2D(size.Width, size.Height);
}
///
/// Creates and returns a new instance of the class from a instance
///
/// The object to create the instance from
/// The newly created instance
public static Float2D FromSize(SizeF size)
{
return new Float2D(size.Width, size.Height);
}
}
}
================================================
FILE: WinFormAnimation/float3D.cs
================================================
using System;
using System.Drawing;
namespace WinFormAnimation
{
///
/// The Float3D class contains two values and
/// represents a point in a 3D plane
///
public class Float3D : IConvertible, IEquatable, IEquatable
{
///
/// Initializes a new instance of the class.
///
///
/// The horizontal value
///
///
/// The vertical value
///
///
/// The depth value
///
public Float3D(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
///
/// Initializes a new instance of the class.
///
public Float3D() : this(default(float), default(float), default(float))
{
}
///
/// Gets the horizontal value of the point
///
public float X { get; set; }
///
/// Gets the vertical value of the point
///
public float Y { get; set; }
///
/// Gets the depth value of the point
///
public float Z { get; set; }
///
/// Returns the for this instance.
///
///
/// The enumerated constant that is the of the class or value type that implements
/// this interface.
///
public TypeCode GetTypeCode()
{
return TypeCode.Object;
}
///
/// Converts the value of this instance to an equivalent Boolean value using the specified culture-specific formatting
/// information.
///
///
/// A Boolean value equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public bool ToBoolean(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified culture-specific
/// formatting information.
///
///
/// An 8-bit unsigned integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public byte ToByte(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent Unicode character using the specified culture-specific
/// formatting information.
///
///
/// A Unicode character equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public char ToChar(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent using the specified
/// culture-specific formatting information.
///
///
/// A instance equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public DateTime ToDateTime(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent number using the specified
/// culture-specific formatting information.
///
///
/// A number equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public decimal ToDecimal(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent double-precision floating-point number using the specified
/// culture-specific formatting information.
///
///
/// A double-precision floating-point number equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public double ToDouble(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 16-bit signed integer using the specified culture-specific
/// formatting information.
///
///
/// An 16-bit signed integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public short ToInt16(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 32-bit signed integer using the specified culture-specific
/// formatting information.
///
///
/// An 32-bit signed integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public int ToInt32(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 64-bit signed integer using the specified culture-specific
/// formatting information.
///
///
/// An 64-bit signed integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public long ToInt64(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture-specific
/// formatting information.
///
///
/// An 8-bit signed integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public sbyte ToSByte(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent single-precision floating-point number using the specified
/// culture-specific formatting information.
///
///
/// A single-precision floating-point number equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public float ToSingle(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified culture-specific
/// formatting information.
///
///
/// An 16-bit unsigned integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public ushort ToUInt16(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified culture-specific
/// formatting information.
///
///
/// An 32-bit unsigned integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public uint ToUInt32(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified culture-specific
/// formatting information.
///
///
/// An 64-bit unsigned integer equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
/// This method is not supported
public ulong ToUInt64(IFormatProvider provider)
{
throw new InvalidCastException();
}
///
/// Converts the value of this instance to an equivalent using the specified
/// culture-specific formatting information.
///
///
/// A instance equivalent to the value of this instance.
///
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
public string ToString(IFormatProvider provider)
{
return ToString();
}
///
/// Converts the value of this instance to an of the specified
/// that has an equivalent value, using the specified culture-specific formatting
/// information.
///
///
/// An instance of type whose value is equivalent to
/// the value of this instance.
///
/// The to which the value of this instance is converted.
///
/// An interface implementation that supplies
/// culture-specific formatting information.
///
public object ToType(Type conversionType, IFormatProvider provider)
{
if (conversionType == typeof (Color))
{
return (Color) this;
}
throw new InvalidCastException();
}
///
/// Indicates whether the current object is equal to a object.
///
///
/// true if the current object is equal to the parameter; otherwise, false.
///
/// An object to compare with this object.
public bool Equals(Color other)
{
return this == other;
}
///
/// Indicates whether the current object is equal to another object of the same type.
///
///
/// true if the current object is equal to the parameter; otherwise, false.
///
/// An object to compare with this object.
public bool Equals(Float3D other)
{
return this == other;
}
///
/// Determines whether the specified is equal to the current
/// .
///
///
/// true if the specified is equal to the current ;
/// otherwise, false.
///
/// The to compare with the current .
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
var conversionType = obj.GetType();
if (conversionType == typeof (Color))
{
return this == (Color) obj;
}
return obj.GetType() == GetType() && Equals((Float3D) obj);
}
///
/// Serves as a hash function for a particular type. This code will change of the values of the X and Y changes. Make
/// sure to not change the values while stored in a hash dependent data structure.
///
///
/// A hash code for the current .
///
public override int GetHashCode()
{
unchecked
{
// ReSharper disable NonReadonlyMemberInGetHashCode
var hashCode = X.GetHashCode();
hashCode = (hashCode*397) ^ Y.GetHashCode();
hashCode = (hashCode*397) ^ Z.GetHashCode();
return hashCode;
// ReSharper restore NonReadonlyMemberInGetHashCode
}
}
///
/// Compares two objects for equality
///
/// Left object
/// Right object
/// true if both objects are equal, otherwise false
public static bool operator ==(Float3D left, Float3D right)
{
if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return ReferenceEquals(left, null) && ReferenceEquals(right, null);
}
// ReSharper disable CompareOfFloatsByEqualityOperator
return ReferenceEquals(left, right) ||
((double) (left.X) == right.X && (double) (left.Y) == right.Y && (double) (left.Z) == right.Z);
// ReSharper restore CompareOfFloatsByEqualityOperator
}
///
/// Compares two objects for in-equality
///
/// Left object
/// Right object
/// false if both objects are equal, otherwise true
public static bool operator !=(Float3D left, Float3D right)
{
return !(left == right);
}
///
/// Represents the values as an instance of the class
///
///
/// The class to convert
///
///
/// A new instance of the class representing the values in the instance
///
public static implicit operator Color(Float3D float3D)
{
return Color.FromArgb((int) float3D.X, (int) float3D.Y, (int) float3D.Z);
}
///
/// Returns a string that represents the current .
///
///
/// A string that represents the current .
///
public override string ToString()
{
return "(" + X.ToString("0.00") + "," + Y.ToString("0.00") + "," + Z.ToString("0.00") + ")";
}
///
/// Creates and returns a new instance of the class from a instance
///
/// The object to create the instance from
/// The newly created instance
public static Float3D FromColor(Color color)
{
return new Float3D(color.R, color.G, color.B);
}
}
}
================================================
FILE: WinFormAnimation/readme.txt
================================================
WinForm Animation Library
A simple library for animating controls/values in .Net
WinForm (.Net 3.5 and later).
=========================================================================
USAGE
Use the three 'Animator', 'Animator2D' and 'Animator3D' classes to
start an animation.
SAMPLE ON ONE DIMENSIONAL ANIMATION OF A PROPERTY
new Animator(new Path(0, 100, 5000))
.Play(pb_progress, Animator.KnownProperties.Value);
SAMPLE ON TWO DIMENSIONAL ANIMATION OF A PROPERTY
new Animator2D(
new Path2D(0, 100, -100, 200, 5000)
.ContinueTo(this.Location.ToFloat2D(), 2000, 3000))
.Play(this, Animator2D.KnownProperties.Location);
SAMPLE ON THREE DIMENSIONAL ANIMATION OF A PROPERTY
new Animator3D(
new Path3D(
Color.Blue.ToFloat3D(),
Color.Red.ToFloat3D(),
2000, 1000,
AnimationFunctions.CubicEaseIn),
FPSLimiterKnownValues.LimitTen)
.Play(c_customLabel, "CustomColor");
MORE SAMPLES:
Check the Project's Github page at:
https://github.com/falahati/WinFormAnimation
================================================
FILE: WinFormAnimation.Samples/Demo1.Designer.cs
================================================
namespace WinFormAnimation.Samples
{
partial class Demo1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.lbl_res = new System.Windows.Forms.Label();
this.btn_play = new System.Windows.Forms.Button();
this.btn_stop = new System.Windows.Forms.Button();
this.btn_pause = new System.Windows.Forms.Button();
this.btn_resume = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lbl_res
//
this.lbl_res.AutoSize = true;
this.lbl_res.Location = new System.Drawing.Point(69, 10);
this.lbl_res.Name = "lbl_res";
this.lbl_res.Size = new System.Drawing.Size(13, 13);
this.lbl_res.TabIndex = 4;
this.lbl_res.Text = "0";
//
// btn_play
//
this.btn_play.Location = new System.Drawing.Point(36, 3);
this.btn_play.Name = "btn_play";
this.btn_play.Size = new System.Drawing.Size(27, 24);
this.btn_play.TabIndex = 1;
this.btn_play.Text = ">";
this.btn_play.UseVisualStyleBackColor = true;
this.btn_play.Click += new System.EventHandler(this.PlayButton);
//
// btn_stop
//
this.btn_stop.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
this.btn_stop.Location = new System.Drawing.Point(3, 3);
this.btn_stop.Name = "btn_stop";
this.btn_stop.Size = new System.Drawing.Size(27, 24);
this.btn_stop.TabIndex = 0;
this.btn_stop.Text = "□";
this.btn_stop.UseVisualStyleBackColor = true;
this.btn_stop.Click += new System.EventHandler(this.StopButton);
//
// btn_pause
//
this.btn_pause.Location = new System.Drawing.Point(3, 33);
this.btn_pause.Name = "btn_pause";
this.btn_pause.Size = new System.Drawing.Size(27, 24);
this.btn_pause.TabIndex = 2;
this.btn_pause.Text = "| |";
this.btn_pause.UseVisualStyleBackColor = true;
this.btn_pause.Click += new System.EventHandler(this.PauseButton);
//
// btn_resume
//
this.btn_resume.Location = new System.Drawing.Point(36, 33);
this.btn_resume.Name = "btn_resume";
this.btn_resume.Size = new System.Drawing.Size(27, 24);
this.btn_resume.TabIndex = 3;
this.btn_resume.Text = ">";
this.btn_resume.UseVisualStyleBackColor = true;
this.btn_resume.Click += new System.EventHandler(this.ResumeButton);
//
// Demo1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.lbl_res);
this.Controls.Add(this.btn_play);
this.Controls.Add(this.btn_stop);
this.Controls.Add(this.btn_pause);
this.Controls.Add(this.btn_resume);
this.DoubleBuffered = true;
this.Name = "Demo1";
this.Size = new System.Drawing.Size(130, 66);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Label lbl_res;
private System.Windows.Forms.Button btn_play;
private System.Windows.Forms.Button btn_stop;
private System.Windows.Forms.Button btn_pause;
private System.Windows.Forms.Button btn_resume;
}
}
================================================
FILE: WinFormAnimation.Samples/Demo1.cs
================================================
using System;
using System.Windows.Forms;
namespace WinFormAnimation.Samples
{
internal partial class Demo1 : UserControl
{
private readonly Animator _animator = new Animator();
public Demo1()
{
InitializeComponent();
_animator.Paths = new Path(0, 100, 5000).ToArray();
}
private void PlayButton(object sender, EventArgs e)
{
_animator.Play(lbl_res, Animator.KnownProperties.Text);
}
private void StopButton(object sender, EventArgs e)
{
_animator.Stop();
}
private void ResumeButton(object sender, EventArgs e)
{
_animator.Resume();
}
private void PauseButton(object sender, EventArgs e)
{
_animator.Pause();
}
}
}
================================================
FILE: WinFormAnimation.Samples/Demo1.resx
================================================
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
================================================
FILE: WinFormAnimation.Samples/Demo2.Designer.cs
================================================
namespace WinFormAnimation.Samples
{
partial class Demo2
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.btn_play = new System.Windows.Forms.Button();
this.btn_stop = new System.Windows.Forms.Button();
this.btn_pause = new System.Windows.Forms.Button();
this.btn_resume = new System.Windows.Forms.Button();
this.pb_image = new System.Windows.Forms.PictureBox();
this.cb_repeat = new System.Windows.Forms.CheckBox();
this.cb_reverse = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.pb_image)).BeginInit();
this.SuspendLayout();
//
// btn_play
//
this.btn_play.Location = new System.Drawing.Point(36, 3);
this.btn_play.Name = "btn_play";
this.btn_play.Size = new System.Drawing.Size(27, 24);
this.btn_play.TabIndex = 1;
this.btn_play.Text = ">";
this.btn_play.UseVisualStyleBackColor = true;
this.btn_play.Click += new System.EventHandler(this.PlayButton);
//
// btn_stop
//
this.btn_stop.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
this.btn_stop.Location = new System.Drawing.Point(3, 3);
this.btn_stop.Name = "btn_stop";
this.btn_stop.Size = new System.Drawing.Size(27, 24);
this.btn_stop.TabIndex = 0;
this.btn_stop.Text = "□";
this.btn_stop.UseVisualStyleBackColor = true;
this.btn_stop.Click += new System.EventHandler(this.StopButton);
//
// btn_pause
//
this.btn_pause.Location = new System.Drawing.Point(3, 33);
this.btn_pause.Name = "btn_pause";
this.btn_pause.Size = new System.Drawing.Size(27, 24);
this.btn_pause.TabIndex = 2;
this.btn_pause.Text = "| |";
this.btn_pause.UseVisualStyleBackColor = true;
this.btn_pause.Click += new System.EventHandler(this.PauseButton);
//
// btn_resume
//
this.btn_resume.Location = new System.Drawing.Point(36, 33);
this.btn_resume.Name = "btn_resume";
this.btn_resume.Size = new System.Drawing.Size(27, 24);
this.btn_resume.TabIndex = 3;
this.btn_resume.Text = ">";
this.btn_resume.UseVisualStyleBackColor = true;
this.btn_resume.Click += new System.EventHandler(this.ResumeButton);
//
// pb_image
//
this.pb_image.Image = global::WinFormAnimation.Samples.Properties.Resources.star_32;
this.pb_image.Location = new System.Drawing.Point(69, 3);
this.pb_image.Name = "pb_image";
this.pb_image.Size = new System.Drawing.Size(32, 32);
this.pb_image.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pb_image.TabIndex = 5;
this.pb_image.TabStop = false;
//
// cb_repeat
//
this.cb_repeat.AutoSize = true;
this.cb_repeat.Location = new System.Drawing.Point(3, 63);
this.cb_repeat.Name = "cb_repeat";
this.cb_repeat.Size = new System.Drawing.Size(61, 17);
this.cb_repeat.TabIndex = 6;
this.cb_repeat.Text = "Repeat";
this.cb_repeat.UseVisualStyleBackColor = true;
this.cb_repeat.CheckedChanged += new System.EventHandler(this.RepeatChecked);
//
// cb_reverse
//
this.cb_reverse.AutoSize = true;
this.cb_reverse.Enabled = false;
this.cb_reverse.Location = new System.Drawing.Point(3, 86);
this.cb_reverse.Name = "cb_reverse";
this.cb_reverse.Size = new System.Drawing.Size(66, 17);
this.cb_reverse.TabIndex = 7;
this.cb_reverse.Text = "Reverse";
this.cb_reverse.UseVisualStyleBackColor = true;
this.cb_reverse.CheckedChanged += new System.EventHandler(this.ReverseChecked);
//
// Demo2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.cb_reverse);
this.Controls.Add(this.cb_repeat);
this.Controls.Add(this.pb_image);
this.Controls.Add(this.btn_play);
this.Controls.Add(this.btn_stop);
this.Controls.Add(this.btn_pause);
this.Controls.Add(this.btn_resume);
this.DoubleBuffered = true;
this.Name = "Demo2";
this.Size = new System.Drawing.Size(362, 159);
((System.ComponentModel.ISupportInitialize)(this.pb_image)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Button btn_play;
private System.Windows.Forms.Button btn_stop;
private System.Windows.Forms.Button btn_pause;
private System.Windows.Forms.Button btn_resume;
private System.Windows.Forms.PictureBox pb_image;
private System.Windows.Forms.CheckBox cb_repeat;
private System.Windows.Forms.CheckBox cb_reverse;
}
}
================================================
FILE: WinFormAnimation.Samples/Demo2.cs
================================================
using System;
using System.Windows.Forms;
namespace WinFormAnimation.Samples
{
internal partial class Demo2 : UserControl
{
private readonly Animator2D _animator = new Animator2D();
public Demo2()
{
InitializeComponent();
_animator.Paths = new Path2D(
new Path(70, 320, 2000, AnimationFunctions.CubicEaseOut),
new Path(5, 100, 2000, AnimationFunctions.CubicEaseIn))
.ContinueTo(new Path2D(
new Path(320, 70, 2000, 300, AnimationFunctions.ExponentialEaseInOut),
new Path(100, 5, 1700, 600, AnimationFunctions.Linear)));
}
private void PlayButton(object sender, EventArgs e)
{
_animator.Play(pb_image, Animator2D.KnownProperties.Location);
}
private void StopButton(object sender, EventArgs e)
{
_animator.Stop();
}
private void ResumeButton(object sender, EventArgs e)
{
_animator.Resume();
}
private void PauseButton(object sender, EventArgs e)
{
_animator.Pause();
}
private void RepeatChecked(object sender, EventArgs e)
{
_animator.Repeat = cb_repeat.Checked;
cb_reverse.Enabled = cb_repeat.Checked;
}
private void ReverseChecked(object sender, EventArgs e)
{
_animator.ReverseRepeat = cb_reverse.Checked;
}
}
}
================================================
FILE: WinFormAnimation.Samples/Demo2.resx
================================================
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
================================================
FILE: WinFormAnimation.Samples/Demo3.Designer.cs
================================================
namespace WinFormAnimation.Samples
{
partial class Demo3
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.btn_play = new System.Windows.Forms.Button();
this.btn_stop = new System.Windows.Forms.Button();
this.btn_pause = new System.Windows.Forms.Button();
this.btn_resume = new System.Windows.Forms.Button();
this.p_color = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// btn_play
//
this.btn_play.Location = new System.Drawing.Point(36, 3);
this.btn_play.Name = "btn_play";
this.btn_play.Size = new System.Drawing.Size(27, 24);
this.btn_play.TabIndex = 5;
this.btn_play.Text = ">";
this.btn_play.UseVisualStyleBackColor = true;
this.btn_play.Click += new System.EventHandler(this.PlayButton);
//
// btn_stop
//
this.btn_stop.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
this.btn_stop.Location = new System.Drawing.Point(3, 3);
this.btn_stop.Name = "btn_stop";
this.btn_stop.Size = new System.Drawing.Size(27, 24);
this.btn_stop.TabIndex = 4;
this.btn_stop.Text = "□";
this.btn_stop.UseVisualStyleBackColor = true;
this.btn_stop.Click += new System.EventHandler(this.StopButton);
//
// btn_pause
//
this.btn_pause.Location = new System.Drawing.Point(3, 33);
this.btn_pause.Name = "btn_pause";
this.btn_pause.Size = new System.Drawing.Size(27, 24);
this.btn_pause.TabIndex = 6;
this.btn_pause.Text = "| |";
this.btn_pause.UseVisualStyleBackColor = true;
this.btn_pause.Click += new System.EventHandler(this.PauseButton);
//
// btn_resume
//
this.btn_resume.Location = new System.Drawing.Point(36, 33);
this.btn_resume.Name = "btn_resume";
this.btn_resume.Size = new System.Drawing.Size(27, 24);
this.btn_resume.TabIndex = 7;
this.btn_resume.Text = ">";
this.btn_resume.UseVisualStyleBackColor = true;
this.btn_resume.Click += new System.EventHandler(this.ResumeButton);
//
// p_color
//
this.p_color.BackColor = System.Drawing.Color.Aqua;
this.p_color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.p_color.Location = new System.Drawing.Point(70, 4);
this.p_color.Name = "p_color";
this.p_color.Size = new System.Drawing.Size(168, 53);
this.p_color.TabIndex = 8;
//
// Demo3
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.p_color);
this.Controls.Add(this.btn_play);
this.Controls.Add(this.btn_stop);
this.Controls.Add(this.btn_pause);
this.Controls.Add(this.btn_resume);
this.DoubleBuffered = true;
this.Name = "Demo3";
this.Size = new System.Drawing.Size(241, 63);
this.ResumeLayout(false);
}
private System.Windows.Forms.Button btn_play;
private System.Windows.Forms.Button btn_stop;
private System.Windows.Forms.Button btn_pause;
private System.Windows.Forms.Button btn_resume;
private System.Windows.Forms.Panel p_color;
}
}
================================================
FILE: WinFormAnimation.Samples/Demo3.cs
================================================
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace WinFormAnimation.Samples
{
internal partial class Demo3 : UserControl
{
private readonly Animator3D _animator = new Animator3D();
public Demo3()
{
InitializeComponent();
}
private void PlayButton(object sender, EventArgs e)
{
_animator.Stop();
_animator.Paths =
new Path3D(Color.Aqua.ToFloat3D(), Color.FromArgb(255, 128, 0).ToFloat3D(), 3000).ToArray();
_animator.Play(p_color, Animator3D.KnownProperties.BackColor, new SafeInvoker(() =>
{
_animator.Paths = _animator.Paths.Last().Reverse().ToArray();
_animator.Play(p_color, Animator3D.KnownProperties.BackColor);
}));
}
private void StopButton(object sender, EventArgs e)
{
_animator.Stop();
}
private void ResumeButton(object sender, EventArgs e)
{
_animator.Resume();
}
private void PauseButton(object sender, EventArgs e)
{
_animator.Pause();
}
}
}
================================================
FILE: WinFormAnimation.Samples/Demo3.resx
================================================
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
================================================
FILE: WinFormAnimation.Samples/Demo4.Designer.cs
================================================
namespace WinFormAnimation.Samples
{
partial class Demo4
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.nud_fps = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.nud_num = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.nud_dur = new System.Windows.Forms.NumericUpDown();
this.label4 = new System.Windows.Forms.Label();
this.lbl_fps = new System.Windows.Forms.Label();
this.lbl_cpu = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.btn_run = new System.Windows.Forms.Button();
this.lbl_time = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.cpu_timer = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.nud_fps)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nud_num)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nud_dur)).BeginInit();
this.SuspendLayout();
//
// nud_fps
//
this.nud_fps.Location = new System.Drawing.Point(69, 3);
this.nud_fps.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.nud_fps.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.nud_fps.Name = "nud_fps";
this.nud_fps.Size = new System.Drawing.Size(120, 20);
this.nud_fps.TabIndex = 1;
this.nud_fps.Value = new decimal(new int[] {
30,
0,
0,
0});
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(3, 5);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 13);
this.label1.TabIndex = 0;
this.label1.Text = "FPS Limiter";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(3, 31);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(58, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Animations";
//
// nud_num
//
this.nud_num.Location = new System.Drawing.Point(69, 29);
this.nud_num.Maximum = new decimal(new int[] {
5000,
0,
0,
0});
this.nud_num.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.nud_num.Name = "nud_num";
this.nud_num.Size = new System.Drawing.Size(120, 20);
this.nud_num.TabIndex = 3;
this.nud_num.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(3, 57);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(47, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Duration";
//
// nud_dur
//
this.nud_dur.Location = new System.Drawing.Point(69, 55);
this.nud_dur.Maximum = new decimal(new int[] {
100000,
0,
0,
0});
this.nud_dur.Minimum = new decimal(new int[] {
1000,
0,
0,
0});
this.nud_dur.Name = "nud_dur";
this.nud_dur.Size = new System.Drawing.Size(120, 20);
this.nud_dur.TabIndex = 5;
this.nud_dur.Value = new decimal(new int[] {
3000,
0,
0,
0});
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(279, 5);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(73, 13);
this.label4.TabIndex = 6;
this.label4.Text = "Average FPS:";
//
// lbl_fps
//
this.lbl_fps.AutoSize = true;
this.lbl_fps.Location = new System.Drawing.Point(358, 5);
this.lbl_fps.Name = "lbl_fps";
this.lbl_fps.Size = new System.Drawing.Size(10, 13);
this.lbl_fps.TabIndex = 7;
this.lbl_fps.Text = "-";
//
// lbl_cpu
//
this.lbl_cpu.AutoSize = true;
this.lbl_cpu.Location = new System.Drawing.Point(358, 31);
this.lbl_cpu.Name = "lbl_cpu";
this.lbl_cpu.Size = new System.Drawing.Size(10, 13);
this.lbl_cpu.TabIndex = 9;
this.lbl_cpu.Text = "-";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(279, 31);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(75, 13);
this.label7.TabIndex = 8;
this.label7.Text = "Average CPU:";
//
// btn_run
//
this.btn_run.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_run.Location = new System.Drawing.Point(464, 51);
this.btn_run.Name = "btn_run";
this.btn_run.Size = new System.Drawing.Size(160, 24);
this.btn_run.TabIndex = 10;
this.btn_run.Text = "RUN";
this.btn_run.UseVisualStyleBackColor = true;
this.btn_run.Click += new System.EventHandler(this.RunButton);
//
// lbl_time
//
this.lbl_time.AutoSize = true;
this.lbl_time.Location = new System.Drawing.Point(358, 57);
this.lbl_time.Name = "lbl_time";
this.lbl_time.Size = new System.Drawing.Size(10, 13);
this.lbl_time.TabIndex = 12;
this.lbl_time.Text = "-";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(279, 57);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(33, 13);
this.label6.TabIndex = 11;
this.label6.Text = "Time:";
//
// Demo4
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.lbl_time);
this.Controls.Add(this.label6);
this.Controls.Add(this.btn_run);
this.Controls.Add(this.lbl_cpu);
this.Controls.Add(this.label7);
this.Controls.Add(this.lbl_fps);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.nud_dur);
this.Controls.Add(this.label2);
this.Controls.Add(this.nud_num);
this.Controls.Add(this.label1);
this.Controls.Add(this.nud_fps);
this.Name = "Demo4";
this.Size = new System.Drawing.Size(627, 89);
((System.ComponentModel.ISupportInitialize)(this.nud_fps)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nud_num)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nud_dur)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.NumericUpDown nud_fps;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown nud_num;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown nud_dur;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label lbl_fps;
private System.Windows.Forms.Label lbl_cpu;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Button btn_run;
private System.Windows.Forms.Label lbl_time;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Timer cpu_timer;
}
}
================================================
FILE: WinFormAnimation.Samples/Demo4.cs
================================================
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
namespace WinFormAnimation.Samples
{
internal partial class Demo4 : UserControl
{
private readonly List _animators = new List();
private readonly Process _currentProcess = Process.GetCurrentProcess();
private readonly Stopwatch _stopWatch = new Stopwatch();
private int _cpuUsage;
private int _endedAnimations;
private int _frameHits;
public Demo4()
{
InitializeComponent();
}
private void RunButton(object sender, EventArgs e)
{
Enabled = false;
_animators.Clear();
_frameHits = 0;
_endedAnimations = 0;
var rnd = new Random();
for (var i = 0; i < nud_num.Value; i++)
{
_animators.Add(new Animator((FPSLimiterKnownValues) nud_fps.Value)
{
Paths = new[] {new Path(rnd.Next(1000), rnd.Next(1000), (ulong) nud_dur.Value)}
});
}
_cpuUsage = (int) _currentProcess.TotalProcessorTime.TotalMilliseconds;
_stopWatch.Reset();
_stopWatch.Start();
_animators.ForEach(a => { a.Play(new SafeInvoker(Hit, this), new SafeInvoker(End, this)); });
}
private void Hit(float value)
{
_frameHits += 1;
}
private void End()
{
_endedAnimations += 1;
if (_endedAnimations == nud_num.Value)
{
_stopWatch.Stop();
lbl_fps.Text =
$"{Round((decimal) (_frameHits/((_stopWatch.ElapsedMilliseconds/1000f)*(double) nud_num.Value)))} fps";
lbl_time.Text = $"{_stopWatch.ElapsedMilliseconds} ms";
lbl_cpu.Text =
$"{Round((decimal) ((_currentProcess.TotalProcessorTime.TotalMilliseconds - _cpuUsage)/_stopWatch.ElapsedMilliseconds)*(decimal) (100f/Environment.ProcessorCount))} % - {Environment.ProcessorCount} Cores";
Enabled = true;
}
}
private float Round(decimal n)
{
return (float) Math.Round(n, 2);
}
}
}
================================================
FILE: WinFormAnimation.Samples/Demo4.resx
================================================
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
17, 17
================================================
FILE: WinFormAnimation.Samples/MainForm.Designer.cs
================================================
namespace WinFormAnimation.Samples
{
partial class MainForm
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.demo41 = new WinFormAnimation.Samples.Demo4();
this.demo31 = new WinFormAnimation.Samples.Demo3();
this.demo21 = new WinFormAnimation.Samples.Demo2();
this.demo11 = new WinFormAnimation.Samples.Demo1();
this.SuspendLayout();
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(70, 13);
this.label1.TabIndex = 3;
this.label1.Text = "1D Animation";
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 92);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(70, 13);
this.label2.TabIndex = 4;
this.label2.Text = "3D Animation";
//
// label4
//
this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 174);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(61, 13);
this.label4.TabIndex = 7;
this.label4.Text = "Benchmark";
//
// demo41
//
this.demo41.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.demo41.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.demo41.Location = new System.Drawing.Point(12, 190);
this.demo41.Name = "demo41";
this.demo41.Size = new System.Drawing.Size(613, 82);
this.demo41.TabIndex = 6;
//
// demo31
//
this.demo31.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.demo31.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.demo31.Location = new System.Drawing.Point(12, 108);
this.demo31.Name = "demo31";
this.demo31.Size = new System.Drawing.Size(245, 63);
this.demo31.TabIndex = 2;
//
// demo21
//
this.demo21.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.demo21.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.demo21.Location = new System.Drawing.Point(263, 12);
this.demo21.Name = "demo21";
this.demo21.Size = new System.Drawing.Size(362, 159);
this.demo21.TabIndex = 1;
//
// demo11
//
this.demo11.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.demo11.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.demo11.Location = new System.Drawing.Point(12, 28);
this.demo11.Name = "demo11";
this.demo11.Size = new System.Drawing.Size(245, 61);
this.demo11.TabIndex = 0;
//
// frm_Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(639, 283);
this.Controls.Add(this.label4);
this.Controls.Add(this.demo41);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.demo31);
this.Controls.Add(this.demo21);
this.Controls.Add(this.demo11);
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frm_Main";
this.Opacity = 0D;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "WinForm Animation Library Samples";
this.Shown += new System.EventHandler(this.FormShown);
this.ResumeLayout(false);
this.PerformLayout();
}
private Demo1 demo11;
private Demo2 demo21;
private Demo3 demo31;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private Demo4 demo41;
private System.Windows.Forms.Label label4;
}
}
================================================
FILE: WinFormAnimation.Samples/MainForm.cs
================================================
using System;
using System.Windows.Forms;
namespace WinFormAnimation.Samples
{
internal partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void FormShown(object sender, EventArgs e)
{
new Animator(new Path(0, 1, 400, 100)).Play(this, Animator.KnownProperties.Opacity);
}
}
}
================================================
FILE: WinFormAnimation.Samples/MainForm.resx
================================================
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
================================================
FILE: WinFormAnimation.Samples/Program.cs
================================================
using System;
using System.Windows.Forms;
namespace WinFormAnimation.Samples
{
internal static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
================================================
FILE: WinFormAnimation.Samples/Properties/AssemblyInfo.cs
================================================
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Demo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Demo")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("071459e3-8a65-47e6-9d8b-ccff86732fe2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
================================================
FILE: WinFormAnimation.Samples/Properties/Resources.Designer.cs
================================================
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
namespace WinFormAnimation.Samples.Properties {
using System;
///
/// A strongly-typed resource class, for looking up localized strings, etc.
///
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinFormAnimation.Samples.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
internal static System.Drawing.Bitmap star_32 {
get {
object obj = ResourceManager.GetObject("star-32", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}
================================================
FILE: WinFormAnimation.Samples/Properties/Resources.resx
================================================
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
..\Resources\star-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
================================================
FILE: WinFormAnimation.Samples/Properties/Settings.Designer.cs
================================================
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
namespace WinFormAnimation.Samples.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}
================================================
FILE: WinFormAnimation.Samples/Properties/Settings.settings
================================================
================================================
FILE: WinFormAnimation.Samples/WinFormAnimation.Samples.csproj
================================================
Debug
AnyCPU
{EF38FA05-26F0-49DB-A18F-4C5B6303C77A}
WinExe
Properties
WinFormAnimation.Samples
WinFormAnimation.Samples
v4.0
512
AnyCPU
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
false
AnyCPU
pdbonly
true
bin\Release\
TRACE
prompt
4
false
UserControl
Demo2.cs
UserControl
Demo1.cs
UserControl
Demo3.cs
UserControl
Demo4.cs
Form
MainForm.cs
Demo2.cs
Designer
Demo1.cs
Designer
Demo3.cs
Designer
Demo4.cs
MainForm.cs
Designer
ResXFileCodeGenerator
Resources.Designer.cs
Designer
True
Resources.resx
True
SettingsSingleFileGenerator
Settings.Designer.cs
True
Settings.settings
True
{4fe3eb4d-c3f1-4715-aac5-c8671f646414}
WinFormAnimation
================================================
FILE: WinFormAnimation.Samples/app.config
================================================
================================================
FILE: WinFormAnimation.sln
================================================
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormAnimation", "WinFormAnimation\WinFormAnimation.csproj", "{4FE3EB4D-C3F1-4715-AAC5-C8671F646414}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormAnimation.Samples", "WinFormAnimation.Samples\WinFormAnimation.Samples.csproj", "{EF38FA05-26F0-49DB-A18F-4C5B6303C77A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4FE3EB4D-C3F1-4715-AAC5-C8671F646414}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FE3EB4D-C3F1-4715-AAC5-C8671F646414}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FE3EB4D-C3F1-4715-AAC5-C8671F646414}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FE3EB4D-C3F1-4715-AAC5-C8671F646414}.Release|Any CPU.Build.0 = Release|Any CPU
{EF38FA05-26F0-49DB-A18F-4C5B6303C77A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF38FA05-26F0-49DB-A18F-4C5B6303C77A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF38FA05-26F0-49DB-A18F-4C5B6303C77A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF38FA05-26F0-49DB-A18F-4C5B6303C77A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
================================================
FILE: WinFormAnimation.sln.DotSettings
================================================
FPS