* UILight:增加方形显示,优化渐变色

This commit is contained in:
Sunny 2021-06-19 22:35:59 +08:00
parent 1419577357
commit 2693135d15
9 changed files with 124 additions and 42 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -78,6 +78,8 @@
this.uiLight1.Location = new System.Drawing.Point(30, 52); this.uiLight1.Location = new System.Drawing.Point(30, 52);
this.uiLight1.MinimumSize = new System.Drawing.Size(1, 1); this.uiLight1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiLight1.Name = "uiLight1"; this.uiLight1.Name = "uiLight1";
this.uiLight1.OffCenterColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(248)))), ((int)(((byte)(232)))));
this.uiLight1.OnCenterColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(248)))), ((int)(((byte)(232)))));
this.uiLight1.Radius = 35; this.uiLight1.Radius = 35;
this.uiLight1.Size = new System.Drawing.Size(35, 35); this.uiLight1.Size = new System.Drawing.Size(35, 35);
this.uiLight1.TabIndex = 20; this.uiLight1.TabIndex = 20;
@ -101,6 +103,8 @@
this.uiLight2.Location = new System.Drawing.Point(114, 52); this.uiLight2.Location = new System.Drawing.Point(114, 52);
this.uiLight2.MinimumSize = new System.Drawing.Size(1, 1); this.uiLight2.MinimumSize = new System.Drawing.Size(1, 1);
this.uiLight2.Name = "uiLight2"; this.uiLight2.Name = "uiLight2";
this.uiLight2.OffCenterColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(248)))), ((int)(((byte)(232)))));
this.uiLight2.OnCenterColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(248)))), ((int)(((byte)(232)))));
this.uiLight2.Radius = 35; this.uiLight2.Radius = 35;
this.uiLight2.Size = new System.Drawing.Size(35, 35); this.uiLight2.Size = new System.Drawing.Size(35, 35);
this.uiLight2.State = Sunny.UI.UILightState.Off; this.uiLight2.State = Sunny.UI.UILightState.Off;
@ -114,6 +118,8 @@
this.uiLight3.Location = new System.Drawing.Point(156, 52); this.uiLight3.Location = new System.Drawing.Point(156, 52);
this.uiLight3.MinimumSize = new System.Drawing.Size(1, 1); this.uiLight3.MinimumSize = new System.Drawing.Size(1, 1);
this.uiLight3.Name = "uiLight3"; this.uiLight3.Name = "uiLight3";
this.uiLight3.OffCenterColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(248)))), ((int)(((byte)(232)))));
this.uiLight3.OnCenterColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(248)))), ((int)(((byte)(232)))));
this.uiLight3.Radius = 35; this.uiLight3.Radius = 35;
this.uiLight3.Size = new System.Drawing.Size(35, 35); this.uiLight3.Size = new System.Drawing.Size(35, 35);
this.uiLight3.State = Sunny.UI.UILightState.Blink; this.uiLight3.State = Sunny.UI.UILightState.Blink;
@ -122,15 +128,19 @@
// //
// uiLight4 // uiLight4
// //
this.uiLight4.CenterColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(248)))), ((int)(((byte)(232))))); this.uiLight4.CenterColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.uiLight4.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiLight4.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLight4.Location = new System.Drawing.Point(72, 52); this.uiLight4.Location = new System.Drawing.Point(72, 52);
this.uiLight4.MinimumSize = new System.Drawing.Size(1, 1); this.uiLight4.MinimumSize = new System.Drawing.Size(1, 1);
this.uiLight4.Name = "uiLight4"; this.uiLight4.Name = "uiLight4";
this.uiLight4.OffCenterColor = System.Drawing.Color.Gainsboro;
this.uiLight4.OnCenterColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.uiLight4.OnColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); this.uiLight4.OnColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
this.uiLight4.Radius = 35; this.uiLight4.Radius = 0;
this.uiLight4.Shape = Sunny.UI.UIShape.Square;
this.uiLight4.ShowLightLine = false; this.uiLight4.ShowLightLine = false;
this.uiLight4.Size = new System.Drawing.Size(35, 35); this.uiLight4.Size = new System.Drawing.Size(35, 35);
this.uiLight4.State = Sunny.UI.UILightState.Blink;
this.uiLight4.TabIndex = 36; this.uiLight4.TabIndex = 36;
this.uiLight4.Text = "uiLight4"; this.uiLight4.Text = "uiLight4";
// //

View File

@ -120,6 +120,9 @@
<metadata name="uiToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="uiToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>107, 17</value> <value>107, 17</value>
</metadata> </metadata>
<metadata name="uiToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>107, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>35</value> <value>35</value>
</metadata> </metadata>

View File

