184 lines
5.0 KiB
C#
184 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Drawing.Drawing2D;
|
|
|
|
namespace HexcalMC
|
|
{
|
|
public partial class Lamp : UserControl
|
|
{
|
|
public Lamp()
|
|
{
|
|
InitializeComponent();
|
|
base.SetStyle(ControlStyles.ResizeRedraw, true);
|
|
this.DoubleBuffered = true;
|
|
}
|
|
|
|
private void Lamp_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private static Color[] _colors = new Color[]
|
|
{
|
|
Color.Green,
|
|
Color.Orange,
|
|
Color.Red,
|
|
Color.White,
|
|
Color.Silver,
|
|
Color.Transparent,
|
|
Color.Yellow,
|
|
Color.Blue
|
|
};
|
|
|
|
private const int Ok = 0;
|
|
private const int Warn = 1;
|
|
private const int Error = 2;
|
|
private const int Debug = 4;
|
|
private const int Undef = -1;
|
|
private int _state = -1;
|
|
|
|
|
|
private string _dtext = "";
|
|
private bool _shadow = false;
|
|
|
|
/// <summary> 设置颜色 </summary>
|
|
public int State
|
|
{
|
|
get
|
|
{
|
|
return this._state;
|
|
}
|
|
set
|
|
{
|
|
this._state = value;
|
|
this.Refresh();
|
|
}
|
|
}
|
|
|
|
/// <summary> 设置文字 </summary>
|
|
public string LText
|
|
{
|
|
get
|
|
{
|
|
return this._dtext;
|
|
}
|
|
set
|
|
{
|
|
this._dtext = value;
|
|
}
|
|
}
|
|
|
|
/// <summary> 设置阴影 </summary>
|
|
public bool Shadow
|
|
{
|
|
get
|
|
{
|
|
return this._shadow;
|
|
}
|
|
set
|
|
{
|
|
this._shadow = value;
|
|
}
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs gr)
|
|
{
|
|
base.OnPaint(gr);
|
|
int num = Math.Min(base.Width, base.Height);
|
|
bool flag = num >= 8;
|
|
if (flag)
|
|
{
|
|
this.DrawLamp(gr.Graphics, num);
|
|
}
|
|
}
|
|
|
|
private void DrawLamp(Graphics g, int rad)
|
|
{
|
|
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
RectangleF rect = new RectangleF(1f, 1f, (float)(rad - 5), (float)(rad - 5));
|
|
float num = rect.Width / 12f;
|
|
RectangleF rect2 = new RectangleF(rect.Location, rect.Size);
|
|
rect2.Inflate(1f, 1f);
|
|
if (_shadow)
|
|
{
|
|
rect2.X += num;
|
|
rect2.Y += num;
|
|
g.FillEllipse(Brushes.Gray, rect2);
|
|
rect2.X -= num;
|
|
rect2.Y -= num;
|
|
}
|
|
g.FillEllipse(Brushes.Black, rect2);
|
|
|
|
if (_state != -1)
|
|
{
|
|
using (GraphicsPath graphicsPath = new GraphicsPath())
|
|
{
|
|
graphicsPath.AddEllipse(rect);
|
|
int x = (int)(rect.X + rect.Width / 3f);
|
|
int y = (int)(rect.Y + rect.Height / 3f);
|
|
Color color = Lamp._colors[_state];
|
|
using (PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath))
|
|
{
|
|
pathGradientBrush.CenterColor = Color.Snow;
|
|
pathGradientBrush.CenterPoint = new Point(x, y);
|
|
pathGradientBrush.SurroundColors = new Color[]
|
|
{
|
|
color
|
|
};
|
|
g.FillPath(pathGradientBrush, graphicsPath);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
using (Brush brush = new SolidBrush(this.BackColor))
|
|
{
|
|
g.FillEllipse(brush, rect);
|
|
}
|
|
}
|
|
|
|
if (_dtext.Length > 0)
|
|
{
|
|
float emSize = rect.Height / 6f;
|
|
Font font = new Font("Microsoft Sans Serif", emSize, FontStyle.Bold, GraphicsUnit.Point, 0);
|
|
int num2 = (int)font.GetHeight();
|
|
int y2 = (int)rect.Height / 2 - num2 / 2;
|
|
int num3 = (int)g.MeasureString(_dtext, font).Width;
|
|
int num4 = (int)(rect.Width - (float)num3) / 2;
|
|
bool flag3 = num4 < 0;
|
|
if (flag3)
|
|
{
|
|
num4 = 0;
|
|
}
|
|
g.DrawString(_dtext, font, Brushes.Black, new Point(num4, y2));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public class LampColor
|
|
{
|
|
public const int Ok = 0;
|
|
public const int Warn = 1;
|
|
public const int Error = 2;
|
|
public const int Debug = 4;
|
|
public const int Undef = -1;
|
|
|
|
public const int Green = 0;
|
|
public const int Orange = 1;
|
|
public const int Red = 2;
|
|
public const int White = 3;
|
|
public const int Silver = 4;
|
|
public const int Transparent = 5;
|
|
public const int Yellow = 6;
|
|
public const int Blue = 7;
|
|
}
|
|
}
|