Example #1
0
        /// <summary>
        /// 按下鼠标左键
        /// </summary>
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            _selectMode = SelectionMode.None;
            PointF point = new Point(e.X, e.Y);

            // 调整大小的测试(仅当选择了控件时,光标位于句柄上)
            int n = drawArea.GraphicsList.SelectionCount;

            for (int i = 0; i < n; i++)
            {
                DrawObject o = drawArea.GraphicsList.GetSelectedObject(i);

                int  handleNumber = o.HitTest(point);
                bool hitOnOutline = o.HitOnCircumferance;

                if (handleNumber > 0)
                {
                    _selectMode = SelectionMode.Size;

                    #region LineConnect
                    if (o is DrawConnectLine && handleNumber != 2)
                    {
                        ((DrawConnectLine)o).SetFollowObjectNull(handleNumber);
                    }

                    if (o is DrawConnectObject connect)
                    {
                        connect.SetFollowDrawObject(handleNumber, null, -1);
                    }
                    //if (o is WireConnectLineDrawObject && handleNumber != 2)
                    //{
                    //    ((WireConnectLineDrawObject)o).SetFollowObjectNull(handleNumber);
                    //}

                    #endregion

                    //if ( o is SingleDisConnectorDrawObject && handleNumber == 9)
                    //{
                    //    float state = ((SingleDisConnectorDrawObject)o).Switch;
                    //    ((SingleDisConnectorDrawObject)o).Switch = state == 0 ? 1 : 0;
                    //}

                    // 在类成员中保留调整大小的对象
                    _resizedObject       = o;
                    _resizedObjectHandle = handleNumber;

                    // 因为我们只想调整一个对象的大小,所以取消选择所有其他对象。
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected = true;
                    o.MouseClickOnHandle(handleNumber);

                    break;
                }

                if (hitOnOutline && (n == 1))
                {
                    _selectMode = SelectionMode.Size;
                    o.MouseClickOnBorder();
                    o.Selected = true;
                }
            }


            // 移动测试(光标在对象上)
            if (_selectMode == SelectionMode.None)
            {
                int        n1 = drawArea.GraphicsList.Count;
                DrawObject o  = null;

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea.GraphicsList[i].HitTest(point) == 0)
                    {
                        o = drawArea.GraphicsList[i];
                        break;
                    }
                }

                if (o != null)
                {
                    _selectMode = SelectionMode.Move;

                    // 如果未按ctrl且尚未选择单击的对象,则取消全选
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.GraphicsList.UnselectAll();
                    }

                    // 选择单击的对象
                    o.Selected = true;

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            //判断是否点击到旋钮
            if (_selectMode == SelectionMode.None)
            {
                for (int i = 0; i < n; i++)
                {
                    DrawObject o         = drawArea.GraphicsList.GetSelectedObject(i);
                    bool       hitonknob = o.HitKnobTest(point);
                    if (hitonknob)
                    {
                        _selectMode = SelectionMode.Rotate;

                        // 在类成员中保留调整角度的对象
                        _rerotateObject = o;

                        // 因为我们只想调整一个对象的大小,所以取消选择所有其他对象。
                        drawArea.GraphicsList.UnselectAll();
                        o.Selected = true;

                        break;
                    }
                }
            }

            // 净选择
            if (_selectMode == SelectionMode.None)
            {
                // 点击背景
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.GraphicsList.UnselectAll();
                }

                _selectMode = SelectionMode.NetSelection;
                drawArea.DrawNetRectangle = true;
            }
            //保存一次最近操作
            _lastPoint.X  = e.X;
            _lastPoint.Y  = e.Y;
            _startPoint.X = e.X;
            _startPoint.Y = e.Y;

            drawArea.Capture      = true;
            drawArea.NetRectangle = DrawRectangleObject.GetNormalizedRectangle(_startPoint, _lastPoint);

            drawArea.Refresh();
        }