lixiaojun
2024-08-16 2779e00649911e53903b7ff15c55eae9cfda6333
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
namespace Yw.WinFrmUI.HydroL2d
{
    /// <summary>
    /// 水泵
    /// </summary>
    public class Pump : Link
    {
        /// <summary>
        /// 线色
        /// </summary>
        public Color? LineColor { get; set; }
 
        /// <summary>
        /// 线宽
        /// </summary>
        public float? LineWidth { get; set; }
 
        /// <summary>
        /// 图片
        /// </summary>
        public Image Image { get; set; }
 
        /// <summary>
        /// 宽度
        /// </summary>
        public float? Width { get; set; }
 
        /// <summary>
        /// 高度
        /// </summary>
        public float? Height { get; set; }
 
        /// <summary>
        /// 绘制
        /// </summary>
        public override void Draw(Graphics g)
        {
            var fromCachePen = true;
            var pen = CacheHelper.PumpLinePen;
            if (this.LineColor.HasValue && this.LineWidth.HasValue)
            {
                pen = new Pen(this.LineColor.Value, this.LineWidth.Value);
                fromCachePen = false;
            }
            g.DrawLine(pen, this.StartPosition, this.EndPosition);
            if (!fromCachePen)
            {
                pen.Dispose();
            }
 
            var img = CacheHelper.PumpImage;
            if (this.Image != null)
            {
                img = this.Image;
            }
            var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Pump.Width;
            var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Pump.Height;
            var isNewImage = false;
            if (img.Width != (int)width || img.Height != (int)height)
            {
                img = img.CloneC(width, height);
                isNewImage = true;
            }
 
            g.DrawImage(img, this.StartPosition.GetCenter(this.EndPosition));
 
            if (isNewImage)
            {
                img.Dispose();
            }
 
        }
 
 
    }
}