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
}
///
/// 建立圆角路径的样式。
///
public enum RoundStyle
{
///
/// 四个角都不是圆角。
///
None = 0,
///
/// 四个角都为圆角。
///
All = 1,
///
/// 左边两个角为圆角。
///
Left = 2,
///
/// 右边两个角为圆角。
///
Right = 3,
///
/// 上边两个角为圆角。
///
Top = 4,
///
/// 下边两个角为圆角。
///
Bottom = 5,
///
/// 左下角为圆角。
///
BottomLeft = 6,
///
/// 右下角为圆角。
///
BottomRight = 7,
}
///
/// 矩形的圆角半径
///
public struct CornerRadius
{
#region Initializes
///
/// (构造函数).Initializes a new instance of the struct.
/// 设置四个角为相同的圆角半径
///
/// The radius.
public CornerRadius(int radius)
: this(radius, radius, radius, radius)
{
}
///
/// (构造函数).Initializes a new instance of the struct.
/// 初始化四个角的圆角半径
///
/// The top left.
/// The top right.
/// The bottom left.
/// The bottom right.
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
///
/// 左上角圆角半径
///
public int TopLeft;
///
/// 右上角圆角半径
///
public int TopRight;
///
/// 左下角圆角半径
///
public int BottomLeft;
///
/// 右下角圆角半径
///
public int BottomRigth;
#endregion
}
public enum EnumControlState
{
None,
///
/// 默认状态
///
Default,
///
/// 高亮状态(鼠标悬浮)
///
HeightLight,
///
/// 焦点(鼠标按下、已选择、输入状态等)
///
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
///
/// 阶梯渐变色彩
///
public struct GradientColor
{
///
/// (构造函数).Initializes a new instance of the struct.
///
/// The color1.
/// The color2.
/// The factors.
/// The positions.
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;
}
///
/// 初始色彩
///
public Color First;
///
/// 结束色彩
///
public Color Second;
///
/// 色彩渲染系数(0到1的浮点数值)
///
public float[] Factors;
///
/// 色彩渲染位置(0到1的浮点数值)
///
public float[] Positions;
}
#endregion
}