Beispiel #1
0
        /// <summary>
        /// Left mouse button is pressed
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(IToolDrawArea drawArea, MouseEventArgs e)
        {
            changeState = null;
            wasMove = false;


            SelectMode = PointerSelectionMode.None;
            var point = new Point(e.X, e.Y);

            // Test for resizing (only if control is selected, cursor is on the handle)
            foreach (IDrawObject o in drawArea.GraphicsCollection.Selection)
            {
                int handleNumber = o.HitTest(point);

                if (handleNumber > (int)HandleNumber.None)
                {
                    SelectMode = PointerSelectionMode.Size;

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

                    // Since we want to resize only one object, unselect all other objects
                    drawArea.GraphicsCollection.UnselectAll();
                    o.Selected = true;
                    selectedDrawObject = o;
                    changeState = new TrackChangeState(drawArea.GraphicsCollection);
                    break;
                }
            }

            // Test for move (cursor is on the object)
            if (SelectMode == PointerSelectionMode.None)
            {
                int n1 = drawArea.GraphicsCollection.Count;
                IDrawObject o = null;

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

                if (o != null)
                {
                    SelectMode = PointerSelectionMode.Move;

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

                    // Select clicked object
                    o.Selected = true;
                    selectedDrawObject = o;
                    changeState = new TrackChangeState(drawArea.GraphicsCollection);
                    drawArea.Control.Cursor = Cursors.SizeAll;
                }
            }

            // Net selection
            if (SelectMode == PointerSelectionMode.None)
            {
                // click on background
                if ((Control.ModifierKeys & Keys.Control) == 0)
                    drawArea.GraphicsCollection.UnselectAll();

                SelectMode = PointerSelectionMode.NetSelection;

            }

            lastPoint.X = e.X;
            lastPoint.Y = e.Y;
            startPoint.X = e.X;
            startPoint.Y = e.Y;
            drawArea.Control.Capture = true;
            drawArea.Control.Refresh();

            if (SelectMode == PointerSelectionMode.NetSelection)
            {
                // Draw selection rectangle in initial position
                ControlPaint.DrawReversibleFrame(
                    drawArea.Control.RectangleToScreen(GraphicUtility.GetNormalizedRectangle(startPoint, new Size(lastPoint))),
                    Color.Black,
                    FrameStyle.Dashed);
            }

            if (selectedDrawObject != null)
            {
                drawArea.SelectNewDrawObject(selectedDrawObject);
                selectedDrawObject = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Right mouse button is released
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseUp(IToolDrawArea drawArea, MouseEventArgs e)
        {
            if (SelectMode == PointerSelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.Control.RectangleToScreen(GraphicUtility.GetNormalizedRectangle(startPoint, new Size(lastPoint))),
                    Color.Black,
                    FrameStyle.Dashed);

                // Make group selection
                drawArea.GraphicsCollection.SelectInRectangle(
                    GraphicUtility.GetNormalizedRectangle(startPoint, new Size(lastPoint)));

                SelectMode = PointerSelectionMode.None;
            }

            if (resizedObject != null)
            {
                // after resizing
                resizedObject.Normalize();
                resizedObject = null;
            }

            drawArea.Control.Capture = false;
            drawArea.Control.Refresh();

            if (changeState != null && wasMove)
            {
                // Keep state after moving/resizing and add command to history
                changeState.NewState(drawArea.GraphicsCollection);
                ConfigToolContext.Instance.ToolTracker.AddTrackToHistory(changeState);
                changeState = null;
            }
        }