|
|
using System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;
namespace Customize.Controls{ public enum EnumTheme { Default = 0,
BlueSea = 1,
KissOfAngel = 2,
NoFlower = 3,
SunsetRed = 4, } public enum LinearGradientModePanel { Horizontal = 0, Vertical = 1, ForwardDiagonal = 2, BackwardDiagonal = 3, None = 4 }
[FlagsAttribute()] public enum CornerCurveMode {
None = 0, TopLeft = 1, TopRight = 2, TopLeft_TopRight = 3, BottomLeft = 4, TopLeft_BottomLeft = 5, TopRight_BottomLeft = 6, TopLeft_TopRight_BottomLeft = 7, BottomRight = 8, BottomRight_TopLeft = 9, BottomRight_TopRight = 10, BottomRight_TopLeft_TopRight = 11, BottomRight_BottomLeft = 12, BottomRight_TopLeft_BottomLeft = 13, BottomRight_TopRight_BottomLeft = 14, All = 15
}
/// <summary>
/// 建立圆角路径的样式。
/// </summary>
public enum RoundStyle { /// <summary>
/// 四个角都不是圆角。
/// </summary>
None = 0, /// <summary>
/// 四个角都为圆角。
/// </summary>
All = 1, /// <summary>
/// 左边两个角为圆角。
/// </summary>
Left = 2, /// <summary>
/// 右边两个角为圆角。
/// </summary>
Right = 3, /// <summary>
/// 上边两个角为圆角。
/// </summary>
Top = 4, /// <summary>
/// 下边两个角为圆角。
/// </summary>
Bottom = 5, /// <summary>
/// 左下角为圆角。
/// </summary>
BottomLeft = 6, /// <summary>
/// 右下角为圆角。
/// </summary>
BottomRight = 7, }
/// <summary>
/// 矩形的圆角半径
/// </summary>
public struct CornerRadius { #region Initializes
/// <summary>
/// (构造函数).Initializes a new instance of the <see cref="CornerRadius"/> struct.
/// 设置四个角为相同的圆角半径
/// </summary>
/// <param name="radius">The radius.</param>
public CornerRadius(int radius) : this(radius, radius, radius, radius) { }
/// <summary>
/// (构造函数).Initializes a new instance of the <see cref="CornerRadius"/> struct.
/// 初始化四个角的圆角半径
/// </summary>
/// <param name="topLeft">The top left.</param>
/// <param name="topRight">The top right.</param>
/// <param name="bottomLeft">The bottom left.</param>
/// <param name="bottomRight">The bottom right.</param>
public CornerRadius(int topLeft, int topRight, int bottomLeft, int bottomRight) { this.TopLeft = topLeft; this.TopRight = topRight; this.BottomLeft = bottomLeft; this.BottomRigth = bottomRight; } #endregion
#region Fields
/// <summary>
/// 左上角圆角半径
/// </summary>
public int TopLeft;
/// <summary>
/// 右上角圆角半径
/// </summary>
public int TopRight;
/// <summary>
/// 左下角圆角半径
/// </summary>
public int BottomLeft;
/// <summary>
/// 右下角圆角半径
/// </summary>
public int BottomRigth;
#endregion
}
public enum EnumControlState { None,
/// <summary>
/// 默认状态
/// </summary>
Default,
/// <summary>
/// 高亮状态(鼠标悬浮)
/// </summary>
HeightLight,
/// <summary>
/// 焦点(鼠标按下、已选择、输入状态等)
/// </summary>
Focused, }
public struct HSLColor { double m_hue; double m_saturation; double m_lightness; // http://en.wikipedia.org/wiki/HSL_color_space
public double Hue { get { return m_hue; } set { m_hue = value; } } public double Saturation { get { return m_saturation; } set { m_saturation = value; } } public double Lightness { get { return m_lightness; } set { m_lightness = value; if (m_lightness < 0) m_lightness = 0; if (m_lightness > 1) m_lightness = 1; } } public HSLColor(double hue, double saturation, double lightness) { m_hue = Math.Min(360, hue); m_saturation = Math.Min(1, saturation); m_lightness = Math.Min(1, lightness); } public HSLColor(Color color) { m_hue = 0; m_saturation = 1; m_lightness = 1; FromRGB(color); } public Color Color { get { return ToRGB(); } set { FromRGB(value); } } void FromRGB(Color cc) { double r = (double)cc.R / 255d; double g = (double)cc.G / 255d; double b = (double)cc.B / 255d;
double min = Math.Min(Math.Min(r, g), b); double max = Math.Max(Math.Max(r, g), b); // calulate hue according formula given in
// "Conversion from RGB to HSL or HSV"
m_hue = 0; if (min != max) { if (r == max && g >= b) { m_hue = 60 * ((g - b) / (max - min)) + 0; } else if (r == max && g < b) { m_hue = 60 * ((g - b) / (max - min)) + 360; } else if (g == max) { m_hue = 60 * ((b - r) / (max - min)) + 120; } else if (b == max) { m_hue = 60 * ((r - g) / (max - min)) + 240; } } // find lightness
m_lightness = (min + max) / 2;
// find saturation
if (m_lightness == 0 || min == max) m_saturation = 0; else if (m_lightness > 0 && m_lightness <= 0.5) m_saturation = (max - min) / (2 * m_lightness); else if (m_lightness > 0.5) m_saturation = (max - min) / (2 - 2 * m_lightness); } Color ToRGB() { // convert to RGB according to
// "Conversion from HSL to RGB"
double r = m_lightness; double g = m_lightness; double b = m_lightness; if (m_saturation == 0) return Color.FromArgb(255, (int)(r * 255), (int)(g * 255), (int)(b * 255));
double q = 0; if (m_lightness < 0.5) q = m_lightness * (1 + m_saturation); else q = m_lightness + m_saturation - (m_lightness * m_saturation); double p = 2 * m_lightness - q; double hk = m_hue / 360;
// r,g,b colors
double[] tc = new double[3] { hk + (1d / 3d), hk, hk - (1d / 3d) }; double[] colors = new double[3] { 0, 0, 0 };
for (int color = 0; color < colors.Length; color++) { if (tc[color] < 0) tc[color] += 1; if (tc[color] > 1) tc[color] -= 1;
if (tc[color] < (1d / 6d)) colors[color] = p + ((q - p) * 6 * tc[color]); else if (tc[color] >= (1d / 6d) && tc[color] < (1d / 2d)) colors[color] = q; else if (tc[color] >= (1d / 2d) && tc[color] < (2d / 3d)) colors[color] = p + ((q - p) * 6 * (2d / 3d - tc[color])); else colors[color] = p;
colors[color] *= 255; // convert to value expected by Color
} return Color.FromArgb(255, (int)colors[0], (int)colors[1], (int)colors[2]); }
public static bool operator !=(HSLColor left, HSLColor right) { return !(left == right); } public static bool operator ==(HSLColor left, HSLColor right) { return (left.Hue == right.Hue && left.Lightness == right.Lightness && left.Saturation == right.Saturation); } public override string ToString() { string s = string.Format("HSL({0:f2}, {1:f2}, {2:f2})", Hue, Saturation, Lightness); return s; } }
#region 阶梯渐变色彩 GradientColor
/// <summary>
/// 阶梯渐变色彩
/// </summary>
public struct GradientColor { /// <summary>
/// (构造函数).Initializes a new instance of the <see cref="GradientColor"/> struct.
/// </summary>
/// <param name="color1">The color1.</param>
/// <param name="color2">The color2.</param>
/// <param name="factors">The factors.</param>
/// <param name="positions">The positions.</param>
public GradientColor(Color color1, Color color2, float[] factors, float[] positions) { this.First = color1; this.Second = color2; this.Factors = factors == null ? new float[] { } : factors; this.Positions = positions == null ? new float[] { } : positions; }
/// <summary>
/// 初始色彩
/// </summary>
public Color First;
/// <summary>
/// 结束色彩
/// </summary>
public Color Second;
/// <summary>
/// 色彩渲染系数(0到1的浮点数值)
/// </summary>
public float[] Factors;
/// <summary>
/// 色彩渲染位置(0到1的浮点数值)
/// </summary>
public float[] Positions;
}
#endregion
}
|