Beispiel #1
0
        public override void OnMouseDown(ZWPictureBox pictureBox, MouseEventArgs e)
        {
            wasMove = false;
            Point point = new Point(e.X, e.Y);

            selectMode           = SelectionMode.None;
            dragBoxFromMouseDown = Rectangle.Empty;

            // Test for moving or resizing (only if control is selected, cursor is on the handle)
            foreach (DrawObject o in pictureBox.GraphicsList)
            {
                if (o is DrawCircle)
                {
                    continue;
                }
                DrawObject.HitTestResult htr = o.HitTest(pictureBox, point, false);
                if (!o.Selected)    // test for drag and drop
                {
                    if (htr.ElementType == DrawObject.ElementType.Gate)
                    {
                        Size dragSize = SystemInformation.DragSize;
                        dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2),
                                                                       e.Y - (dragSize.Height / 2)), dragSize);

                        selectMode = SelectionMode.Drag;
                    }
                }
                else if (htr.ElementType == DrawTools.DrawObject.ElementType.Handle)
                {
                    int handleNumber = htr.Index;
                    if (handleNumber > 0)
                    {
                        selectMode = SelectionMode.Size;

                        // keep resized object in class member
                        resizedObject       = o;
                        resizedObjectHandle = handleNumber;

                        //Restore DrawPolygonFrame para
                        if (resizedObject is DrawPolyLine)
                        {
                            (resizedObject as DrawPolyLine).NeedReverseX  = false;
                            (resizedObject as DrawPolyLine).NeedReverseY  = false;
                            (resizedObject as DrawPolyLine).SetProportion = true;
                        }

                        pictureBox.GraphicsList.UnselectAll();
                        o.Selected = true;
                    }
                }
                else if (htr.ElementType == DrawObject.ElementType.Gate)
                {
                    selectMode        = SelectionMode.Move;
                    pictureBox.Cursor = Cursors.SizeAll;
                    break;
                }
            }

            // Test for selection (cursor is on the object or label)
            if (selectMode == SelectionMode.None || selectMode == SelectionMode.Drag)
            {
                DrawObject o         = null;
                int        gateIndex = 0;
                for (int i = 0; i < pictureBox.GraphicsList.Count; i++)
                {
                    if (pictureBox.GraphicsList[i] is DrawCircle)
                    {
                        continue;
                    }
                    DrawObject.HitTestResult htr = pictureBox.GraphicsList[i].HitTest(pictureBox, point, true);
                    if (htr.ElementType == DrawObject.ElementType.Gate)
                    {
                        o          = pictureBox.GraphicsList[i];
                        gateIndex  = htr.Index;
                        selectMode = o.Selected ? SelectionMode.Move : SelectionMode.Select;
                        break;
                    }
                }
                if (o != null)
                {
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        pictureBox.GraphicsList.UnselectAll();
                    }
                    o.Selected = true;
                }
            }
            // un-select
            if (selectMode == SelectionMode.None || selectMode == SelectionMode.Drag)
            {
                // click on background
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    pictureBox.GraphicsList.UnselectAll();
                }
            }

            // Net selection
            if (selectMode == SelectionMode.None)
            {
                selectMode = SelectionMode.NetSelection;
            }
            lastPoint.X  = e.X;
            lastPoint.Y  = e.Y;
            startPoint.X = e.X;
            startPoint.Y = e.Y;

            pictureBox.Capture = true;
            pictureBox.Refresh();
        }
Beispiel #2
0
 /// <summary>
 /// delete draw objcet
 /// </summary>
 /// <param name="drawObject"></param>
 public void DeleteDrawObject(DrawObject drawObject)
 {
     graphicsList.Remove(drawObject);
 }