From c44c1b442fde596c1d20c0ad82e4d308f71ec806 Mon Sep 17 00:00:00 2001
From: xcd <834800634@qq.com>
Date: 星期六, 01 八月 2020 13:55:46 +0800
Subject: [PATCH] 部分修改

---
 src/Bro.UI.Model.Winform/UI/CanvasImage.cs |  217 +++++++++++++++++++++++++++--------------------------
 1 files changed, 110 insertions(+), 107 deletions(-)

diff --git a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
index 55af243..978e513 100644
--- a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
+++ b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
@@ -30,6 +30,9 @@
             MouseDown += Canvas_MouseDown;
             MouseMove += Canvas_MouseMove;
             MouseUp += Canvas_MouseUp;
+
+            EventRouter.ChangeElementsMouseState -= OnElementChangeMouseState;
+            EventRouter.ChangeElementsMouseState += OnElementChangeMouseState;
         }
 
         #region Event
@@ -261,10 +264,12 @@
                         MouseState = MouseState.New;
                         break;
                     case ElementState.Selected:
-                        MouseState = MouseState.SelectedElement;
+                        CurrentElementId = ele.ID;
+                        Cursor = Cursors.Default;
                         break;
                     case ElementState.Moving:
                         MouseState = MouseState.MoveElement;
+                        Cursor = Cursors.NoMove2D;
                         break;
                     case ElementState.MouseInSide:
                         MouseState = MouseState.InSideElement;
@@ -272,14 +277,67 @@
                     case ElementState.MouseHover:
                         MouseState = MouseState.HoverElement;
                         break;
+
+                    case ElementState.CanStretchLeft:
+                        Cursor = Cursors.SizeWE;
+                        break;
+                    case ElementState.StretchingLeft:
+                        MouseState = MouseState.StretchingLeft;
+                        Cursor = Cursors.SizeWE;
+                        break;
+                    case ElementState.CanStretchBottom:
+                        Cursor = Cursors.SizeNS;
+                        break;
+                    case ElementState.StretchingBottom:
+                        MouseState = MouseState.StretchingBottom;
+                        Cursor = Cursors.SizeNS;
+                        break;
+                    case ElementState.CanStretchRight:
+                        Cursor = Cursors.SizeWE;
+                        break;
+                    case ElementState.StretchingRight:
+                        MouseState = MouseState.StretchingRight;
+                        Cursor = Cursors.SizeWE;
+                        break;
+                    case ElementState.CanStretchTop:
+                        Cursor = Cursors.SizeNS;
+                        break;
+                    case ElementState.StretchingTop:
+                        MouseState = MouseState.StretchingTop;
+                        Cursor = Cursors.SizeNS;
+                        break;
+
+                    case ElementState.CanStretchLeftLowerCorner:
+                        Cursor = Cursors.SizeNESW;
+                        break;
+                    case ElementState.StretchingLeftLowerCorner:
+                        MouseState = MouseState.StretchingLeftLowerCorner;
+                        Cursor = Cursors.SizeNESW;
+                        break;
+                    case ElementState.CanStretchLeftUpperCorner:
+                        Cursor = Cursors.SizeNWSE;
+                        break;
+                    case ElementState.StretchingLeftUpperCorner:
+                        MouseState = MouseState.StretchingLeftUpperCorner;
+                        Cursor = Cursors.SizeNWSE;
+                        break;
+                    case ElementState.CanStretchRightLowerCorner:
+                        Cursor = Cursors.SizeNWSE;
+                        break;
+                    case ElementState.StretchingRightLowerCorner:
+                        MouseState = MouseState.StretchingRightLowerCorner;
+                        Cursor = Cursors.SizeNWSE;
+                        break;
+                    case ElementState.CanStretchRightUpperCorner:
+                        Cursor = Cursors.SizeNESW;
+                        break;
+                    case ElementState.StretchingRightUpperCorner:
+                        MouseState = MouseState.StretchingRightUpperCorner;
+                        Cursor = Cursors.SizeNESW;
+                        break;
                     default:
                         MouseState = MouseState.Normal;
                         break;
-                }
-
-                if (MouseState == MouseState.SelectedElement)
-                {
-                    CurrentElementId = ele.ID;
                 }
             }
             else
@@ -301,6 +359,8 @@
                     MouseState = MouseState.Normal;
                 }
             }
+
+            this.Invalidate();
         }
         #endregion
 
@@ -328,6 +388,7 @@
         }
 
         Point startPoint, currentPoint;
