基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,458 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Lskj.Control.ImageLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// 线性动画函数(算法基本由Silverlight提取出来)
|
||||
/// </summary>
|
||||
[Description("线性动画函数(算法基本由Silverlight提取出来)")]
|
||||
public static class AnimationCore
|
||||
{
|
||||
#region UniformMotion
|
||||
|
||||
/// <summary>
|
||||
/// 匀速
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <returns></returns>
|
||||
public static double UniformMotion(double origin, double transform, double usedTime, double allTime)
|
||||
{
|
||||
return origin + transform * UniformMotionCore(usedTime, allTime);
|
||||
}
|
||||
/// <summary>
|
||||
/// 匀速
|
||||
/// </summary>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <returns></returns>
|
||||
public static double UniformMotionCore(double usedTime, double allTime)
|
||||
{
|
||||
return usedTime / allTime;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Ease
|
||||
|
||||
/// <summary>
|
||||
/// 变速
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值2)</param>
|
||||
/// <returns></returns>
|
||||
public static double EaseIn(double origin, double transform, double usedTime, double allTime, double power)
|
||||
{
|
||||
return origin + transform * EaseInCore(usedTime / allTime, power);
|
||||
}
|
||||
/// <summary>
|
||||
/// 变速
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值2)</param>
|
||||
/// <returns></returns>
|
||||
public static double EaseInCore(double progressTime, double power)
|
||||
{
|
||||
power = Math.Max(0.0, power);
|
||||
return Math.Pow(progressTime, power);
|
||||
}
|
||||
/// <summary>
|
||||
/// 变速
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值2)</param>
|
||||
/// <returns></returns>
|
||||
public static double EaseOut(double origin, double transform, double usedTime, double allTime, double power)
|
||||
{
|
||||
return origin + transform * (EaseOutCore(usedTime / allTime, power));
|
||||
}
|
||||
/// <summary>
|
||||
/// 变速
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值2)</param>
|
||||
/// <returns></returns>
|
||||
public static double EaseOutCore(double progressTime, double power)
|
||||
{
|
||||
return 1.0 - EaseInCore(1.0 - progressTime, power);
|
||||
}
|
||||
/// <summary>
|
||||
/// 变速
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值2)</param>
|
||||
/// <returns></returns>
|
||||
public static double EaseBoth(double origin, double transform, double usedTime, double allTime, double power)
|
||||
{
|
||||
return origin + transform * EaseBothCore(usedTime / allTime, power);
|
||||
}
|
||||
/// <summary>
|
||||
/// 变速
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值2)</param>
|
||||
/// <returns></returns>
|
||||
public static double EaseBothCore(double progressTime, double power)
|
||||
{
|
||||
if (progressTime >= 0.5)
|
||||
return (1.0 - EaseInCore((1.0 - progressTime) * 2.0, power)) * 0.5 + 0.5;
|
||||
return EaseInCore(progressTime * 2.0, power) * 0.5;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Back
|
||||
|
||||
/// <summary>
|
||||
/// 收缩
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值3)</param>
|
||||
/// <param name="amplitude">收缩与相关联的幅度动画。此值必须大于或等于 0。 默认值为 1。</param>
|
||||
/// <returns></returns>
|
||||
public static double BackIn(double origin, double transform, double usedTime, double allTime, double power, double amplitude)
|
||||
{
|
||||
return origin + transform * BackInCore((usedTime / allTime), power, amplitude);
|
||||
}
|
||||
/// <summary>
|
||||
/// 收缩
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值3)</param>
|
||||
/// <param name="amplitude">收缩与相关联的幅度动画。此值必须大于或等于 0。 默认值为 1。</param>
|
||||
/// <returns></returns>
|
||||
public static double BackInCore(double progressTime, double power, double amplitude)
|
||||
{
|
||||
amplitude = Math.Max(0.0, amplitude);
|
||||
return Math.Pow(progressTime, power) - progressTime * amplitude * Math.Sin(Math.PI * progressTime);
|
||||
}
|
||||
/// <summary>
|
||||
/// 收缩
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值3)</param>
|
||||
/// <param name="amplitude">收缩与相关联的幅度动画。此值必须大于或等于 0。 默认值为 1。</param>
|
||||
/// <returns></returns>
|
||||
public static double BackOut(double origin, double transform, double usedTime, double allTime, double power, double amplitude)
|
||||
{
|
||||
return origin + transform * BackOutCore((usedTime / allTime), power, amplitude);
|
||||
}
|
||||
/// <summary>
|
||||
/// 收缩
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值3)</param>
|
||||
/// <param name="amplitude">收缩与相关联的幅度动画。此值必须大于或等于 0。 默认值为 1。</param>
|
||||
/// <returns></returns>
|
||||
public static double BackOutCore(double progressTime, double power, double amplitude)
|
||||
{
|
||||
return 1.0 - BackInCore(1.0 - progressTime, power, amplitude);
|
||||
}
|
||||
/// <summary>
|
||||
/// 收缩
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值3)</param>
|
||||
/// <param name="amplitude">收缩与相关联的幅度动画。此值必须大于或等于 0。 默认值为 1。</param>
|
||||
/// <returns></returns>
|
||||
public static double BackBoth(double origin, double transform, double usedTime, double allTime, double power, double amplitude)
|
||||
{
|
||||
return origin + transform * BackBothCore(usedTime / allTime, power, amplitude);
|
||||
}
|
||||
/// <summary>
|
||||
/// 收缩
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="power">动画曲线幂(默认值3)</param>
|
||||
/// <param name="amplitude">收缩与相关联的幅度动画。此值必须大于或等于 0。 默认值为 1。</param>
|
||||
/// <returns></returns>
|
||||
public static double BackBothCore(double progressTime, double power, double amplitude)
|
||||
{
|
||||
if (progressTime >= 0.5)
|
||||
return (1.0 - BackInCore((1.0 - progressTime) * 2.0, power, amplitude)) * 0.5 + 0.5;
|
||||
return BackInCore(progressTime * 2.0, power, amplitude) * 0.5;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Bounce
|
||||
|
||||
/// <summary>
|
||||
/// 弹球减振 加速
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="bounces">反弹次数。值必须大于或等于零(默认值为3)</param>
|
||||
/// <param name="bounciness">指定反弹动画的弹性大小。虽然较高的值都会导致反弹 (弹性较小),此属性中的结果很少或者反弹低值会丢失反弹 (弹性较大) 之间的高度。此值必须是正数(默认值为 2)</param>
|
||||
/// <returns></returns>
|
||||
public static double BounceIn(double origin, double transform, double usedTime, double allTime, int bounces, double bounciness)
|
||||
{
|
||||
return origin + transform * BounceInCore((usedTime / allTime), bounces, bounciness);
|
||||
}
|
||||
/// <summary>
|
||||
/// 弹球减振 加速
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="bounces">反弹次数。值必须大于或等于零(默认值为3)</param>
|
||||
/// <param name="bounciness">指定反弹动画的弹性大小。虽然较高的值都会导致反弹 (弹性较小),此属性中的结果很少或者反弹低值会丢失反弹 (弹性较大) 之间的高度。此值必须是正数(默认值为 2)</param>
|
||||
/// <returns></returns>
|
||||
public static double BounceInCore(double progressTime, int bounces, double bounciness)
|
||||
{
|
||||
double y1 = Math.Max(0.0, (double)bounces);
|
||||
double num1 = bounciness;
|
||||
if (num1 < 1.0 || Math.Abs(num1 - 1.0) < 2.22044604925031E-15)
|
||||
num1 = 1001.0 / 1000.0;
|
||||
double num2 = Math.Pow(num1, y1);
|
||||
double num3 = 1.0 - num1;
|
||||
double num4 = (1.0 - num2) / num3 + num2 * 0.5;
|
||||
double y2 = Math.Floor(Math.Log(-(progressTime * num4) * (1.0 - num1) + 1.0, num1));
|
||||
double y3 = y2 + 1.0;
|
||||
double num5 = (1.0 - Math.Pow(num1, y2)) / (num3 * num4);
|
||||
double num6 = (1.0 - Math.Pow(num1, y3)) / (num3 * num4);
|
||||
double num7 = (num5 + num6) * 0.5;
|
||||
double num8 = progressTime - num7;
|
||||
double num9 = num7 - num5;
|
||||
return -Math.Pow(1.0 / num1, y1 - y2) / (num9 * num9) * (num8 - num9) * (num8 + num9);
|
||||
}
|
||||
/// <summary>
|
||||
/// 加速 弹球减振
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="bounces">反弹次数。值必须大于或等于零(默认值为3)</param>
|
||||
/// <param name="bounciness">指定反弹动画的弹性大小。虽然较高的值都会导致反弹 (弹性较小),此属性中的结果很少或者反弹低值会丢失反弹 (弹性较大) 之间的高度。此值必须是正数(默认值为 2)</param>
|
||||
/// <returns></returns>
|
||||
public static double BounceOut(double origin, double transform, double usedTime, double allTime, int bounces, double bounciness)
|
||||
{
|
||||
return origin + transform * BounceOutCore((usedTime / allTime), bounces, bounciness);
|
||||
}
|
||||
/// <summary>
|
||||
/// 加速 弹球减振
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="bounces">反弹次数。值必须大于或等于零(默认值为3)</param>
|
||||
/// <param name="bounciness">指定反弹动画的弹性大小。虽然较高的值都会导致反弹 (弹性较小),此属性中的结果很少或者反弹低值会丢失反弹 (弹性较大) 之间的高度。此值必须是正数(默认值为 2)</param>
|
||||
/// <returns></returns>
|
||||
public static double BounceOutCore(double progressTime, int bounces, double bounciness)
|
||||
{
|
||||
return 1.0 - BounceInCore(1.0 - progressTime, bounces, bounciness);
|
||||
}
|
||||
/// <summary>
|
||||
/// 弹球减振 加速 弹球减振
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="bounces">反弹次数。值必须大于或等于零(默认值为3)</param>
|
||||
/// <param name="bounciness">指定反弹动画的弹性大小。虽然较高的值都会导致反弹 (弹性较小),此属性中的结果很少或者反弹低值会丢失反弹 (弹性较大) 之间的高度。此值必须是正数(默认值为 2)</param>
|
||||
/// <returns></returns>
|
||||
public static double BounceBoth(double origin, double transform, double usedTime, double allTime, int bounces, double bounciness)
|
||||
{
|
||||
return origin + transform * BounceBothCore(usedTime / allTime, bounces, bounciness);
|
||||
}
|
||||
/// <summary>
|
||||
/// 弹球减振 加速 弹球减振
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="bounces">反弹次数。值必须大于或等于零(默认值为3)</param>
|
||||
/// <param name="bounciness">指定反弹动画的弹性大小。虽然较高的值都会导致反弹 (弹性较小),此属性中的结果很少或者反弹低值会丢失反弹 (弹性较大) 之间的高度。此值必须是正数(默认值为 2)</param>
|
||||
/// <returns></returns>
|
||||
public static double BounceBothCore(double progressTime, int bounces, double bounciness)
|
||||
{
|
||||
if (progressTime >= 0.5)
|
||||
return (1.0 - BounceInCore((1.0 - progressTime) * 2.0, bounces, bounciness)) * 0.5 + 0.5;
|
||||
return BounceInCore(progressTime * 2.0, bounces, bounciness) * 0.5;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Elastic
|
||||
|
||||
/// <summary>
|
||||
/// Elastic
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="oscillations">目标来回滑过动画目标的次数。此值必须大于或等于0 (默认值为3)</param>
|
||||
/// <param name="springiness">弹簧铡度。 越小的 Springiness 值为,严格 spring,通过每个振动的强度减小的速度越快弹性。一个正数(默认值为3)</param>
|
||||
/// <returns></returns>
|
||||
public static double ElasticIn(double origin, double transform, double usedTime, double allTime, int oscillations, double springiness)
|
||||
{
|
||||
return origin + transform * ElasticInCore((usedTime / allTime), oscillations, springiness);
|
||||
}
|
||||
/// <summary>
|
||||
/// Elastic
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="oscillations">目标来回滑过动画目标的次数。此值必须大于或等于0 (默认值为3)</param>
|
||||
/// <param name="springiness">弹簧铡度。 越小的 Springiness 值为,严格 spring,通过每个振动的强度减小的速度越快弹性。一个正数(默认值为3)</param>
|
||||
/// <returns></returns>
|
||||
public static double ElasticInCore(double progressTime, int oscillations, double springiness)
|
||||
{
|
||||
oscillations = Math.Max(0, oscillations);
|
||||
springiness = Math.Max(0.0, springiness);
|
||||
return (!(Math.Abs(springiness) < 2.22044604925031E-15) ? (Math.Exp(springiness * progressTime) - 1.0) / (Math.Exp(springiness) - 1.0) : progressTime) * Math.Sin((2.0 * Math.PI * oscillations + Math.PI / 2.0) * progressTime);
|
||||
}
|
||||
/// <summary>
|
||||
/// Elastic
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="oscillations">目标来回滑过动画目标的次数。此值必须大于或等于0 (默认值为3)</param>
|
||||
/// <param name="springiness">弹簧铡度。 越小的 Springiness 值为,严格 spring,通过每个振动的强度减小的速度越快弹性。一个正数(默认值为3)</param>
|
||||
/// <returns></returns>
|
||||
public static double ElasticOut(double origin, double transform, double usedTime, double allTime, int oscillations, double springiness)
|
||||
{
|
||||
return origin + transform * ElasticOutCore((usedTime / allTime), oscillations, springiness);
|
||||
}
|
||||
/// <summary>
|
||||
/// Elastic
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="oscillations">目标来回滑过动画目标的次数。此值必须大于或等于0 (默认值为3)</param>
|
||||
/// <param name="springiness">弹簧铡度。 越小的 Springiness 值为,严格 spring,通过每个振动的强度减小的速度越快弹性。一个正数(默认值为3)</param>
|
||||
/// <returns></returns>
|
||||
public static double ElasticOutCore(double progressTime, int oscillations, double springiness)
|
||||
{
|
||||
return 1.0 - ElasticInCore(1.0 - progressTime, oscillations, springiness);
|
||||
}
|
||||
/// <summary>
|
||||
/// Elastic
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <param name="oscillations">目标来回滑过动画目标的次数。此值必须大于或等于0 (默认值为3)</param>
|
||||
/// <param name="springiness">弹簧铡度。 越小的 Springiness 值为,严格 spring,通过每个振动的强度减小的速度越快弹性。一个正数(默认值为3)</param>
|
||||
/// <returns></returns>
|
||||
public static double ElasticBoth(double origin, double transform, double usedTime, double allTime, int oscillations, double springiness)
|
||||
{
|
||||
return origin + transform * ElasticBothCore(usedTime / allTime, oscillations, springiness);
|
||||
}
|
||||
/// <summary>
|
||||
/// Elastic
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <param name="oscillations">目标来回滑过动画目标的次数。此值必须大于或等于0 (默认值为3)</param>
|
||||
/// <param name="springiness">弹簧铡度。 越小的 Springiness 值为,严格 spring,通过每个振动的强度减小的速度越快弹性。一个正数(默认值为3)</param>
|
||||
/// <returns></returns>
|
||||
public static double ElasticBothCore(double progressTime, int oscillations, double springiness)
|
||||
{
|
||||
if (progressTime >= 0.5)
|
||||
return (1.0 - ElasticInCore((1.0 - progressTime) * 2.0, oscillations, springiness)) * 0.5 + 0.5;
|
||||
return ElasticInCore(progressTime * 2.0, oscillations, springiness) * 0.5;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Quadratic
|
||||
|
||||
/// <summary>
|
||||
/// 二次
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <returns></returns>
|
||||
public static double QuadraticIn(double origin, double transform, double usedTime, double allTime)
|
||||
{
|
||||
return origin + transform * QuadraticInCore(usedTime / allTime);
|
||||
}
|
||||
/// <summary>
|
||||
/// 二次
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <returns></returns>
|
||||
public static double QuadraticInCore(double progressTime)
|
||||
{
|
||||
return -4 * Math.Pow((progressTime - 0.5), 2.0) + 1.0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 二次
|
||||
/// </summary>
|
||||
/// <param name="origin">要变换的起始值</param>
|
||||
/// <param name="transform">要变换的总值</param>
|
||||
/// <param name="usedTime">已进行动画时间</param>
|
||||
/// <param name="allTime">总动画时间</param>
|
||||
/// <returns></returns>
|
||||
public static double QuadraticOut(double origin, double transform, double usedTime, double allTime)
|
||||
{
|
||||
return origin + transform * QuadraticOutCore(usedTime / allTime);
|
||||
}
|
||||
/// <summary>
|
||||
/// 二次
|
||||
/// </summary>
|
||||
/// <param name="progressTime">已进行动画时间/总动画时间</param>
|
||||
/// <returns></returns>
|
||||
public static double QuadraticOutCore(double progressTime)
|
||||
{
|
||||
if (progressTime >= 0.5)
|
||||
{
|
||||
return 4 * Math.Pow((progressTime - 0.5 - 0.5), 2.0);
|
||||
}
|
||||
return 4 * Math.Pow((progressTime), 2.0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动画类型
|
||||
/// </summary>
|
||||
[Description("动画类型")]
|
||||
public enum AnimationTypes
|
||||
{
|
||||
UniformMotion,
|
||||
EaseIn,
|
||||
EaseOut,
|
||||
EaseBoth,
|
||||
BackIn,
|
||||
BackOut,
|
||||
BackBoth,
|
||||
BounceIn,
|
||||
BounceOut,
|
||||
BounceBoth,
|
||||
ElasticIn,
|
||||
ElasticOut,
|
||||
ElasticBoth,
|
||||
QuadraticIn,
|
||||
QuadraticOut
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,638 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Lskj.Control.ImageLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// 动画定时器类
|
||||
/// </summary>
|
||||
[Category("动画定时器类")]
|
||||
[DefaultProperty("Options")]
|
||||
[DefaultEvent("Animationing")]
|
||||
[TypeConverter(typeof(EmptyExpandableObjectConverter))]
|
||||
public class AnimationTimer : IDisposable
|
||||
{
|
||||
#region 新增事件
|
||||
|
||||
public delegate void AnimationEventHandler(object sender, AnimationEventArgs e);
|
||||
|
||||
private event AnimationEventHandler animationStart = null;
|
||||
/// <summary>
|
||||
/// 动画开始前事件
|
||||
/// </summary>
|
||||
[Description("动画开始前事件")]
|
||||
public event AnimationEventHandler AnimationStart
|
||||
{
|
||||
add { this.animationStart += value; }
|
||||
remove { this.animationStart -= value; }
|
||||
}
|
||||
|
||||
private event AnimationEventHandler animationing = null;
|
||||
/// <summary>
|
||||
/// 动画时间间隔发生事件
|
||||
/// </summary>
|
||||
[Description("动画时间间隔发生事件")]
|
||||
public event AnimationEventHandler Animationing
|
||||
{
|
||||
add { this.animationing += value; }
|
||||
remove { this.animationing -= value; }
|
||||
}
|
||||
|
||||
private event AnimationEventHandler animationEnding = null;
|
||||
/// <summary>
|
||||
/// 动画结束时事件
|
||||
/// </summary>
|
||||
[Description("动画结束时事件")]
|
||||
public event AnimationEventHandler AnimationEnding
|
||||
{
|
||||
add { this.animationEnding += value; }
|
||||
remove { this.animationEnding -= value; }
|
||||
}
|
||||
|
||||
private event AnimationEventHandler animationRepetition = null;
|
||||
/// <summary>
|
||||
/// 动画重复间隔时事件
|
||||
/// </summary>
|
||||
[Description("动画重复间隔时事件")]
|
||||
public event AnimationEventHandler AnimationRepetition
|
||||
{
|
||||
add { this.animationRepetition += value; }
|
||||
remove { this.animationRepetition -= value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 新增属性
|
||||
|
||||
public AnimationTypes animationType = AnimationTypes.EaseIn;
|
||||
/// <summary>
|
||||
/// 动画类型(默认值EaseIn)
|
||||
/// </summary>
|
||||
[Description("动画类型")]
|
||||
[DefaultValue(AnimationTypes.EaseIn)]
|
||||
public AnimationTypes AnimationType
|
||||
{
|
||||
get { return this.animationType; }
|
||||
set { this.animationType = value; }
|
||||
}
|
||||
|
||||
public System.Windows.Forms.Control _control = null;
|
||||
/// <summary>
|
||||
/// 动画所属控件
|
||||
/// </summary>
|
||||
[Description("动画所属控件")]
|
||||
[DefaultValue(null)]
|
||||
public System.Windows.Forms.Control Control
|
||||
{
|
||||
get { return this._control; }
|
||||
set { this._control = value; }
|
||||
}
|
||||
|
||||
private AnimationOptions options;
|
||||
/// <summary>
|
||||
/// 动画设置参数
|
||||
/// </summary>
|
||||
[Description("动画设置参数")]
|
||||
public AnimationOptions Options
|
||||
{
|
||||
get { return this.options; }
|
||||
set { this.options = value; }
|
||||
}
|
||||
|
||||
private int interval = 20;
|
||||
/// <summary>
|
||||
/// 动画定时器时间间隔(默认值20毫秒)
|
||||
/// </summary>
|
||||
[Description("动画定时器时间间隔")]
|
||||
[DefaultValue(20)]
|
||||
public int Interval
|
||||
{
|
||||
get { return this.interval; }
|
||||
set
|
||||
{
|
||||
if (this.interval == value)
|
||||
return;
|
||||
this.interval = value;
|
||||
if (this.timer != null)
|
||||
this.timer.Interval = this.interval;
|
||||
}
|
||||
}
|
||||
|
||||
private double animationUsedTime = 0.0;
|
||||
/// <summary>
|
||||
/// 动画已经使用了多少时间(默认值0.0毫秒)
|
||||
/// </summary>
|
||||
[Description("动画已经使用了多少时间(默认值0.0毫秒)")]
|
||||
[Browsable(false)]
|
||||
[DefaultValue(0.0)]
|
||||
public double AnimationUsedTime
|
||||
{
|
||||
get { return this.animationUsedTime; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 字段
|
||||
|
||||
private bool disposed = false;
|
||||
|
||||
/// <summary>
|
||||
/// 动画定时器
|
||||
/// </summary>
|
||||
private System.Windows.Forms.Timer timer = null;
|
||||
|
||||
/// <summary>
|
||||
/// 添加还是减少动画时间间隔(决定动画方向)
|
||||
/// </summary>
|
||||
private AnimationIntervalTypes intervalTypes = AnimationIntervalTypes.Add;
|
||||
|
||||
/// <summary>
|
||||
/// 动画进行中时间累计器
|
||||
/// </summary>
|
||||
[DefaultValue(0.0)]
|
||||
private double runTime = 0.0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 析构
|
||||
|
||||
/// <summary>
|
||||
/// 用于组件的初始化
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public AnimationTimer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="_control">要变化动画的控件</param>
|
||||
/// <param name="_options">动画配置</param>
|
||||
public AnimationTimer(System.Windows.Forms.Control _control, AnimationOptions _options)
|
||||
{
|
||||
this._control = _control;
|
||||
this.options = _options;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 公开方法
|
||||
|
||||
/// <summary>
|
||||
/// 动画开始
|
||||
/// </summary>
|
||||
/// <param name="_intervalTypes">添加还是减少动画时间间隔(决定动画方向)</param>
|
||||
/// <param name="_usedTime">动画已经使用了多少时间(默认值0.0毫秒)</param>
|
||||
public void Start(AnimationIntervalTypes _intervalTypes, double _usedTime)
|
||||
{
|
||||
this.intervalTypes = _intervalTypes;
|
||||
this.Stop();
|
||||
this.runTime = _usedTime;
|
||||
if (this.animationStart != null)
|
||||
{
|
||||
this.animationStart.Invoke(this._control, new AnimationEventArgs() { Data = this.options.Data, AllTransformValue = this.options.AllTransformValue, AnimationUsedTime = this.runTime, ProgressValue = GetProgress(this.AnimationType, this.options, this.runTime) });
|
||||
}
|
||||
if (this.timer == null || this.options.EveryNewTimer)
|
||||
{
|
||||
this.timer = new System.Windows.Forms.Timer();
|
||||
this.timer.Tick += new EventHandler(this.timer_Tick);
|
||||
this.timer.Interval = this.interval;
|
||||
}
|
||||
this.timer.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动画停止
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
if (this.timer != null)
|
||||
{
|
||||
this.timer.Enabled = false;
|
||||
if (this.options.EveryNewTimer)
|
||||
{
|
||||
this.timer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停
|
||||
/// </summary>
|
||||
public void Suspend()
|
||||
{
|
||||
if (this.timer != null)
|
||||
{
|
||||
this.timer.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 继续
|
||||
/// </summary>
|
||||
public void Continue()
|
||||
{
|
||||
if (this.timer != null)
|
||||
{
|
||||
this.timer.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取动画的进度(0.0-1.0)
|
||||
/// </summary>
|
||||
/// <param name="_animationType">动画类型</param>
|
||||
/// <param name="_options">动画参数</param>
|
||||
/// <param name="_usedTime">动画已经使用了多少时间</param>
|
||||
/// <returns></returns>
|
||||
public static double GetProgress(AnimationTypes _animationType, AnimationOptions _options, double _usedTime)
|
||||
{
|
||||
if (_usedTime <= 0)
|
||||
return 0.0;
|
||||
if (_usedTime >= _options.AllTransformTime)
|
||||
return 1.0;
|
||||
|
||||
double result = 0.0;
|
||||
|
||||
switch (_animationType)
|
||||
{
|
||||
case AnimationTypes.UniformMotion:
|
||||
result = AnimationCore.UniformMotionCore(_usedTime, _options.AllTransformTime);
|
||||
break;
|
||||
case AnimationTypes.EaseIn:
|
||||
result = AnimationCore.EaseInCore(_usedTime / _options.AllTransformTime, _options.Power);
|
||||
break;
|
||||
case AnimationTypes.EaseOut:
|
||||
result = AnimationCore.EaseOutCore(_usedTime / _options.AllTransformTime, _options.Power);
|
||||
break;
|
||||
case AnimationTypes.EaseBoth:
|
||||
result = AnimationCore.EaseBothCore(_usedTime / _options.AllTransformTime, _options.Power);
|
||||
break;
|
||||
case AnimationTypes.BackIn:
|
||||
result = AnimationCore.BackInCore(_usedTime / _options.AllTransformTime, _options.Power, _options.Amplitude);
|
||||
break;
|
||||
case AnimationTypes.BackOut:
|
||||
result = AnimationCore.BackOutCore(_usedTime / _options.AllTransformTime, _options.Power, _options.Amplitude);
|
||||
break;
|
||||
case AnimationTypes.BackBoth:
|
||||
result = AnimationCore.BackBothCore(_usedTime / _options.AllTransformTime, _options.Power, _options.Amplitude);
|
||||
break;
|
||||
case AnimationTypes.BounceIn:
|
||||
result = AnimationCore.BounceInCore(_usedTime / _options.AllTransformTime, _options.Bounces, _options.Bounciness);
|
||||
break;
|
||||
case AnimationTypes.BounceOut:
|
||||
result = AnimationCore.BounceOutCore(_usedTime / _options.AllTransformTime, _options.Bounces, _options.Bounciness);
|
||||
break;
|
||||
case AnimationTypes.BounceBoth:
|
||||
result = AnimationCore.BounceBothCore(_usedTime / _options.AllTransformTime, _options.Bounces, _options.Bounciness);
|
||||
break;
|
||||
case AnimationTypes.ElasticIn:
|
||||
result = AnimationCore.ElasticInCore(_usedTime / _options.AllTransformTime, _options.Oscillations, _options.Springiness);
|
||||
break;
|
||||
case AnimationTypes.ElasticOut:
|
||||
result = AnimationCore.ElasticOutCore(_usedTime / _options.AllTransformTime, _options.Oscillations, _options.Springiness);
|
||||
break;
|
||||
case AnimationTypes.ElasticBoth:
|
||||
result = AnimationCore.ElasticBothCore(_usedTime / _options.AllTransformTime, _options.Oscillations, _options.Springiness);
|
||||
break;
|
||||
case AnimationTypes.QuadraticIn:
|
||||
result = AnimationCore.QuadraticInCore(_usedTime / _options.AllTransformTime);
|
||||
break;
|
||||
case AnimationTypes.QuadraticOut:
|
||||
result = AnimationCore.QuadraticOutCore(_usedTime / _options.AllTransformTime);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 私有方法
|
||||
|
||||
/// <summary>
|
||||
/// 动画定时更新
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (this.intervalTypes == AnimationIntervalTypes.Add)
|
||||
this.runTime += this.timer.Interval;
|
||||
else
|
||||
this.runTime -= this.timer.Interval;
|
||||
|
||||
if ((this.runTime >= 0 && this.runTime < this.options.AllTransformTime) || this.options.AnimationTimerType == AnimationTimerTypes.AlwaysAnimation)
|
||||
{
|
||||
if (this.animationing != null)
|
||||
{
|
||||
this.animationUsedTime = this.runTime;
|
||||
this.animationing.Invoke(this._control, new AnimationEventArgs() { Data = this.options.Data, AllTransformValue = this.options.AllTransformValue, AnimationUsedTime = this.runTime, ProgressValue = GetProgress(this.AnimationType, this.options, this.runTime) });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.animationing != null)//保证最后一次百分百变化
|
||||
{
|
||||
this.animationUsedTime = this.runTime < 0 ? 0.0 : this.options.AllTransformTime;
|
||||
this.animationing.Invoke(this._control, new AnimationEventArgs() { Data = this.options.Data, AllTransformValue = this.options.AllTransformValue, AnimationUsedTime = this.runTime, ProgressValue = GetProgress(this.AnimationType, this.options, this.runTime) });
|
||||
}
|
||||
|
||||
if (this.options.AnimationTimerType == AnimationTimerTypes.AlwaysRepeatAnimation)
|
||||
{
|
||||
this.runTime = 0.0;
|
||||
if (this.animationRepetition != null)
|
||||
{
|
||||
this.animationRepetition.Invoke(this._control, new AnimationEventArgs() { Data = this.options.Data, AllTransformValue = this.options.AllTransformValue, AnimationUsedTime = this.runTime, ProgressValue = GetProgress(this.AnimationType, this.options, this.runTime) });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Stop();
|
||||
if (this.animationEnding != null)
|
||||
{
|
||||
this.animationUsedTime = this.runTime < 0 ? 0.0 : this.options.AllTransformTime;
|
||||
this.animationEnding.Invoke(this._control, new AnimationEventArgs() { Data = this.options.Data, AllTransformValue = this.options.AllTransformValue, AnimationUsedTime = this.animationUsedTime, ProgressValue = this.runTime < 0 ? 0.0 : 1.0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 析构器
|
||||
|
||||
~AnimationTimer()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize((object)this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (this.disposed)
|
||||
return;
|
||||
if (disposing)
|
||||
{
|
||||
if (this.timer != null)
|
||||
{
|
||||
this.timer.Dispose();
|
||||
this.timer = (System.Windows.Forms.Timer)null;
|
||||
}
|
||||
}
|
||||
this.disposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#region 类
|
||||
|
||||
/// <summary>
|
||||
/// 动画参数设置
|
||||
/// </summary>
|
||||
[Description("动画参数设置")]
|
||||
[TypeConverter(typeof(EmptyExpandableObjectConverter))]
|
||||
public class AnimationOptions
|
||||
{
|
||||
private bool everyNewTimer = true;
|
||||
/// <summary>
|
||||
/// 是否每一次调用Start方法是都重新创建一个Timer定时器实例(默认值为true)
|
||||
/// </summary>
|
||||
[Description("是否每一次调用Start方法是都重新创建一个Timer定时器实例(默认值为true)")]
|
||||
[DefaultValue(true)]
|
||||
public bool EveryNewTimer
|
||||
{
|
||||
get { return this.everyNewTimer; }
|
||||
set { this.everyNewTimer = value; }
|
||||
}
|
||||
|
||||
private AnimationTimerTypes animationTimerType = AnimationTimerTypes.Normal;
|
||||
/// <summary>
|
||||
/// 动画定时器类型
|
||||
/// </summary>
|
||||
[Description("动画定时器类型")]
|
||||
[DefaultValue(AnimationTimerTypes.Normal)]
|
||||
public AnimationTimerTypes AnimationTimerType
|
||||
{
|
||||
get { return this.animationTimerType; }
|
||||
set { this.animationTimerType = value; }
|
||||
}
|
||||
|
||||
private double allTransformTime = 300.0;
|
||||
/// <summary>
|
||||
/// 动画要变换的总时间(默认值300.0)
|
||||
/// </summary>
|
||||
[Description("动画要变换的总时间(默认值300.0)")]
|
||||
[DefaultValue(300.0)]
|
||||
public double AllTransformTime
|
||||
{
|
||||
get { return this.allTransformTime; }
|
||||
set { this.allTransformTime = value; }
|
||||
}
|
||||
|
||||
private double allTransformValue = 10.0;
|
||||
/// <summary>
|
||||
/// 动画要变换的总变化值(默认值10.0)
|
||||
/// </summary>
|
||||
[Description("动画要变换的总变化值(默认值10.0)")]
|
||||
[DefaultValue(10.0)]
|
||||
public double AllTransformValue
|
||||
{
|
||||
get { return this.allTransformValue; }
|
||||
set { this.allTransformValue = value; }
|
||||
}
|
||||
|
||||
private object data = null;
|
||||
/// <summary>
|
||||
/// 自定义参数
|
||||
/// </summary>
|
||||
[Description("自定义参数")]
|
||||
[Browsable(false)]
|
||||
public object Data
|
||||
{
|
||||
get { return this.data; }
|
||||
set { this.data = value; }
|
||||
}
|
||||
|
||||
private double power = 3.0;
|
||||
/// <summary>
|
||||
/// 动画曲线幂(默认值3.0)
|
||||
/// (限于EaseIn、EaseOut、EaseBoth、BackIn、BackOut、BackBoth)
|
||||
/// </summary>
|
||||
[Description("动画曲线幂(默认值3)")]
|
||||
[DefaultValue(3.0)]
|
||||
public double Power
|
||||
{
|
||||
get { return this.power; }
|
||||
set { this.power = value; }
|
||||
}
|
||||
|
||||
private double amplitude = 1.0;
|
||||
/// <summary>
|
||||
/// 收缩与相关联的幅度动画。此值必须大于或等于 0。 默认值为 1.0。
|
||||
/// (限于BackIn、BackOut、BackBoth)
|
||||
/// </summary>
|
||||
[Description("收缩与相关联的幅度动画。此值必须大于或等于 0。 默认值为 1.0")]
|
||||
[DefaultValue(1.0)]
|
||||
public double Amplitude
|
||||
{
|
||||
get { return this.amplitude; }
|
||||
set { this.amplitude = value; }
|
||||
}
|
||||
|
||||
private int bounces = 3;
|
||||
/// <summary>
|
||||
/// 反弹次数。值必须大于或等于零(默认值为3)
|
||||
/// (限于BounceIn、BounceOut、BounceBoth)
|
||||
/// </summary>
|
||||
[Description("反弹次数。值必须大于或等于零(默认值为3)")]
|
||||
[DefaultValue(3)]
|
||||
public int Bounces
|
||||
{
|
||||
get { return this.bounces; }
|
||||
set { this.bounces = value; }
|
||||
}
|
||||
|
||||
private double bounciness = 2.0;
|
||||
/// <summary>
|
||||
/// 指定反弹动画的弹性大小。虽然较高的值都会导致反弹 (弹性较小),此属性中的结果很少或者反弹低值会丢失反弹 (弹性较大) 之间的高度。此值必须是正数(默认值为 2.0)
|
||||
/// (限于BounceIn、BounceOut、BounceBoth)
|
||||
/// </summary>
|
||||
[Description("指定反弹动画的弹性大小。虽然较高的值都会导致反弹 (弹性较小),此属性中的结果很少或者反弹低值会丢失反弹 (弹性较大) 之间的高度。此值必须是正数(默认值为 2.0)")]
|
||||
[DefaultValue(2.0)]
|
||||
public double Bounciness
|
||||
{
|
||||
get { return this.bounciness; }
|
||||
set { this.bounciness = value; }
|
||||
}
|
||||
|
||||
private int oscillations = 3;
|
||||
/// <summary>
|
||||
/// 目标来回滑过动画目标的次数。此值必须大于或等于0 (默认值为3)
|
||||
/// (限于ElasticIn、ElasticOut、ElasticBoth)
|
||||
/// </summary>
|
||||
[Description("目标来回滑过动画目标的次数。此值必须大于或等于0 (默认值为3)")]
|
||||
[DefaultValue(3)]
|
||||
public int Oscillations
|
||||
{
|
||||
get { return this.oscillations; }
|
||||
set { this.oscillations = value; }
|
||||
}
|
||||
|
||||
private double springiness = 3.0;
|
||||
/// <summary>
|
||||
/// 弹簧铡度。 越小的 Springiness 值为,严格 spring,通过每个振动的强度减小的速度越快弹性。一个正数(默认值为3.0)
|
||||
/// (限于ElasticIn、ElasticOut、ElasticBoth)
|
||||
/// </summary>
|
||||
[Description("弹簧铡度。 越小的 Springiness 值为,严格 spring,通过每个振动的强度减小的速度越快弹性。一个正数(默认值为3.0)")]
|
||||
[DefaultValue(3.0)]
|
||||
public double Springiness
|
||||
{
|
||||
get { return this.springiness; }
|
||||
set { this.springiness = value; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动画事件数据
|
||||
/// </summary>
|
||||
[Description("动画事件数据")]
|
||||
public class AnimationEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 动画要变换的总变化值
|
||||
/// </summary>
|
||||
public double AllTransformValue { get; set; }
|
||||
/// <summary>
|
||||
/// 已进行了多少动画时间
|
||||
/// </summary>
|
||||
public double AnimationUsedTime { get; set; }
|
||||
/// <summary>
|
||||
/// 动画总变化值的进度(0.0-1.0)
|
||||
/// </summary>
|
||||
public double ProgressValue { get; set; }
|
||||
/// <summary>
|
||||
/// 自定义参数
|
||||
/// </summary>
|
||||
public object Data { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 枚举
|
||||
|
||||
/// <summary>
|
||||
/// 动画定时器类型
|
||||
/// </summary>
|
||||
[Description("动画定时器类型")]
|
||||
public enum AnimationTimerTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// 一次性动画
|
||||
/// </summary>
|
||||
Normal,
|
||||
/// <summary>
|
||||
/// 永久动画
|
||||
/// </summary>
|
||||
AlwaysAnimation,
|
||||
/// <summary>
|
||||
/// 永久重复动画
|
||||
/// </summary>
|
||||
AlwaysRepeatAnimation
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动画时间操作类型(决定动画方向)
|
||||
/// </summary>
|
||||
[Description("动画时间操作类型(决定动画方向)")]
|
||||
public enum AnimationIntervalTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
Add,
|
||||
/// <summary>
|
||||
/// 减少
|
||||
/// </summary>
|
||||
Subtrac
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Design
|
||||
|
||||
/// <summary>
|
||||
/// 展开属性选型去除描述
|
||||
/// </summary>
|
||||
[Description("展开属性选型去除描述")]
|
||||
public class EmptyExpandableObjectConverter : ExpandableObjectConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// 当该属性为展开属性选型时,属性编辑器删除该属性的描述
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="culture"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="destinationType"></param>
|
||||
/// <returns></returns>
|
||||
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
return (object)"";
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Lskj.Control.ImageLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// 集合属性编辑窗口扩展(显示帮助文本)
|
||||
/// </summary>
|
||||
[Description("集合属性编辑窗口扩展(显示帮助文本)")]
|
||||
public class CollectionEditorExt : CollectionEditor
|
||||
{
|
||||
public CollectionEditorExt(Type type) : base(type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override CollectionForm CreateCollectionForm()
|
||||
{
|
||||
CollectionForm frm = base.CreateCollectionForm();
|
||||
FieldInfo fileinfo = frm.GetType().GetField("propertyBrowser", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (fileinfo != null)
|
||||
{
|
||||
(fileinfo.GetValue(frm) as System.Windows.Forms.PropertyGrid).HelpVisible = true;//显示帮助文本
|
||||
}
|
||||
frm.Width = 400;
|
||||
frm.Height = 400;
|
||||
return frm;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Design;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace Lskj.Control.ImageLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// 选取颜色(可选透明度)
|
||||
/// </summary>
|
||||
[Description("选取颜色(可选透明度)")]
|
||||
public class ColorEditorExt : ColorEditor
|
||||
{
|
||||
private ColorEditorUIWrapper colorEditorUIWrapper;
|
||||
|
||||
public ColorEditorExt()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑给定的对象值
|
||||
/// </summary>
|
||||
/// <param name="context">可用于获取附加上下文信息</param>
|
||||
/// <param name="provider">通过它可能获得编辑服务</param>
|
||||
/// <param name="value">正在编辑的值的实例</param>
|
||||
/// <returns>对象的新值</returns>
|
||||
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
||||
{
|
||||
if (provider != null)
|
||||
{
|
||||
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
|
||||
if (edSvc != null)
|
||||
{
|
||||
if (this.colorEditorUIWrapper == null)
|
||||
{
|
||||
this.colorEditorUIWrapper = new ColorEditorUIWrapper(this);
|
||||
}
|
||||
this.colorEditorUIWrapper.Start(edSvc, value);
|
||||
edSvc.DropDownControl(this.colorEditorUIWrapper.Control);
|
||||
if ((colorEditorUIWrapper.Value != null) && ((Color)this.colorEditorUIWrapper.Value != Color.Empty))
|
||||
{
|
||||
value = this.colorEditorUIWrapper.Value;
|
||||
}
|
||||
this.colorEditorUIWrapper.End();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制代表提供的画布上的给定对象的值。
|
||||
/// </summary>
|
||||
/// <param name="e">绘制内容和绘制位置。 </param>
|
||||
public override void PaintValue(PaintValueEventArgs e)
|
||||
{
|
||||
if (!(e.Value is Color))
|
||||
return;
|
||||
Color color = (Color)e.Value;
|
||||
Pen pen = new Pen(Color.Gray);
|
||||
SolidBrush solidBrush1 = new SolidBrush((color == Color.Empty || color == Color.Transparent) ? Color.Empty : Color.FromArgb(color.R, color.G, color.B));
|
||||
SolidBrush solidBrush2 = new SolidBrush(color);
|
||||
e.Graphics.FillRectangle(solidBrush1, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width / 2, e.Bounds.Height));
|
||||
if (!(color == Color.Empty || color == Color.Transparent))
|
||||
e.Graphics.DrawLine(pen, e.Bounds.Width / 2 + 1, e.Bounds.Y, e.Bounds.Width / 2 + 1, e.Bounds.Bottom - 2);
|
||||
e.Graphics.FillRectangle(solidBrush2, new Rectangle(e.Bounds.Width / 2, e.Bounds.Y, e.Bounds.Width / 2, e.Bounds.Height));
|
||||
solidBrush1.Dispose();
|
||||
solidBrush2.Dispose();
|
||||
pen.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 颜色编辑器面板
|
||||
/// </summary>
|
||||
[Description("颜色编辑器面板")]
|
||||
public class ColorEditorUIWrapper
|
||||
{
|
||||
private System.Windows.Forms.Control ower;
|
||||
private Panel alphaPanel;
|
||||
private Label alphadesLabel;
|
||||
private TrackBar alphaTrackBar;
|
||||
private Label alphaLabel;
|
||||
private Label alphacolorLabel;
|
||||
private MethodInfo startMethodInfo;
|
||||
private MethodInfo endMethodInfo;
|
||||
private PropertyInfo valuePropertyInfo;
|
||||
|
||||
public ColorEditorUIWrapper(ColorEditorExt _ower)
|
||||
{
|
||||
Type colorUiType = typeof(ColorEditor).GetNestedType("ColorUI", BindingFlags.CreateInstance | BindingFlags.NonPublic);
|
||||
ConstructorInfo constructorInfo = colorUiType.GetConstructor(new Type[] { typeof(ColorEditor) });
|
||||
this.ower = (System.Windows.Forms.Control)constructorInfo.Invoke(new object[] { _ower });
|
||||
this.startMethodInfo = this.ower.GetType().GetMethod("Start");
|
||||
this.endMethodInfo = this.ower.GetType().GetMethod("End");
|
||||
this.valuePropertyInfo = this.ower.GetType().GetProperty("Value");
|
||||
|
||||
this.alphaPanel = new Panel();
|
||||
this.alphadesLabel = new Label();
|
||||
this.alphaTrackBar = new TrackBar();
|
||||
this.alphaLabel = new Label();
|
||||
this.alphacolorLabel = new Label();
|
||||
//
|
||||
// alphaPanel
|
||||
//
|
||||
this.alphaPanel.BackColor = this.ower.BackColor;
|
||||
this.alphaPanel.Dock = DockStyle.Right;
|
||||
this.alphaPanel.Width = 45;
|
||||
this.alphaPanel.Controls.Add(this.alphaTrackBar);
|
||||
this.alphaPanel.Controls.Add(this.alphadesLabel);
|
||||
this.alphaPanel.Controls.Add(this.alphaLabel);
|
||||
this.alphaPanel.Controls.Add(this.alphacolorLabel);
|
||||
//
|
||||
// alphaTrackBar
|
||||
//
|
||||
this.alphaTrackBar.BackColor = this.ower.BackColor;
|
||||
this.alphaTrackBar.Dock = DockStyle.Fill;
|
||||
this.alphaTrackBar.Orientation = Orientation.Vertical;
|
||||
this.alphaTrackBar.TickStyle = TickStyle.Both;
|
||||
this.alphaTrackBar.Maximum = byte.MaxValue;
|
||||
this.alphaTrackBar.Minimum = byte.MinValue;
|
||||
this.alphaTrackBar.SmallChange = 1;
|
||||
this.alphaTrackBar.LargeChange = 1;
|
||||
this.alphaTrackBar.ValueChanged += new EventHandler(this.alphaTrackBar_ValueChanged);
|
||||
//
|
||||
// alphadesLabel
|
||||
//
|
||||
this.alphadesLabel.BackColor = this.ower.BackColor;
|
||||
this.alphadesLabel.Dock = DockStyle.Top;
|
||||
this.alphadesLabel.Text = "透明度";
|
||||
this.alphadesLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// alphaLabel
|
||||
//
|
||||
this.alphaLabel.BackColor = this.ower.BackColor;
|
||||
this.alphaLabel.Dock = DockStyle.Bottom;
|
||||
this.alphaLabel.Text = "0";
|
||||
this.alphaLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// alphacolorLabel
|
||||
//
|
||||
this.alphacolorLabel.BackColor = this.ower.BackColor;
|
||||
this.alphacolorLabel.Dock = DockStyle.Bottom;
|
||||
this.alphacolorLabel.AutoSize = false;
|
||||
this.alphacolorLabel.Height = 24;
|
||||
this.alphacolorLabel.Text = "";
|
||||
this.alphacolorLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||
this.alphacolorLabel.Paint += new PaintEventHandler(this.alphacolorLabel_Paint);
|
||||
|
||||
this.ower.Controls.Add(this.alphaPanel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑颜色时显示的控件
|
||||
/// </summary>
|
||||
public System.Windows.Forms.Control Control
|
||||
{
|
||||
get { return this.ower; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取具有透明度颜色值
|
||||
/// </summary>
|
||||
public object Value
|
||||
{
|
||||
get
|
||||
{
|
||||
object result = this.valuePropertyInfo.GetValue(ower, new object[0]);
|
||||
if (result is Color)
|
||||
{
|
||||
if ((Color)result != Color.Transparent)
|
||||
{
|
||||
if (this.alphaTrackBar.Value == 0)
|
||||
{
|
||||
this.alphaTrackBar.Value = byte.MaxValue;
|
||||
}
|
||||
result = Color.FromArgb(this.alphaTrackBar.Value, (Color)result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///启动编辑过程
|
||||
/// </summary>
|
||||
/// <param name="service">编辑服务</param>
|
||||
/// <param name="value">要编辑的值</param>
|
||||
public void Start(IWindowsFormsEditorService service, object value)
|
||||
{
|
||||
if (value is Color)
|
||||
this.alphaTrackBar.Value = ((Color)value).A;
|
||||
|
||||
this.startMethodInfo.Invoke(ower, new object[] { service, value });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///结束编辑过程
|
||||
/// </summary>
|
||||
public void End()
|
||||
{
|
||||
this.endMethodInfo.Invoke(ower, new object[0]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 透明度更改事件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void alphaTrackBar_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
this.alphaLabel.Text = this.alphaTrackBar.Value.ToString();
|
||||
this.alphacolorLabel.Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 颜色预览面板
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void alphacolorLabel_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
object result = this.valuePropertyInfo.GetValue(ower, new object[0]);
|
||||
if (result != null && result is Color)
|
||||
{
|
||||
Color color = (Color)this.Value;
|
||||
Graphics g = e.Graphics;
|
||||
Pen pen = new Pen(Color.Silver);
|
||||
SolidBrush solidBrush1 = new SolidBrush(Color.FromArgb(color.R, color.G, color.B));
|
||||
SolidBrush solidBrush2 = new SolidBrush(color);
|
||||
g.FillRectangle(solidBrush1, new RectangleF(g.ClipBounds.X, g.ClipBounds.Y, g.ClipBounds.Width / 2 - 1, g.ClipBounds.Height - 3));
|
||||
g.FillRectangle(solidBrush2, new RectangleF(g.ClipBounds.Width / 2 - 1, g.ClipBounds.Y, g.ClipBounds.Width / 2 - 1, g.ClipBounds.Height - 3));
|
||||
g.DrawRectangle(pen, g.ClipBounds.X, g.ClipBounds.Y, g.ClipBounds.Width - 3, g.ClipBounds.Height - 4);
|
||||
solidBrush1.Dispose();
|
||||
solidBrush2.Dispose();
|
||||
pen.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace Lskj.Control.ImageLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// ColorExt控件设计模式行为
|
||||
/// </summary>
|
||||
[Description("ColorExt控件设计模式行为")]
|
||||
public class ColorExtDesigner : ControlDesigner
|
||||
{
|
||||
public override SelectionRules SelectionRules
|
||||
{
|
||||
get
|
||||
{
|
||||
return SelectionRules.LeftSizeable | SelectionRules.Moveable | SelectionRules.RightSizeable;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace Lskj.Control.ImageLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// ColorPickerExt控件设计模式行为
|
||||
/// </summary>
|
||||
[Description("ColorPickerExt控件设计模式行为")]
|
||||
public class ColorPickerExtDesigner : ControlDesigner
|
||||
{
|
||||
public override SelectionRules SelectionRules
|
||||
{
|
||||
get
|
||||
{
|
||||
return SelectionRules.Moveable;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace Lskj.Control.ImageLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// 绘制虚线边框
|
||||
/// </summary>
|
||||
[Description("绘制虚线边框")]
|
||||
public class DottedLineBorderExtDesigner : ControlDesigner
|
||||
{
|
||||
protected override void OnPaintAdornments(PaintEventArgs pe)
|
||||
{
|
||||
base.OnPaintAdornments(pe);
|
||||
this.DrawBorder(pe.Graphics);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制虚线边框
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
private void DrawBorder(Graphics graphics)
|
||||
{
|
||||
System.Windows.Forms.Control control = this.Control;
|
||||
Rectangle clientRectangle = control.ClientRectangle;
|
||||
Pen pen = new Pen((double)control.BackColor.GetBrightness() >= 0.5 ? ControlPaint.Dark(control.BackColor) : ControlPaint.Light(control.BackColor));
|
||||
pen.DashStyle = DashStyle.Dash;
|
||||
--clientRectangle.Width;
|
||||
--clientRectangle.Height;
|
||||
graphics.DrawRectangle(pen, clientRectangle);
|
||||
pen.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace Lskj.Control.ImageLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// ImageCarousel控件设计模式行为
|
||||
/// </summary>
|
||||
[Description("ImageCarousel控件设计模式行为")]
|
||||
public class ImageCarouselExtDesigner : ControlDesigner
|
||||
{
|
||||
protected override void OnPaintAdornments(PaintEventArgs pe)
|
||||
{
|
||||
base.OnPaintAdornments(pe);
|
||||
this.DrawTipText(pe.Graphics);
|
||||
this.DrawBorder(pe.Graphics);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制虚线边框
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
private void DrawBorder(Graphics graphics)
|
||||
{
|
||||
ImageCarouselExt control = (ImageCarouselExt)this.Control;
|
||||
Rectangle clientRectangle = control.ClientRectangle;
|
||||
Pen pen = new Pen((double)control.BackColor.GetBrightness() >= 0.5 ? ControlPaint.Dark(control.BackColor) : ControlPaint.Light(control.BackColor));
|
||||
pen.DashStyle = DashStyle.Dash;
|
||||
--clientRectangle.Width;
|
||||
--clientRectangle.Height;
|
||||
graphics.DrawRectangle(pen, clientRectangle);
|
||||
|
||||
#region
|
||||
RectangleF rectf = control.GetDisplayRectangle();
|
||||
pen.DashStyle = DashStyle.Solid;
|
||||
pen.Color = Color.OliveDrab;
|
||||
graphics.DrawRectangle(pen, rectf.X, rectf.Y, rectf.Width, rectf.Height);
|
||||
#endregion
|
||||
|
||||
pen.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制提示文本
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
private void DrawTipText(Graphics graphics)
|
||||
{
|
||||
ImageCarouselExt _control = (ImageCarouselExt)this.Control;
|
||||
System.Windows.Forms.Control control = this.Control;
|
||||
if (_control.Images.Count < 1)
|
||||
{
|
||||
string text = "请添加图片";
|
||||
SizeF text_size = graphics.MeasureString(text, _control.Font);
|
||||
SolidBrush text_sb = new SolidBrush((double)control.BackColor.GetBrightness() >= 0.5 ? ControlPaint.Dark(control.BackColor) : ControlPaint.Light(control.BackColor));
|
||||
graphics.DrawString(text, _control.Font, text_sb, new RectangleF(control.ClientRectangle.X + (control.ClientRectangle.Width - text_size.Width) / 2f, control.ClientRectangle.Y + (control.ClientRectangle.Height - text_size.Height) / 2f, text_size.Width, text_size.Height));
|
||||
text_sb.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Lskj.Control.ImageLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// ImageWhirligigExt控件设计模式行为
|
||||
/// </summary>
|
||||
[Description("ImageWhirligigExt控件设计模式行为")]
|
||||
public class ImageWhirligigExtDesigner : DottedLineBorderExtDesigner
|
||||
{
|
||||
protected override void OnPaintAdornments(PaintEventArgs pe)
|
||||
{
|
||||
this.DrawTipText(pe.Graphics);
|
||||
base.OnPaintAdornments(pe);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制提示文本
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
private void DrawTipText(Graphics graphics)
|
||||
{
|
||||
ImageWhirligigExt _control = (ImageWhirligigExt)this.Control;
|
||||
System.Windows.Forms.Control control = this.Control;
|
||||
if (_control.Images.Count < 1)
|
||||
{
|
||||
string text = "请添加图片";
|
||||
SizeF text_size = graphics.MeasureString(text, _control.Font);
|
||||
SolidBrush text_sb = new SolidBrush((double)control.BackColor.GetBrightness() >= 0.5 ? ControlPaint.Dark(control.BackColor) : ControlPaint.Light(control.BackColor));
|
||||
graphics.DrawString(text, _control.Font, text_sb, new RectangleF(control.ClientRectangle.X + (control.ClientRectangle.Width - text_size.Width) / 2f, control.ClientRectangle.Y + (control.ClientRectangle.Height - text_size.Height) / 2f, text_size.Width, text_size.Height));
|
||||
text_sb.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user