コード例 #1
0
        private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (isResizing && (e.LeftButton == MouseButtonState.Pressed))
            {
                if (moveFirst)
                {
                    inkCanvas.Children.Remove(chosenFigUI);
                }
                else
                {
                    inkCanvas.Children.RemoveAt(inkCanvas.Children.Count - 2);
                }
                //chosenFigUI = null;

                moveFirst = false;
                b         = e.GetPosition(inkCanvas);
                if (isFirstHoriz)
                {
                    chosenFig.firstPoint.X += e.GetPosition(inkCanvas).X - startResize.X;
                    if (chosenFig is Square || chosenFig is Circle)
                    {
                        chosenFig.firstPoint.Y += e.GetPosition(inkCanvas).X - startResize.X;
                    }
                }
                else
                if (isSecondHoriz)
                {
                    chosenFig.secondPoint.X += e.GetPosition(inkCanvas).X - startResize.X;
                    if (chosenFig is Square || chosenFig is Circle)
                    {
                        chosenFig.secondPoint.Y += e.GetPosition(inkCanvas).X - startResize.X;
                    }
                }
                else
                if (isFirstVert)
                {
                    chosenFig.firstPoint.Y += e.GetPosition(inkCanvas).Y - startResize.Y;
                    if (chosenFig is Square || chosenFig is Circle)
                    {
                        chosenFig.firstPoint.X += e.GetPosition(inkCanvas).Y - startResize.Y;
                    }
                }
                else
                if (isSecondVert)
                {
                    chosenFig.secondPoint.Y += e.GetPosition(inkCanvas).Y - startResize.Y;
                    if (chosenFig is Square || chosenFig is Circle)
                    {
                        chosenFig.secondPoint.X += e.GetPosition(inkCanvas).Y - startResize.Y;
                    }
                }

                chosenFig.Draw(inkCanvas);
                inkCanvas.Children[inkCanvas.Children.Count - 1].MouseDown += MainWindow_MouseDown;
                inkCanvas.Children[inkCanvas.Children.Count - 1].MouseUp   += MainWindow_MouseUp;
                ((System.Windows.Shapes.Shape)inkCanvas.Children[inkCanvas.Children.Count - 1]).Cursor = Cursors.Cross;
                chosenFigUI = inkCanvas.Children[inkCanvas.Children.Count - 1];
                inkCanvas.Children.Remove(frame);
                DrawFrame(chosenFig);
                startResize = e.GetPosition(inkCanvas);
                return;
            }
            else
            if (chosenFigUI != null && chosenFig != null && (e.LeftButton == MouseButtonState.Pressed) && isMoving)
            {
                if (moveFirst)
                {
                    inkCanvas.Children.Remove(chosenFigUI);
                }
                else
                {
                    inkCanvas.Children.RemoveAt(inkCanvas.Children.Count - 2);
                }

                moveFirst = false;

                b = e.GetPosition(inkCanvas);
                chosenFig.firstPoint.X  = x.X + b.X - a.X;
                chosenFig.firstPoint.Y  = x.Y + b.Y - a.Y;
                chosenFig.secondPoint.X = y.X + b.X - a.X;
                chosenFig.secondPoint.Y = y.Y + b.Y - a.Y;

                chosenFig.Draw(inkCanvas);
                chosenFigUI = inkCanvas.Children[inkCanvas.Children.Count - 1];

                inkCanvas.Children[inkCanvas.Children.Count - 1].MouseDown += MainWindow_MouseDown;
                inkCanvas.Children[inkCanvas.Children.Count - 1].MouseUp   += MainWindow_MouseUp;
                ((System.Windows.Shapes.Shape)inkCanvas.Children[inkCanvas.Children.Count - 1]).Cursor = Cursors.Cross;
                inkCanvas.Children.Remove(frame);
                DrawFrame(chosenFig);

                return;
            }
            else
            if (isDrawing && (e.LeftButton == MouseButtonState.Pressed) && !isResizing && !isMoving)
            {
                b                   = e.GetPosition(inkCanvas);
                current             = creators[tag].Create();
                current.firstPoint  = a;
                current.secondPoint = b;
                current.thickness   = thickness;
                // ChangingObjects();
                if (!drawFirst)
                {
                    inkCanvas.Children.RemoveAt(inkCanvas.Children.Count - 1);
                    printedFigures.RemoveAt(printedFigures.Count - 1);
                }
                drawFirst = false;


                printedFigures.Add(current);
                current.Draw(inkCanvas);
                inkCanvas.Children[inkCanvas.Children.Count - 1].MouseDown += MainWindow_MouseDown;
                inkCanvas.Children[inkCanvas.Children.Count - 1].MouseUp   += MainWindow_MouseUp;
                ((System.Windows.Shapes.Shape)inkCanvas.Children[inkCanvas.Children.Count - 1]).Cursor = Cursors.Cross;

                isCanceled = false;
                //isRedo = false;
                deletedFigures.Clear();
                removedFigures.Clear();
                return;
            }
        }