+        bool _isMouseBtnPressing = false;
 
         private void Canvas_MouseDown(object sender, MouseEventArgs e)
         {
@@ -335,49 +396,22 @@
 
             if (e.Button == MouseButtons.Left)
             {
+                _isMouseBtnPressing = true;
+
                 switch (MouseState)
                 {
                     case MouseState.Normal:
-                        //if (DrawTemplate == null && string.IsNullOrWhiteSpace(CurrentElementId))
-                        //{
-                        //    this.Cursor = Cursors.Hand;
-                        //    startPoint = e.Location;
-                        //}
-                        //else
-                        //{
-                        //    MouseState = MouseState.New;
-                        //}
-                        MouseState = MouseState.MovingAll;
                         startPoint = e.Location;
-
-                        //Elements.ForEach(ele =>
-                        foreach (IShapeElement ele in Elements)
-                        {
-                            ele.State = ElementState.Normal;
-                            ele.OnMouseDown(p);
-                        }
-                        //);
                         break;
                     case MouseState.StretchingLeft:
                         break;
                     case MouseState.StretchingRight:
                         break;
-                    case MouseState.StretchingUp:
+                    case MouseState.StretchingTop:
                         break;
-                    case MouseState.StretchingDown:
+                    case MouseState.StretchingBottom:
                         break;
                     case MouseState.MoveElement:
-                        break;
-                    case MouseState.SelectedElement:
-                        //MouseState = MouseState.MoveElement;
-                        startPoint = e.Location;
-
-                        //Elements.ForEach(ele =>
-                        foreach (IShapeElement ele in Elements)
-                        {
-                            ele.OnMouseDown(p);
-                        }
-                        //);
                         break;
                     case MouseState.HoverElement:
                     case MouseState.InSideElement:
@@ -392,26 +426,16 @@
                         break;
                 }
 
-                //if (DrawTemplate == null)
-                //{
-                //    this.Cursor = Cursors.Hand;
-                //    startPoint = e.Location;
-                //}
-
-                //Point p = ToMapPoint(e.Location);
-
-                //Elements.ForEach(ele =>
-                //{
-                //    ele.State = ElementState.Normal;
-                //    ele.OnMouseDown(p);
-                //});
-
-                //DrawTemplate?.OnMouseDown(p);
+                foreach (IShapeElement ele in Elements)
+                {
+                    ele.OnMouseDown(p);
+                }
             }
         }
 
         private void Canvas_MouseUp(object sender, MouseEventArgs e)
         {
+            _isMouseBtnPressing = false;
             switch (MouseState)
             {
                 case MouseState.Normal:
@@ -424,9 +448,9 @@
                     break;
                 case MouseState.StretchingRight:
                     break;
-                case MouseState.StretchingUp:
+                case MouseState.StretchingTop:
                     break;
-                case MouseState.StretchingDown:
+                case MouseState.StretchingBottom:
                     break;
                 case MouseState.MoveElement:
                     //MouseState = MouseState.SelectedElement;
@@ -443,7 +467,6 @@
                 case MouseState.SelectionZoneDoing:
                     MouseState = MouseState.SelectionZone;
 
-                    //Elements.ForEach(ele =>
                     foreach (IShapeElement ele in Elements)
                     {
                         if (ele.IsIntersect(_selectionRect))
@@ -451,7 +474,6 @@
                             ele.State = ElementState.Selected;
                         }
                     }
-                    //);
 
                     break;
             }
@@ -460,12 +482,10 @@
 
             Point p = ToMapPoint(e.Location);
             DrawTemplate?.OnMouseUp(p);
-            //Elements.ForEach(ele =>
             foreach (IShapeElement ele in Elements)
             {
                 ele.OnMouseUp(p);
             }
-            //);
         }
 
         private void Canvas_MouseMove(object sender, MouseEventArgs e)
