From 8f677b1741b78e4de4c95373fc02587a05d7b5ca Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期五, 16 八月 2024 17:52:08 +0800
Subject: [PATCH] 2d尝试,功能基本实现,还差绘制特定区域

---
 WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/02-node/Tank.cs |  166 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 148 insertions(+), 18 deletions(-)

diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/02-node/Tank.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/02-node/Tank.cs
index 2506a42..37bc512 100644
--- a/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/02-node/Tank.cs
+++ b/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/02-node/Tank.cs
@@ -21,32 +21,162 @@
         public float? Height { get; set; }
 
         /// <summary>
+        /// 鎮仠鍥剧墖
+        /// </summary>
+        public Image HoveredImage { get; set; }
+
+        /// <summary>
+        /// 鎮仠瀹藉害
+        /// </summary>
+        public float? HoveredWidth { get; set; }
+
+        /// <summary>
+        /// 鎮仠楂樺害
+        /// </summary>
+        public float? HoveredHeight { get; set; }
+
+        /// <summary>
+        /// 閫夋嫨鍥剧墖
+        /// </summary>
+        public Image SelectedImage { get; set; }
+
+        /// <summary>
+        /// 閫夋嫨瀹藉害
+        /// </summary>
+        public float? SelectedWidth { get; set; }
+
+        /// <summary>
+        /// 閫夋嫨楂樺害
+        /// </summary>
+        public float? SelectedHeight { get; set; }
+
+        //鑾峰彇鍧愭爣浣嶇疆
+        private Coordinate GetCoordinate(Graphics g)
+        {
+            var ps = this.Position; //鍘熷鐐�    
+            var ws = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Tank.Size.Width;//鍘熷瀹藉害     
+            var hs = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Tank.Size.Height;//鍘熷楂樺害
+            var wz = ws / g.PageScale;//缂╂斁瀹藉害         
+            var hz = hs / g.PageScale; //缂╂斁楂樺害
+            return Coordinate.GetCoordinate(ps, 0, new SizeF(wz, hz), StringAlignment.Center, StringAlignment.Center);
+        }
+        private Coordinate _coordinate = null;//鍧愭爣淇℃伅
+
+        /// <summary>
         /// 缁樺埗
         /// </summary>
         public override void Draw(Graphics g)
         {
-            var img = CacheHelper.TankImage;
-            if (this.Image != null)
-            {
-                img = this.Image;
-            }
-            var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Tank.Width;
-            var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Tank.Height;
-            var isNewImage = false;
-            if (img.Width != (int)width || img.Height != (int)height)
-            {
-                img = img.CloneC(width, height);
-                isNewImage = true;
-            }
+            _coordinate = GetCoordinate(g);
 
-            g.DrawImage(img, this.Position);
-
-            if (isNewImage)
+            if (this.Hovered)
             {
-                img.Dispose();
-            }
+                var hoveredImg = CacheHelper.TankHoveredImage;
+                if (this.HoveredImage != null)
+                {
+                    hoveredImg = this.HoveredImage;
+                }
+                var hoveredWidth = this.HoveredWidth.HasValue ? this.HoveredWidth.Value : CacheHelper.HydroL2d.Tank.HoveredSize.Width;
+                var hoveredHeight = this.HoveredHeight.HasValue ? this.HoveredHeight.Value : CacheHelper.HydroL2d.Tank.HoveredSize.Height;
+                var isNewImage = false;
+                if (hoveredImg.Width != (int)hoveredWidth || hoveredImg.Height != (int)hoveredHeight)
+                {
+                    hoveredImg = hoveredImg.CloneC(hoveredWidth, hoveredHeight);
+                    isNewImage = true;
+                }
 
+                var dx = hoveredWidth / g.PageScale / 2f;
+                var dy = hoveredHeight / g.PageScale / 2f;
+                var p0 = new PointF(this.Position.X - dx, this.Position.Y - dy);
+
+                g.DrawImage(hoveredImg, p0);
+
+                if (isNewImage)
+                {
+                    hoveredImg.Dispose();
+                }
+            }
+            else if (this.Selected)
+            {
+                var selectedImg = CacheHelper.TankSelectedImage;
+                if (this.SelectedImage != null)
+                {
+                    selectedImg = this.SelectedImage;
+                }
+                var selectedWidth = this.SelectedWidth.HasValue ? this.SelectedWidth.Value : CacheHelper.HydroL2d.Tank.SelectedSize.Width;
+                var selectedHeight = this.SelectedHeight.HasValue ? this.SelectedHeight.Value : CacheHelper.HydroL2d.Tank.SelectedSize.Height;
+                var isNewImage = false;
+                if (selectedImg.Width != (int)selectedWidth || selectedImg.Height != (int)selectedHeight)
+                {
+                    selectedImg = selectedImg.CloneC(selectedWidth, selectedHeight);
+                    isNewImage = true;
+                }
+
+                var dx = selectedWidth / g.PageScale / 2f;
+                var dy = selectedHeight / g.PageScale / 2f;
+                var p0 = new PointF(this.Position.X - dx, this.Position.Y - dy);
+
+                g.DrawImage(selectedImg, p0);
+
+                if (isNewImage)
+                {
+                    selectedImg.Dispose();
+                }
+            }
+            else
+            {
+                var img = CacheHelper.TankImage;
+                if (this.Image != null)
+                {
+                    img = this.Image;
+                }
+                var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Tank.Size.Width;
+                var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Tank.Size.Height;
+                var isNewImage = false;
+                if (img.Width != (int)width || img.Height != (int)height)
+                {
+                    img = img.CloneC(width, height);
+                    isNewImage = true;
+                }
+
+                var dx = width / g.PageScale / 2f;
+                var dy = height / g.PageScale / 2f;
+                var p0 = new PointF(this.Position.X - dx, this.Position.Y - dy);
+
+                g.DrawImage(img, p0);
+
+                if (isNewImage)
+                {
+                    img.Dispose();
+                }
+            }
 
         }
+
+        /// <summary>
+        /// 鍖呭惈
+        /// </summary>
+        public override bool Contains(PointF pt)
+        {
+            if (_coordinate == null)
+            {
+                return false;
+            }
+            return _coordinate.BeforeRectf.Contains(pt);
+        }
+
+        /// <summary>
+        /// 鐩镐氦
+        /// </summary>
+        public override bool Intersect(RectangleF rectf)
+        {
+            if (rectf.Contains(this.Position))
+            {
+                return true;
+            }
+            return false;
+
+        }
+
     }
 }

--
Gitblit v1.9.3