You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Controls/Mesnac.Controls.ChemicalWei.../HslTruck.cs

361 lines
17 KiB
C#

2 years ago
using Mesnac.Basic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Controls.ChemicalWeighing
{
[Description("一个卡车控件,支持两种样式,支持车体升降操作")]
public class HslTruck : UserControl
{
private HslPipeTurnDirection directionStyle = HslPipeTurnDirection.Left;
private float widthDesign = 530f;
private float heightDesign = 325f;
private StringFormat sf = (StringFormat)null;
private float truckAngle = 0.0f;
private int styleMode = 1;
private Color themeColor = Color.FromArgb(235, 209, 159);
private Color boderColor = Color.Silver;
private Pen borderPen = new Pen(Color.FromArgb(150, 150, 150));
private Color edgeColor = Color.FromArgb(176, 176, 176);
private Color centerColor = Color.FromArgb(229, 229, 229);
/// <summary>必需的设计器变量。</summary>
private IContainer components = (IContainer)null;
public HslTruck()
{
this.InitializeComponent();
this.sf = new StringFormat();
this.sf.Alignment = StringAlignment.Center;
this.sf.LineAlignment = StringAlignment.Center;
this.SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
}
/// <summary>获取或设置控件的背景色</summary>
[Browsable(true)]
[Description("获取或设置控件的背景色")]
[Category("HslControls")]
[DefaultValue(typeof(Color), "Transparent")]
[EditorBrowsable(EditorBrowsableState.Always)]
public override Color BackColor
{
get => base.BackColor;
set => base.BackColor = value;
}
/// <summary>获取或设置分类器控件的边缘颜色</summary>
[Browsable(true)]
[Description("获取或设置分类器控件的边缘颜色")]
[Category("HslControls")]
[DefaultValue(typeof(Color), "[176, 176, 176]")]
public Color EdgeColor
{
get => this.edgeColor;
set
{
this.edgeColor = value;
this.Invalidate();
}
}
/// <summary>获取或设置当前的卡车的倾斜角度合适范围为0-21</summary>
[Browsable(true)]
[Description("获取或设置当前的卡车的倾斜角度合适范围为0-21")]
[Category("HslControls")]
[DefaultValue(0.0f)]
public float TruckAngle
{
get => this.truckAngle;
set
{
this.truckAngle = value;
this.Invalidate();
}
}
/// <summary>获取或设置分类器控件的中心颜色</summary>
[Browsable(true)]
[Description("获取或设置分类器控件的中心颜色")]
[Category("HslControls")]
[DefaultValue(typeof(Color), "[229, 229, 229]")]
public Color CenterColor
{
get => this.centerColor;
set
{
this.centerColor = value;
this.Invalidate();
}
}
/// <summary>获取或设置分类器控件的边缘颜色</summary>
[Browsable(true)]
[Description("获取或设置分类器控件的边缘颜色")]
[Category("HslControls")]
[DefaultValue(typeof(Color), "Silver")]
public Color BorderColor
{
get => this.boderColor;
set
{
this.boderColor = value;
this.borderPen.Dispose();
this.borderPen = new Pen(this.boderColor);
this.Invalidate();
}
}
/// <summary>获取或设置卡车的主题颜色</summary>
[Browsable(true)]
[Description("获取或设置卡车的主题颜色")]
[Category("HslControls")]
[DefaultValue(typeof(Color), "[235, 209, 159]")]
public Color ThemeColor
{
get => this.themeColor;
set
{
this.themeColor = value;
this.Invalidate();
}
}
/// <summary>获取或设置卡车的状态有两个选择12</summary>
[Browsable(true)]
[Description("获取或设置卡车的状态有两个选择12")]
[Category("HslControls")]
[DefaultValue(1)]
public int TruckStyle
{
get => this.styleMode;
set
{
this.styleMode = value;
this.Invalidate();
}
}
/// <summary>获取或设置卡车的朝向,仅支持朝右边或是左边</summary>
[Browsable(true)]
[Description("获取或设置卡车的朝向,仅支持朝右边或是左边")]
[Category("HslControls")]
[DefaultValue(typeof(HslPipeTurnDirection), "Right")]
public HslPipeTurnDirection TurnDirection
{
get => this.directionStyle;
set
{
this.directionStyle = value;
this.Invalidate();
}
}
/// <inheritdoc />
protected override void OnPaint(PaintEventArgs e)
{
Graphics graphics = e.Graphics;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
this.PaintHslControls(graphics, this.Width, this.Height);
base.OnPaint(e);
}
/// <inheritdoc cref="M:HslControls.HslArrow.PaintHslControls(System.Drawing.Graphics,System.Single,System.Single)" />
public void PaintHslControls(Graphics g, int width, int height)
{
//if (!Authorization.iashdiadasbdnajsdhjaf())
// return;
if (this.directionStyle == HslPipeTurnDirection.Left)
{
g.ScaleTransform(-1f, 1f);
g.TranslateTransform((float)-width, 0.0f);
}
if (width > 15 && height > 15)
{
if ((double)width > (double)this.widthDesign / (double)this.heightDesign * (double)height)
this.PaintMain(g, this.widthDesign / this.heightDesign * (float)height, (float)height);
else
this.PaintMain(g, (float)width, this.heightDesign / this.widthDesign * (float)width);
}
if (this.directionStyle != HslPipeTurnDirection.Left)
return;
g.TranslateTransform((float)width, 0.0f);
g.ScaleTransform(-1f, 1f);
}
private RectangleF TransRectangleF(RectangleF rectangle, float width, float height) => new RectangleF(rectangle.X * width / this.widthDesign, rectangle.Y * height / this.heightDesign, rectangle.Width * width / this.widthDesign, rectangle.Height * height / this.heightDesign);
private PointF[] TransPoints(PointF[] points, float width, float height)
{
PointF[] pointFArray = new PointF[points.Length];
for (int index = 0; index < points.Length; ++index)
pointFArray[index] = new PointF(points[index].X * width / this.widthDesign, points[index].Y * height / this.heightDesign);
return pointFArray;
}
private void PaintPolygon(Graphics g, string points, Color color, float width, float height)
{
PointF[] pointsFrom = HslHelper.GetPointsFrom(points, this.widthDesign, this.heightDesign, width, height);
using (SolidBrush solidBrush = new SolidBrush(color))
g.FillPolygon((Brush)solidBrush, pointsFrom);
g.DrawPolygon(this.borderPen, pointsFrom);
}
private void PaintMain(Graphics g, float width, float height)
{
ColorBlend colorBlend = new ColorBlend();
colorBlend.Positions = new float[3] { 0.0f, 0.35f, 1f };
colorBlend.Colors = new Color[3]
{
this.edgeColor,
this.centerColor,
this.edgeColor
};
this.PaintPolygon(g, "244,274 410,274 410,283 244,283", this.themeColor, width, height);
this.PaintPolygon(g, "410,125 485,125 529,188 529,283 410,283 410,125", this.themeColor, width, height);
using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(251, 253, 252)))
g.FillPolygon((Brush)solidBrush, HslHelper.GetPointsFrom("430,137 482,137 509,180 509,195 430,195 430,137", this.widthDesign, this.heightDesign, width, height));
using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(232, 244, 237)))
g.FillPolygon((Brush)solidBrush, HslHelper.GetPointsFrom("430,137 482,137 454,195 430,195 430,137", this.widthDesign, this.heightDesign, width, height));
using (Pen pen = new Pen(Color.FromArgb(81, 81, 81), 3f))
g.DrawPolygon(pen, HslHelper.GetPointsFrom("430,137 482,137 509,180 509,195 430,195 430,137", this.widthDesign, this.heightDesign, width, height));
using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(81, 81, 81)))
g.FillEllipse((Brush)solidBrush, this.TransRectangleF((RectangleF)new Rectangle(511, 200, 6, 6), width, height));
using (Pen pen = new Pen(Color.FromArgb(212, 186, 137), 5f))
{
g.DrawLines(pen, HslHelper.GetPointsFrom("413,209 527,209 527,280 413,280 413,209", this.widthDesign, this.heightDesign, width, height));
g.DrawArc(pen, this.TransRectangleF(new RectangleF(430f, 258f, 58f, 52f), width, height), 180f, 180f);
g.DrawPolygon(pen, HslHelper.GetPointsFrom(string.Format("350,268 {0},{1}", (object)(Math.Cos((double)this.truckAngle * 2.0 * Math.PI / 360.0) * 298.0 + 52.0), (object)(258.0 - Math.Sin((double)this.truckAngle * 2.0 * Math.PI / 360.0) * 298.0)), this.widthDesign, this.heightDesign, width, height));
}
this.PaintPolygon(g, "510,179 516,179 516,194 510,194 510,179", Color.FromArgb(81, 81, 81), width, height);
this.PaintPolygon(g, "513,203 515,203 515,194 513,194 513,203", HslHelper.GetColorLight(Color.FromArgb(81, 81, 81)), width, height);
this.PaintPolygon(g, "52,260 396,260 396,275 52,275 52,260", Color.FromArgb(81, 81, 81), width, height);
this.PaintTair(g, 460f, 293f, width, height);
this.PaintTair(g, 102f, 293f, width, height);
this.PaintTair(g, 162f, 293f, width, height);
g.TranslateTransform(52f * width / this.widthDesign, 259f * height / this.heightDesign);
if ((double)this.truckAngle != 0.0)
g.RotateTransform(-this.truckAngle);
if (this.styleMode == 1)
{
this.PaintPolygon(g, "0,-139 348,-139 348,0 0,0 0,-139", Color.FromArgb(233, 233, 233), width, height);
this.PaintPolygon(g, "8,-131 340,-131 340,-8 8,-8 8,-131", this.themeColor, width, height);
float[] numArray = new float[15]
{
30f,
40f,
50f,
95f,
105f,
115f,
160f,
170f,
180f,
225f,
235f,
245f,
290f,
300f,
310f
};
for (int index = 0; index < numArray.Length; ++index)
this.PaintPolygon(g, string.Format("{0},-131 {1},-131 {2},-8 {3},-8 {4},-131", (object)numArray[index], (object)(float)((double)numArray[index] + 5.0), (object)(float)((double)numArray[index] + 5.0), (object)numArray[index], (object)numArray[index]), HslHelper.GetColorLight(this.themeColor), width, height);
}
else if (this.styleMode == 2)
{
RectangleF rect1 = this.TransRectangleF(new RectangleF(-10f, -130f, 20f, 121f), width, height);
LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new PointF(rect1.X, rect1.Y), new PointF(rect1.X, rect1.Y + rect1.Height), Color.FromArgb(142, 196, 216), Color.FromArgb(240, 240, 240));
linearGradientBrush.InterpolationColors = colorBlend;
g.FillEllipse((Brush)linearGradientBrush, rect1);
using (Pen pen = new Pen(this.edgeColor, 1f))
g.DrawEllipse(pen, rect1);
g.FillPolygon((Brush)linearGradientBrush, HslHelper.GetPointsFrom("348,-130 355,-120 355,-10 348,0 348,-130", this.widthDesign, this.heightDesign, width, height));
g.DrawPolygon(this.borderPen, HslHelper.GetPointsFrom("348,-130 355,-120 355,-10 348,0 348,-130", this.widthDesign, this.heightDesign, width, height));
linearGradientBrush.Dispose();
RectangleF rect2 = this.TransRectangleF(new RectangleF(0.0f, -139f, 348f, 140f), width, height);
g.FillRectangle((Brush)new LinearGradientBrush(new PointF(rect2.X, rect2.Y), new PointF(rect2.X, rect2.Y + rect2.Height), Color.FromArgb(142, 196, 216), Color.FromArgb(240, 240, 240))
{
InterpolationColors = colorBlend
}, rect2);
g.DrawRectangle(this.borderPen, rect2.X, rect2.Y, rect2.Width, rect2.Height);
this.PaintPolygon(g, "0,-139 348,-139 348,-134 0,-134 0,-139", this.BorderColor, width, height);
this.PaintPolygon(g, "0,-75 348,-75 348,-65 0,-65 0,-75", this.themeColor, width, height);
this.PaintPolygon(g, "0,-50 348,-50 348,-40 0,-40 0,-50", this.themeColor, width, height);
}
if ((double)this.truckAngle != 0.0)
g.RotateTransform(this.truckAngle);
g.TranslateTransform(-52f * width / this.widthDesign, -259f * height / this.heightDesign);
}
private void PaintTair(Graphics g, float x, float y, float width, float height)
{
SolidBrush solidBrush = new SolidBrush(Color.FromArgb(55, 55, 55));
RectangleF rectangle = new RectangleF(x - 30f, y - 30f, 60f, 60f);
g.FillEllipse((Brush)solidBrush, this.TransRectangleF(rectangle, width, height));
rectangle = new RectangleF(x - 20f, y - 20f, 40f, 40f);
ColorBlend colorBlend = new ColorBlend();
colorBlend.Positions = new float[3] { 0.0f, 0.45f, 1f };
colorBlend.Colors = new Color[3]
{
Color.FromArgb(150, 150, 150),
Color.FromArgb(220, 220, 220),
Color.FromArgb(150, 150, 150)
};
PointF[] pointsFrom = HslHelper.GetPointsFrom(string.Format("{0},{1} {2},{3}", (object)(float)((double)x + 15.0), (object)(float)((double)y - 20.0), (object)(float)((double)x - 15.0), (object)(float)((double)y + 20.0)), this.widthDesign, this.heightDesign, width, height);
LinearGradientBrush linearGradientBrush = new LinearGradientBrush(pointsFrom[0], pointsFrom[1], Color.FromArgb(142, 196, 216), Color.FromArgb(240, 240, 240));
linearGradientBrush.InterpolationColors = colorBlend;
g.FillEllipse((Brush)linearGradientBrush, this.TransRectangleF(rectangle, width, height));
linearGradientBrush.Dispose();
rectangle = new RectangleF(x - 7f, y - 7f, 14f, 14f);
using (Pen pen = new Pen((Brush)solidBrush, 2f))
g.DrawEllipse(pen, this.TransRectangleF(rectangle, width, height));
rectangle = new RectangleF(x - 11f, y - 15f, 8f, 8f);
g.FillEllipse((Brush)solidBrush, this.TransRectangleF(rectangle, width, height));
rectangle = new RectangleF(x - 16f, y + 1f, 8f, 8f);
g.FillEllipse((Brush)solidBrush, this.TransRectangleF(rectangle, width, height));
rectangle = new RectangleF(x - 3f, y + 10f, 8f, 8f);
g.FillEllipse((Brush)solidBrush, this.TransRectangleF(rectangle, width, height));
rectangle = new RectangleF(x + 8f, y + 2f, 8f, 8f);
g.FillEllipse((Brush)solidBrush, this.TransRectangleF(rectangle, width, height));
rectangle = new RectangleF(x + 5f, y - 14f, 8f, 8f);
g.FillEllipse((Brush)solidBrush, this.TransRectangleF(rectangle, width, height));
solidBrush.Dispose();
}
/// <summary>清理所有正在使用的资源。</summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
this.components.Dispose();
base.Dispose(disposing);
}
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
this.AutoScaleMode = AutoScaleMode.None;
this.BackColor = Color.Transparent;
this.Name = nameof(HslTruck);
this.Size = new Size(329, 185);
this.ResumeLayout(false);
}
}
}