@ -47,6 +47,25 @@ namespace Sunny.UI
Radius = Width = Height = 35; Radius = Width = Height = 35;
} }
private UIShape sharpType = UIShape.Circle;
/// <summary>
/// 显示形状:圆形,正方形
/// </summary>
[DefaultValue(UIShape.Circle), Description("显示形状:圆形,正方形"), Category("SunnyUI")]
public UIShape Shape
{
get => sharpType;
set
{
if (sharpType != value)
{
sharpType = value;
Invalidate();
}
}
}
private int interval = 500; private int interval = 500;
[DefaultValue(500), Description("显示间隔"), Category("SunnyUI")] [DefaultValue(500), Description("显示间隔"), Category("SunnyUI")]
@ -82,16 +101,6 @@ namespace Sunny.UI
state = value; state = value;
timer?.Stop(); timer?.Stop();
if (state == UILightState.On)
{
showColor = onColor;
}
if (state == UILightState.Off)
{
showColor = offColor;
}
if (state == UILightState.Blink) if (state == UILightState.Blink)
{ {
if (timer == null) if (timer == null)
@ -101,7 +110,6 @@ namespace Sunny.UI
} }
blinkState = true; blinkState = true;
showColor = onColor;
timer.Start(); timer.Start();
} }
@ -109,22 +117,17 @@ namespace Sunny.UI
} }
} }
private Color showColor = UIColor.Green;
private bool blinkState; private bool blinkState;
private void Timer_Tick(object sender, EventArgs e) private void Timer_Tick(object sender, EventArgs e)
{ {
blinkState = !blinkState; blinkState = !blinkState;
showColor = blinkState ? onColor : offColor;
Invalidate(); Invalidate();
} }
protected override void OnPaintFill(Graphics g, GraphicsPath path) protected override void OnPaintFill(Graphics g, GraphicsPath path)
{ {
if (Width != Height) int ShowSize = Math.Min(Width, Height);
{
Width = Height;
}
Color color; Color color;
if (State == UILightState.On) if (State == UILightState.On)
@ -132,32 +135,75 @@ namespace Sunny.UI
else if (State == UILightState.Off) else if (State == UILightState.Off)
color = OffColor; color = OffColor;
else else
color = showColor; color = blinkState ? onColor : offColor;
GraphicsPath CirclePath = new GraphicsPath(); Color cColor;
CirclePath.AddEllipse(2, 2, Width - 4, Height - 4); if (State == UILightState.On)
g.Smooth(); cColor = OnCenterColor;
else if (State == UILightState.Off)
if (ShowCenterColor) cColor = offCenterColor;
{
Color[] surroundColor = new Color[] { color };
PathGradientBrush gradientBrush = new PathGradientBrush(path);
gradientBrush.CenterColor = centerColor;
gradientBrush.SurroundColors = surroundColor;
g.FillPath(gradientBrush, CirclePath);
gradientBrush.Dispose();
}
else else
cColor = blinkState ? OnCenterColor : offCenterColor;
if (Shape == UIShape.Circle)
{ {
g.FillPath(color, CirclePath); Radius = ShowSize;
GraphicsPath CirclePath = new GraphicsPath();
CirclePath.AddEllipse(2, 2, ShowSize - 4, ShowSize - 4);
g.Smooth();
if (ShowCenterColor)
{
Color[] surroundColor = new Color[] { color };
PathGradientBrush gradientBrush = new PathGradientBrush(path);
gradientBrush.CenterPoint = new PointF(ShowSize / 2.0f, ShowSize / 2.0f);
gradientBrush.CenterColor = cColor;
gradientBrush.SurroundColors = surroundColor;
g.FillPath(gradientBrush, CirclePath);
gradientBrush.Dispose();
}
else
{
g.FillPath(color, CirclePath);
}
CirclePath.Dispose();
if (ShowLightLine)
{
int size = (ShowSize - 4) / 5;
g.DrawArc(cColor, size, size,
ShowSize - size * 2, ShowSize - size * 2,
45, -155);
}
} }
CirclePath.Dispose(); if (Shape == UIShape.Square)
if (ShowLightLine)
{ {
int size = (Width - 4) / 5; Radius = 0;
g.DrawArc(centerColor, size, size, Width - size * 2, Height - size * 2, 45, -155); g.FillRoundRectangle(color, 2, 2, ShowSize - 4, ShowSize - 4, 5);
if (ShowCenterColor)
{
GraphicsPath CirclePath = new GraphicsPath();
Point[] p = {
new Point(3,3),new Point(ShowSize-3,3),
new Point(ShowSize-3,ShowSize-3),new Point(3,ShowSize-3)
};
CirclePath.AddLines(p);
g.Smooth();
Color[] surroundColor = new Color[] { color };
PathGradientBrush gradientBrush = new PathGradientBrush(path);
gradientBrush.CenterPoint = new PointF(ShowSize / 2.0f, ShowSize / 2.0f);
gradientBrush.CenterColor = cColor;
gradientBrush.SurroundColors = surroundColor;
g.FillPath(gradientBrush, CirclePath);
gradientBrush.Dispose();
CirclePath.Dispose();
}
} }
} }
@ -203,10 +249,10 @@ namespace Sunny.UI
} }
} }
private Color centerColor = UIColor.LightGreen; private Color centerColor = UIColor.White;
[DefaultValue(typeof(Color), "110, 190, 40")] [DefaultValue(typeof(Color), "White")]
[Description("中心颜色"), Category("SunnyUI")] [Description("中心颜色"), Category("SunnyUI"), Browsable(false)]
public Color CenterColor public Color CenterColor
{ {
get => centerColor; get => centerColor;
@ -217,6 +263,29 @@ namespace Sunny.UI
} }
} }
[DefaultValue(typeof(Color), "White")]
[Description("中心颜色"), Category("SunnyUI")]
public Color OnCenterColor
{
get => CenterColor;
set => CenterColor = value;
}
private Color offCenterColor = UIColor.White;
[DefaultValue(typeof(Color), "White")]
[Description("中心颜色"), Category("SunnyUI")]
public Color OffCenterColor
{
get => offCenterColor;
set
{
offCenterColor = value;
Invalidate();
}
}
private Color offColor = UIColor.Gray; private Color offColor = UIColor.Gray;
[DefaultValue(typeof(Color), "140, 140, 140")] [DefaultValue(typeof(Color), "140, 140, 140")]