Пример #1
0
        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;

                    // äåðæèì èçìåíÿåìûé îáúåêò â ÷ëåíàõ êëàññà
                    _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)
            {
                // êëèê íà çàäíåì ôîíå
                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 = DrawRectangle.GetNormalizedRectangle(_startPoint, _lastPoint);

            drawArea.Refresh();
        }
Пример #2
0
        /// <summary>
        /// Left mouse button is pressed
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            _selectMode = SelectionMode.None;
            PointF point = new Point(e.X, e.Y);

            // Test for resizing (only if control is selected, cursor is on the handle)
            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;

                    // keep resized object in class members
                    _resizedObject       = o;
                    _resizedObjectHandle = handleNumber;

                    // Since we want to resize only one object, unselect all other objects
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected = true;
                    o.MouseClickOnHandle(handleNumber);

                    break;
                }

                if (hitOnOutline && (n == 1))     //only one item is selected
                {
                    _selectMode = SelectionMode.Size;
                    o.MouseClickOnBorder();
                    o.Selected = true;
                }
            }

            // Test for move (cursor is on the object)
            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;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.GraphicsList.UnselectAll();
                    }

                    // Select clicked object
                    o.Selected = true;

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            // Net selection
            if (_selectMode == SelectionMode.None)
            {
                // click on background
                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 = DrawRectangle.GetNormalizedRectangle(_startPoint, _lastPoint);

            drawArea.Refresh();
        }