Пример #1
0
 // Call this function AFTER operation.
 public void NewState(DrawingCanvas drawingCanvas)
 {
     // Keep objects state after operation.
     FillList(drawingCanvas.GraphicsList, ref listAfter);
 }
Пример #2
0
        public UndoManager(DrawingCanvas drawingCanvas)
        {
            this.drawingCanvas = drawingCanvas;

            ClearHistory();
        }
Пример #3
0
        /// <summary>
        /// Handle mouse down.
        /// Start moving, resizing or group selection.
        /// </summary>
        public override void OnMouseDown(DrawingCanvas drawingCanvas, MouseButtonEventArgs e)
        {
            commandChangeState = null;
            wasMove            = false;


            Point point = e.GetPosition(drawingCanvas);

            selectMode = SelectionMode.None;

            GraphicsBase o;
            GraphicsBase movedObject = null;
            int          handleNumber;

            // Test for resizing (only if control is selected, cursor is on the handle)
            for (int i = drawingCanvas.GraphicsList.Count - 1; i >= 0; i--)
            {
                o = drawingCanvas[i];

                if (o.IsSelected)
                {
                    handleNumber = o.MakeHitTest(point);

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

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

                        // Since we want to resize only one object, unselect all other objects
                        HelperFunctions.UnselectAll(drawingCanvas);
                        o.IsSelected = true;

                        commandChangeState = new CommandChangeState(drawingCanvas);

                        break;
                    }
                }
            }

            // Test for move (cursor is on the object)
            if (selectMode == SelectionMode.None)
            {
                for (int i = drawingCanvas.GraphicsList.Count - 1; i >= 0; i--)
                {
                    o = drawingCanvas[i];

                    if (o.MakeHitTest(point) == 0)
                    {
                        movedObject = o;
                        break;
                    }
                }

                if (movedObject != null)
                {
                    selectMode = SelectionMode.Move;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if (Keyboard.Modifiers != ModifierKeys.Control && !movedObject.IsSelected)
                    {
                        HelperFunctions.UnselectAll(drawingCanvas);
                    }

                    // Select clicked object
                    movedObject.IsSelected = true;

                    // Set move cursor
                    drawingCanvas.Cursor = Cursors.SizeAll;

                    commandChangeState = new CommandChangeState(drawingCanvas);
                }
            }

            // Click on background
            if (selectMode == SelectionMode.None)
            {
                // Unselect all if Ctrl is not pressed
                if (Keyboard.Modifiers != ModifierKeys.Control)
                {
                    HelperFunctions.UnselectAll(drawingCanvas);
                }

                // Group selection. Create selection rectangle.
                GraphicsSelectionRectangle r = new GraphicsSelectionRectangle(
                    point.X, point.Y,
                    point.X + 1, point.Y + 1,
                    drawingCanvas.ActualScale);

                r.Clip = new RectangleGeometry(new Rect(0, 0, drawingCanvas.ActualWidth, drawingCanvas.ActualHeight));

                drawingCanvas.GraphicsList.Add(r);

                selectMode = SelectionMode.GroupSelection;
            }


            lastPoint = point;

            // Capture mouse until MouseUp event is received
            drawingCanvas.CaptureMouse();
        }
Пример #4
0
 // Create this command BEFORE operation.
 public CommandChangeState(DrawingCanvas drawingCanvas)
 {
     // Keep objects state before operation.
     FillList(drawingCanvas.GraphicsList, ref listBefore);
 }
Пример #5
0
        /// <summary>
        /// Handle mouse move.
        /// Se cursor, move/resize, make group selection.
        /// </summary>
        public override void OnMouseMove(DrawingCanvas drawingCanvas, MouseEventArgs e)
        {
            // Exclude all cases except left button on/off.
            if (e.MiddleButton == MouseButtonState.Pressed ||
                e.RightButton == MouseButtonState.Pressed)
            {
                drawingCanvas.Cursor = HelperFunctions.DefaultCursor;
                return;
            }

            Point point = e.GetPosition(drawingCanvas);

            // Set cursor when left button is not pressed
            if (e.LeftButton == MouseButtonState.Released)
            {
                Cursor cursor = null;

                for (int i = 0; i < drawingCanvas.Count; i++)
                {
                    int n = drawingCanvas[i].MakeHitTest(point);

                    if (n > 0)
                    {
                        cursor = drawingCanvas[i].GetHandleCursor(n);
                        break;
                    }
                }

                if (cursor == null)
                {
                    cursor = HelperFunctions.DefaultCursor;
                }

                drawingCanvas.Cursor = cursor;

                return;
            }

            if (!drawingCanvas.IsMouseCaptured)
            {
                return;
            }

            wasMove = true;

            // Find difference between previous and current position
            double dx = point.X - lastPoint.X;
            double dy = point.Y - lastPoint.Y;

            lastPoint = point;

            // Resize
            if (selectMode == SelectionMode.Size)
            {
                if (resizedObject != null)
                {
                    resizedObject.MoveHandleTo(point, resizedObjectHandle);
                }
            }

            // Move
            if (selectMode == SelectionMode.Move)
            {
                foreach (GraphicsBase o in drawingCanvas.Selection)
                {
                    o.Move(dx, dy);
                }
            }

            // Group selection
            if (selectMode == SelectionMode.GroupSelection)
            {
                // Resize selection rectangle
                drawingCanvas[drawingCanvas.Count - 1].MoveHandleTo(
                    point, 5);
            }
        }
Пример #6
0
 /// <summary>
 /// Set cursor
 /// </summary>
 public override void SetCursor(DrawingCanvas drawingCanvas)
 {
     drawingCanvas.Cursor = HelperFunctions.DefaultCursor;
 }
Пример #7
0
 /// <summary>
 /// Detete All again
 /// </summary>
 public override void Redo(DrawingCanvas drawingCanvas)
 {
     drawingCanvas.GraphicsList.Clear();
 }
Пример #8
0
        public override void OnMouseUp(DrawingCanvas drawingCanvas, MouseButtonEventArgs e)
        {
            newPolyLine = null;

            base.OnMouseUp(drawingCanvas, e);
        }
Пример #9
0
 public abstract void SetCursor(DrawingCanvas drawingCanvas);
Пример #10
0
 public abstract void OnMouseUp(DrawingCanvas drawingCanvas, MouseButtonEventArgs e);
Пример #11
0
 public abstract void OnMouseMove(DrawingCanvas drawingCanvas, MouseEventArgs e);