@@ -475,26 +495,26 @@
             switch (MouseState)
             {
                 case MouseState.Normal:
-                    //Elements.ForEach(u =>
-                    //{
-                    //    u.OnMouseMove(p);
-                    //});
+                    {
+                        if (_isMouseBtnPressing)
+                        {
+                            currentPoint = e.Location;
+                            Point p1 = ToMapPoint(startPoint);
+                            Point p2 = ToMapPoint(currentPoint);
+                            Matrix.Translate(p2.X - p1.X, p2.Y - p1.Y);
+                            startPoint = e.Location;
+                        }
+                    }
                     break;
                 case MouseState.StretchingLeft:
                     break;
                 case MouseState.StretchingRight:
                     break;
-                case MouseState.StretchingUp:
+                case MouseState.StretchingTop:
                     break;
-                case MouseState.StretchingDown:
+                case MouseState.StretchingBottom:
                     break;
                 case MouseState.MoveElement:
-                    //Elements.ForEach(ele =>
-                    foreach (IShapeElement ele in Elements)
-                    {
-                        ele.OnMouseMove(p);
-                    }
-                    //);
                     break;
                 case MouseState.HoverElement:
                 case MouseState.InSideElement:
@@ -504,13 +524,6 @@
                 case MouseState.Editing:
                     break;
                 case MouseState.MovingAll:
-                    {
-                        currentPoint = e.Location;
-                        Point p1 = ToMapPoint(startPoint);
-                        Point p2 = ToMapPoint(currentPoint);
-                        Matrix.Translate(p2.X - p1.X, p2.Y - p1.Y);
-                        startPoint = e.Location;
-                    }
                     break;
                 case MouseState.SelectionZoneDoing:
                     {
@@ -529,17 +542,6 @@
                     break;
             }
 
-            //if (this.Cursor == Cursors.Hand)
-            //{
-            //    currentPoint = e.Location;
-
-            //    Point p1 = ToMapPoint(startPoint);
-            //    Point p2 = ToMapPoint(currentPoint);
-            //    Matrix.Translate(p2.X - p1.X, p2.Y - p1.Y);
-            //    startPoint = e.Location;
-            //}
-
-            //DisplayMouseLocation(e.Location);
             Point mapPoint = ToMapPoint(e.Location);
             Color color = Color.Transparent;
             if (MAP != null && mapPoint.X > 0 && mapPoint.X < MAP.Width && mapPoint.Y > 0 && mapPoint.Y < MAP.Height)
@@ -550,12 +552,10 @@
 
             if (MouseState != MouseState.SelectionZoneDoing)
             {
-                //Elements.ForEach(u =>
                 foreach (IShapeElement ele in Elements)
                 {
                     ele.OnMouseMove(p);
                 }
-                //);
             }
 
             Invalidate();
@@ -569,7 +569,7 @@
             {
                 switch (MouseState)
                 {
-                    case MouseState.SelectedElement:
+                    //case MouseState.SelectedElement:
                     case MouseState.HoverElement:
                     case MouseState.InSideElement:
                     case MouseState.MoveElement:
@@ -587,7 +587,7 @@
             }
             else
             {
-                if (MouseState == MouseState.SelectedElement)
+                //if (MouseState == MouseState.SelectedElement)
                 {
                     MouseState = MouseState.Normal;
 
@@ -613,6 +613,9 @@
         {
             if (map == null)
                 return;
+
+            MAP?.Dispose();
+            MAP = null;
 
             MAP = map;
             //MAP = map;
@@ -702,22 +705,22 @@
         #region 鎸夐敭鎿嶄綔
         public void OnCanvasKeyPressed(object sender, KeyPressEventArgs e)
         {
-            if (e.KeyChar == 27)  //Esc
-            {
-                if (MouseState == MouseState.SelectedElement)
-                {
-                    MouseState = MouseState.Normal;
+            //if (e.KeyChar == 27)  //Esc
+            //{
+            //    //if (MouseState == MouseState.SelectedElement)
+            //    {
+            //        MouseState = MouseState.Normal;
 
-                    //Elements.ForEach(ele =>
-                    foreach (IShapeElement ele in Elements)
-                    {
-                        ele.State = ElementState.Normal;
-                    }
-                    //);
-                }
-            }
+            //        //Elements.ForEach(ele =>
+            //        foreach (IShapeElement ele in Elements)
+            //        {
+            //            ele.State = ElementState.Normal;
+            //        }
+            //        //);
+            //    }
+            //}
 
-            Invalidate();
+            //Invalidate();
         }
 
         public void OnCanvasKeyDown(object sender, KeyEventArgs e)
@@ -741,7 +744,7 @@
                     Elements.Remove(Elements.FirstOrDefault(u => u.ID == CurrentElementId));
                     break;
                 case Keys.Escape:
-                    if (MouseState == MouseState.SelectedElement)
+                    //if (MouseState == MouseState.SelectedElement)
                     {
                         MouseState = MouseState.Normal;
 

--
Gitblit v1.8.0