Ejemplo n.º 1
0
        public MainViewModel()
        {
            pullCanvas = new PullCanvas(false, false, false);

            MouseDownCanvasCommand = new RelayCommand<MouseButtonEventArgs>(MouseDownCanvas);
            MouseMoveCanvasCommand = new RelayCommand<MouseEventArgs>(MouseMoveCanvas);
            MouseUpCanvasCommand = new RelayCommand<MouseButtonEventArgs>(MouseUpCanvas);
        }
Ejemplo n.º 2
0
        private void MouseDownCanvas(MouseButtonEventArgs e)
        {
            Point CurrentMousePosition = Mouse.GetPosition(e.MouseDevice.Target);
            if (CurrentMousePosition.X <= CanvasWidth + 10 && CurrentMousePosition.X >= CanvasWidth - 10 && CurrentMousePosition.Y <= CanvasHeight + 10 && CurrentMousePosition.Y >= CanvasHeight - 10)
            {
                pullCanvas = new PullCanvas(true,true,true);
            }
            else if(CurrentMousePosition.X <= CanvasWidth + 10 && CurrentMousePosition.X >= CanvasWidth - 10)
            {
                pullCanvas = new PullCanvas(true, true, false);
            }
            else if(CurrentMousePosition.Y <= CanvasHeight + 10 && CurrentMousePosition.Y >= CanvasHeight - 10)
            {
                pullCanvas = new PullCanvas(true, false, true);
            }
            else
            {
                if (!nodeClicked)
                {
                    clearSelectedNodes();
                    SelectionBoxStart = Mouse.GetPosition(e.MouseDevice.Target);
                    MouseDownCanvasCalled = true;
                    NodeBoxUpdate();
                    isAddingLine = false;
                    isChangingColor = false;
                    isChangingColorText = false;
                    Messenger.Default.Send(Cursors.Arrow);
                    if (fromNode != null) { fromNode.Color = fromNode.PreColor; fromNode = null; }

                }
                else
                {
                    var node = TargetShape(e);
                    if(editNode != null && node != editNode)
                    {
                        NodeBoxUpdate();
                    }
                }
            }
            e.MouseDevice.Target.CaptureMouse();
        }
Ejemplo n.º 3
0
        private void MouseUpCanvas(MouseButtonEventArgs e)
        {
            if(Mouse.Captured != null)
            {
                if (!isAddingLine && MouseDownCanvasCalled)
                {

                    MouseDownCanvasCalled = false;
                    var SelectionBoxEnd = Mouse.GetPosition(e.MouseDevice.Target);
                    var smallX = Math.Min(SelectionBoxStart.X, SelectionBoxEnd.X);
                    var smallY = Math.Min(SelectionBoxStart.Y, SelectionBoxEnd.Y);
                    var largeX = Math.Max(SelectionBoxStart.X, SelectionBoxEnd.X);
                    var largeY = Math.Max(SelectionBoxStart.Y, SelectionBoxEnd.Y);
                    foreach (NodeViewModel n in Nodes)
                        if (!(n.X > largeX || n.X + n.Diameter < smallX || n.Y > largeY || n.Y + n.Diameter < smallY))
                        {
                            addToSelectedNodes(n);
                        }

                    SelectionBoxX = SelectionBoxY = SelectionBoxWidth = SelectionBoxHeight = 0;
                    RaisePropertyChanged(() => SelectionBoxX);
                    RaisePropertyChanged(() => SelectionBoxY);
                    RaisePropertyChanged(() => SelectionBoxWidth);
                    RaisePropertyChanged(() => SelectionBoxHeight);

                }

                if (pullCanvas.isPullingCanvas)
                {
                    Func<NodeViewModel, bool> isInsideCanvasWidth = n => n.X + n.Diameter < CanvasWidth && n.X > 0;
                    Func<NodeViewModel, bool> isInsideCanvasHeight = n => n.Y + n.Diameter < CanvasHeight && n.Y > 0;
                    foreach (var n in Nodes)
                    {
                        if (!isInsideCanvasWidth(n)) CanvasWidth = (int)n.X + (int)n.Diameter;
                        if (!isInsideCanvasHeight(n)) CanvasHeight = (int)n.Y + (int)n.Diameter;
                    }
                    if (CanvasHeight < 0) CanvasHeight = 100;
                    if (CanvasWidth < 0) CanvasWidth = 100;
                    pullCanvas = new PullCanvas(false, false, false);
                }
                e.MouseDevice.Target.ReleaseMouseCapture();
            }
        }