From 4db7d08bb295be33e80f1353f58fcea4a8da6127 Mon Sep 17 00:00:00 2001 From: cloudflight <cloudflight@126.com> Date: 星期一, 10 六月 2024 19:11:39 +0800 Subject: [PATCH] 2024年6月10日 --- Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs | 204 ++++++++++++++++++++++++++++++++++---------------- 1 files changed, 138 insertions(+), 66 deletions(-) diff --git a/Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs b/Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs index 7db7088..a8af967 100644 --- a/Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs +++ b/Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs @@ -18,9 +18,113 @@ public delegate void DrawDelegate(Graphics bufferG, Template template); public delegate void MouseDelegate(MouseEventArgs e); - + partial class MapViewer { + void DrawBackGroud(Graphics bufferG,Template template) + { + if (template == null) return; + var _Nodes = template.network.Nodes.ViewNodes; + var _Links = template.network.Links.ViewLinks; + + var Cpoints = getCurclePoints(64).ToList(); + + var r = 1.73f / zoom; + var rt = r; + + float minElve = float.MinValue; + float maxElve = float.MaxValue; + + r = r * Link_multiply; + List<PointF> diametersZoom = new List<PointF>() { new PointF(0, 0.08f), new PointF(150, 0.03f), new PointF(300, 0.001f), new PointF(800, 0.0001f) }; + + Pen penN = new Pen(Color.FromArgb(0, 0, 255), 1 * r); + + + //鑳屾櫙鍥剧粯鍒� + if (this.mapOption.isShowPic && template != null && File.Exists(template.BackGroundImg_FullPath)) + + + { + //var gs = bufferG.Save(); + // 搴旂敤鐭╅樀鍙樻崲浠ユ姷娑堜箣鍓嶇殑缈昏浆鏁堟灉 + //bufferG.ScaleTransform(1 / Zoom.X, 1 / Zoom.Y); + List<PointF> p = new List<PointF>(); + + if (!this.mapOption.isAutoBackgroundImage) + { + var Cps = new List<PointF> + { + template.BackGroundPoint1, + new PointF(template.BackGroundPoint2.X,template.BackGroundPoint1.Y), + new PointF(template.BackGroundPoint1.X,template.BackGroundPoint2.Y), + //template.BackGroundPoint2, + + + }; + Cps.ForEach(cp => p.Add(WorldPointToMapPoint(cp, template.BackGroundElev, template.OffSet))); + } + else + { + + // 鎭㈠涔嬪墠淇濆瓨鐨勭粯鍥剧姸鎬� + + //var Cps = new List<PointF> + //{ + // template.BackGroundPoint1, + // new PointF(template.BackGroundPoint2.X,template.BackGroundPoint1.Y), + // new PointF(template.BackGroundPoint1.X,template.BackGroundPoint2.Y), + // //template.BackGroundPoint2, + + + //}; + var p1 = new PointF(template.BackGroundImgX, template.BackGroundImgY); + var p2 = new PointF(template.BackGroundImgX + template.BackGroundImgWidth, template.BackGroundImgY + template.BackGroundImgHeight); + + var f = template.BackGroundImgRotaAngle / 180 * Math.PI; + var djx = Math.Sqrt((Math.Pow(template.BackGroundImgWidth, 2) + Math.Pow(template.BackGroundImgHeight, 2))); + var p3 = new PointF(p1.X + (float)(Math.Cos(f) * template.BackGroundImgWidth), p1.Y + (float)(Math.Sin(f) * template.BackGroundImgWidth)); + var p4 = new PointF(p1.X - (float)(Math.Sin(f) * template.BackGroundImgHeight), p1.Y + (float)(Math.Cos(f) * template.BackGroundImgHeight)); + p3.Y = p4.Y; + //p4.Y = -p4.Y; + var Cps = new List<PointF> + { + //template.BackGroundPoint1, + //new PointF(template.BackGroundImgX,template.BackGroundImgY), + p4, + p3,p1 + //template.BackGroundPoint2, + + + }; + template.BackGroundPoint1 = p4; + template.BackGroundPoint2 = new PointF(p3.X, p1.Y); + + + + //List<PointF> p = new List<PointF>(); + Cps.ForEach(cp => p.Add(WorldPointToMapPoint(cp, template.BackGroundElev, template.OffSet))); + } + + //bufferG.DrawImage(System.Drawing.Image.FromFile(@"C:\Users\cloud\Pictures\GenshinImpactCloudGame\QQ鎴浘20230919105637.png"), p[0]); + try + { + var img = System.Drawing.Image.FromFile(template.BackGroundImg_FullPath); + if (img != null) + { + bufferG.FillPolygon(penN.Brush, p.ToArray()); + bufferG.DrawImage(img, p.ToArray()); + } + } + catch + { + + } + + //bufferG.Restore(gs); + } + } + void Draw(Graphics bufferG, Template template) { if (template == null) return; @@ -56,51 +160,7 @@ Pen penClosed = new Pen(Color.OrangeRed, 2 * r); Pen penHovered = new Pen(Color.DeepSkyBlue, 5 * r); - //鑳屾櫙鍥剧粯鍒� - if (this.mapOption.isShowPic && template != null && File.Exists(template.BackGroundImg_FullPath)) - - - { - //var gs = bufferG.Save(); - // 搴旂敤鐭╅樀鍙樻崲浠ユ姷娑堜箣鍓嶇殑缈昏浆鏁堟灉 - //bufferG.ScaleTransform(1 / Zoom.X, 1 / Zoom.Y); - - - - // 鎭㈠涔嬪墠淇濆瓨鐨勭粯鍥剧姸鎬� - - var Cps = new List<PointF> - { - template.BackGroundPoint1, - new PointF(template.BackGroundPoint2.X,template.BackGroundPoint1.Y), - new PointF(template.BackGroundPoint1.X,template.BackGroundPoint2.Y), - //template.BackGroundPoint2, - - - }; - - - - List<PointF> p = new List<PointF>(); - Cps.ForEach(cp => p.Add(WorldPointToMapPoint(cp, template.BackGroundElev, template.OffSet))); - - //bufferG.DrawImage(System.Drawing.Image.FromFile(@"C:\Users\cloud\Pictures\GenshinImpactCloudGame\QQ鎴浘20230919105637.png"), p[0]); - try - { - var img = System.Drawing.Image.FromFile(template.BackGroundImg_FullPath); - if (img != null) - { - bufferG.FillPolygon(penN.Brush, p.ToArray()); - bufferG.DrawImage(img, p.ToArray()); - } - } - catch - { - - } - - //bufferG.Restore(gs); - } + // 缁樺埗绾� @@ -287,8 +347,14 @@ { if (link.StartNode == null || link.EndNode == null) continue; + try + { + bufferG.DrawLines(link.Selected ? penChoosed : pen, new PointF[] { p1, p2 }); + } + catch (Exception ex) + { - bufferG.DrawLines(link.Selected ? penChoosed : pen, new PointF[] { p1, p2 }); + } if (_Template.mapOption._ShowFlowDirection) { var c = new PointF((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); @@ -575,7 +641,7 @@ } if (_isPainting) { - if (_mouseState ==MapViewEnum.MouseState.鏂板绔嬬) + if (_mouseState == MapViewEnum.MouseState.鏂板绔嬬) { var wPos = GetZZWorldPoint(_select_junction1.Position3D, _MousePosition, new Vector3(0, 0, 1)); using (var pen = new Pen(Color.Black, 1 * r)) @@ -594,14 +660,14 @@ { var wPos = GetZZWorldPoint(_select_junction1.Position3D, _MousePosition, new Vector3(1, 1, 0)); //getPointAndHeight(e, _select_junction1, out p, out z); - var mapPos= WorldPointToMapPoint(wPos); + var mapPos = WorldPointToMapPoint(wPos); bufferG.DrawLine(pen, WorldPointToMapPoint(_select_junction1), mapPos); } else { bufferG.DrawLine(pen, WorldPointToMapPoint(_select_junction1), _MousePosition); } - + } } } @@ -680,6 +746,12 @@ return new PointF(worldX, worldY); } + /// <summary> + /// 涓栫晫鎶曞奖鍧愭爣杞崲涓哄睆骞曞潗鏍� + /// </summary> + /// <param name="mapPos"></param> + /// <param name="z"></param> + /// <returns></returns> private PointF MapToScreen(PointF mapPos, float z = 0) { @@ -746,7 +818,7 @@ return new PointF(x, y); } /// <summary> - /// 鑾峰彇鍦板浘鎶曞奖鍧愭爣 + /// 鑾峰彇涓栫晫鎶曞奖鍧愭爣 /// </summary> /// <param name="point"></param> /// <param name="z"></param> @@ -799,13 +871,13 @@ private PointF3D GetZZWorldPoint(PointF3D position3D, PointF mousePosition, Vector3 vector3) { //鍋氫竴鏉¢�氳繃position3D鐨勫钩琛屼簬vector3鐨勭洿绾匡紝 - if (vector3==new Vector3(0,0,1)) + if (vector3 == new Vector3(0, 0, 1)) { return GetLGWorldPoint(position3D, mousePosition); } else { - var p2=MapPointToWorldPoint(mousePosition, position3D.Z); + var p2 = MapPointToWorldPoint(mousePosition, position3D.Z); var vector = new Vector2(p2.X - position3D.X, p2.Y - position3D.Y); //鍒ゆ柇浜岀淮鍚戦噺vector鍦ㄧ鍑犺薄闄愶紝璺濈鍝釜杞存渶杩� var x = vector.X; @@ -825,7 +897,7 @@ return new PointF3D(position3D.X - Math.Abs(x), position3D.Y, position3D.Z); } } - else + else { if (y > 0) { @@ -855,14 +927,14 @@ float sin = (float)Math.Sin(radian_fushi); float cos = (float)Math.Cos(radian_fushi); var p1 = WorldPointToMapPoint(position3D); - var dy=p2.Y - p1.Y; - float dz= dy/cos; - return new PointF3D(position3D.X, position3D.Y, position3D.Z+ dz); + var dy = p2.Y - p1.Y; + float dz = dy / cos; + return new PointF3D(position3D.X, position3D.Y, position3D.Z + dz); } - + private PointF MapPointToWorldPoint(PointF3D point) - { + { return MapPointToWorldPoint(new PointF(point.X, point.Y), point.Z); } /// <summary> @@ -902,26 +974,26 @@ return dist; } //鍒ゆ柇A璺濈绾挎B鍜孋鐨勮窛绂伙紝濡傛灉瓒呭嚭浜嗙嚎娈电殑鑼冨洿锛屽垯杩斿洖鍒版渶杩戠殑绔偣鐨勮窛绂伙紱璺濈绾挎涓績鐐硅秺杩滐紝杩斿洖鐨勮窛绂昏秺澶э紱 - private float Get_dist(PointF A, PointF B,PointF C,float MaxOff) + private float Get_dist(PointF A, PointF B, PointF C, float MaxOff) { //PointF A, PointF B,PointF C锛屾眰鐐笰鍒癇銆丆鏋勬垚绾挎鐨勪腑蹇冪偣鐨勮窛绂� - float dist_off = GetDistanceFromPointAToMidpointOfLineSegmentBC(A,B,C); + float dist_off = GetDistanceFromPointAToMidpointOfLineSegmentBC(A, B, C); //浣跨敤dist_off 璺� 绾挎A銆丅鐨勯暱搴︽瘮杈冿紝濡傛灉澶т簬1/2锛屽垯杩斿洖MaxOff锛屽惁鍒欐寜鐓ф瘮渚嬭繑鍥� float dist_len = Get_dist(B, C); if (dist_len < 5) dist_len = 5; - float dist_add = (dist_off / dist_len>0.5?MaxOff:dist_off/dist_len*2*MaxOff); + float dist_add = (dist_off / dist_len > 0.5 ? MaxOff : dist_off / dist_len * 2 * MaxOff); float dx = C.X - B.X; float dy = C.Y - B.Y; float dist = (float)Math.Sqrt(dx * dx + dy * dy); - if (dist == 0) return Get_dist(A, B)+ dist_add; + if (dist == 0) return Get_dist(A, B) + dist_add; float t = ((A.X - B.X) * dx + (A.Y - B.Y) * dy) / (dist * dist); - if (t < 0) return Get_dist(A, B)+ dist_add; - if (t > 1) return Get_dist(A, C)+ dist_add; + if (t < 0) return Get_dist(A, B) + dist_add; + if (t > 1) return Get_dist(A, C) + dist_add; float x = B.X + t * dx; float y = B.Y + t * dy; - return Get_dist(A, new PointF(x, y))+ dist_add; + return Get_dist(A, new PointF(x, y)) + dist_add; } private float GetDistanceFromPointAToMidpointOfLineSegmentBC(PointF A, PointF B, PointF C) -- Gitblit v1.9.3