コード例 #1
0
ファイル: StateMachine.cs プロジェクト: sm6srw/Dynamo
            internal bool HandleMouseMove(object sender, Point mouseCursor)
            {
                if (this.currentState == State.Connection)
                {
                    // If we are currently connecting and there is an active 
                    // connector, redraw it to match the new mouse coordinates.
                    owningWorkspace.UpdateActiveConnector(mouseCursor);
                }
                else if (this.currentState == State.WindowSelection)
                {
                    // When the mouse is held down, reposition the drag selection box.
                    double x = Math.Min(mouseDownPos.X, mouseCursor.X);
                    double y = Math.Min(mouseDownPos.Y, mouseCursor.Y);
                    double width = Math.Abs(mouseDownPos.X - mouseCursor.X);
                    double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y);

                    // We perform cross selection (i.e. select a node whenever 
                    // it touches the selection box as opposed to only select 
                    // it when it is entirely within the selection box) when 
                    // mouse moves in the opposite direction (i.e. the current 
                    // mouse position is smaller than the point mouse-down 
                    // happened).
                    // 
                    bool isCrossSelection = mouseCursor.X < mouseDownPos.X;

                    SelectionBoxUpdateArgs args = null;
                    args = new SelectionBoxUpdateArgs(x, y, width, height);
                    args.SetSelectionMode(isCrossSelection);
                    this.owningWorkspace.RequestSelectionBoxUpdate(this, args);

                    var rect = new Dynamo.Utilities.Rect2D(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                }
                else if (this.currentState == State.DragSetup)
                {
                    // There are something in the selection, but none is ILocatable.
                    if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable)))
                    {
                        SetCurrentState(State.None);
                        return false;
                    }

                    if (Keyboard.Modifiers != ModifierKeys.Control)
                    {
                        // Record and begin the drag operation for selected nodes.
                        var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                        var command = new DynCmd.DragSelectionCommand(
                            mouseCursor.AsDynamoType(),
                            operation);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        SetCurrentState(State.NodeReposition);
                        return true;
                    }

                }
                else if (this.currentState == State.NodeReposition)
                {
                    // Update the dragged nodes (note: this isn't recorded).
                    owningWorkspace.UpdateDraggedSelection(mouseCursor.AsDynamoType());
                }

                return false; // Mouse event not handled.
            }
コード例 #2
0
ファイル: StateMachine.cs プロジェクト: jxndwl/Dynamo
            internal bool HandleMouseMove(object sender, Point mouseCursor)
            {
                if (this.currentState == State.Connection)
                {
                    // If we are currently connecting and there is an active
                    // connector, redraw it to match the new mouse coordinates.
                    owningWorkspace.UpdateActiveConnector(mouseCursor);
                }
                else if (this.currentState == State.WindowSelection)
                {
                    // When the mouse is held down, reposition the drag selection box.
                    double x      = Math.Min(mouseDownPos.X, mouseCursor.X);
                    double y      = Math.Min(mouseDownPos.Y, mouseCursor.Y);
                    double width  = Math.Abs(mouseDownPos.X - mouseCursor.X);
                    double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y);

                    // We perform cross selection (i.e. select a node whenever
                    // it touches the selection box as opposed to only select
                    // it when it is entirely within the selection box) when
                    // mouse moves in the opposite direction (i.e. the current
                    // mouse position is smaller than the point mouse-down
                    // happened).
                    //
                    bool isCrossSelection = mouseCursor.X < mouseDownPos.X;

                    SelectionBoxUpdateArgs args = null;
                    args = new SelectionBoxUpdateArgs(x, y, width, height);
                    args.SetSelectionMode(isCrossSelection);
                    this.owningWorkspace.RequestSelectionBoxUpdate(this, args);

                    var rect = new Dynamo.Utilities.Rect2D(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);
                }
                else if (this.currentState == State.DragSetup)
                {
                    // There are something in the selection, but none is ILocatable.
                    if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable)))
                    {
                        SetCurrentState(State.None);
                        return(false);
                    }

                    if (Keyboard.Modifiers != ModifierKeys.Control)
                    {
                        // Record and begin the drag operation for selected nodes.
                        var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                        var command   = new DynCmd.DragSelectionCommand(
                            mouseCursor.AsDynamoType(),
                            operation);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        SetCurrentState(State.NodeReposition);
                        return(true);
                    }
                }
                else if (this.currentState == State.NodeReposition)
                {
                    // Update the dragged nodes (note: this isn't recorded).
                    owningWorkspace.UpdateDraggedSelection(mouseCursor.AsDynamoType());
                }

                return(false); // Mouse event not handled.
            }
コード例 #3
0
            internal bool HandleMouseMove(object sender, Point mouseCursor)
            {
                if (this.currentState == State.Connection)
                {
                    // If we are currently connecting and there is an active
                    // connector, redraw it to match the new mouse coordinates.
                    owningWorkspace.UpdateActiveConnector(mouseCursor);
                }
                else if (this.currentState == State.WindowSelection)
                {
                    // When the mouse is held down, reposition the drag selection box.
                    double x      = Math.Min(mouseDownPos.X, mouseCursor.X);
                    double y      = Math.Min(mouseDownPos.Y, mouseCursor.Y);
                    double width  = Math.Abs(mouseDownPos.X - mouseCursor.X);
                    double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y);

                    // We perform cross selection (i.e. select a node whenever
                    // it touches the selection box as opposed to only select
                    // it when it is entirely within the selection box) when
                    // mouse moves in the opposite direction (i.e. the current
                    // mouse position is smaller than the point mouse-down
                    // happened).
                    //
                    bool isCrossSelection = mouseCursor.X < mouseDownPos.X;

                    SelectionBoxUpdateArgs args = null;
                    args = new SelectionBoxUpdateArgs(x, y, width, height);
                    args.SetSelectionMode(isCrossSelection);
                    this.owningWorkspace.RequestSelectionBoxUpdate(this, args);

                    var rect = new Dynamo.Utilities.Rect2D(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);
                }
                else if (this.currentState == State.DragSetup)
                {
                    // There are something in the selection, but none is ILocatable.
                    if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable)))
                    {
                        SetCurrentState(State.None);
                        return(false);
                    }

                    if (Keyboard.Modifiers != ModifierKeys.Control)
                    {
                        // Record and begin the drag operation for selected nodes.
                        var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                        var command   = new DynCmd.DragSelectionCommand(
                            mouseCursor.AsDynamoType(),
                            operation);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        SetCurrentState(State.NodeReposition);
                        return(true);
                    }
                }
                else if (this.currentState == State.NodeReposition)
                {
                    // Update the dragged nodes (note: this isn't recorded).
                    owningWorkspace.UpdateDraggedSelection(mouseCursor.AsDynamoType());

                    var draggedGroups = DynamoSelection.Instance.Selection.OfType <AnnotationModel>();

                    // Here we check if the mouse cursor is inside any Annotation groups
                    var dropGroups = owningWorkspace.Annotations
                                     .Where(x =>
                                            !draggedGroups.Select(a => a.GUID).Contains(x.AnnotationModel.GUID) &&
                                            x.IsExpanded &&
                                            x.AnnotationModel.Rect.Contains(mouseCursor.X, mouseCursor.Y));

                    // In scenarios where there are nested groups, the above will return both
                    // the nested group and the parent group, as the mouse coursor will be inside
                    // both of there rects. In these cases we want to get group that is nested
                    // inside the parent group.
                    var dropGroup = dropGroups
                                    .FirstOrDefault(x => !x.AnnotationModel.HasNestedGroups) ?? dropGroups.FirstOrDefault();


                    // If the dropGroup is null or any of the selected items is already in the dropGroup,
                    // we disable the drop border by setting NodeHoveringState to false
                    var draggedModels = DynamoSelection.Instance.Selection
                                        .OfType <ModelBase>()
                                        .Except(draggedGroups.SelectMany(x => x.Nodes));

                    if (dropGroup is null ||
                        draggedModels
                        .Any(x => owningWorkspace.Model.Annotations.ContainsModel(x)))
                    {
                        owningWorkspace.Annotations
                        .Where(x => x.NodeHoveringState)
                        .ToList()
                        .ForEach(x => x.NodeHoveringState = false);
                    }

                    // If we are dragging groups over a group that is already nested
                    // we return as we cant have more than one nested layer
                    else if (draggedGroups.Any() &&
                             owningWorkspace.Model.Annotations.ContainsModel(dropGroup.AnnotationModel) ||
                             draggedGroups.Any(x => x.HasNestedGroups))
                    {
                        return(false); // Mouse event not handled.
                    }

                    // If the dropGroups NodeHoveringState is set to false
                    // we need to set it to true for the drop border to be displayed.
                    else if (!dropGroup.NodeHoveringState)
                    {
                        // make sure there are no other group
                        // set to NodeHoveringState before setting
                        // the current group.
                        // If we dont do this there are scenarios where
                        // two groups are very close and a node is dragged
                        // quickly between the two where the hovering state
                        // is not reset.
                        owningWorkspace.Annotations
                        .Where(x => x.NodeHoveringState)
                        .ToList()
                        .ForEach(x => x.NodeHoveringState = false);

                        // If the dropGroup belongs to another group
                        // we need to check if the parent group is collapsed
                        // if it is we dont want to be able to add new
                        // models to the drop group.
                        var parentGroup = owningWorkspace.Annotations
                                          .Where(x => x.AnnotationModel.ContainsModel(dropGroup.AnnotationModel))
                                          .FirstOrDefault();
                        if (parentGroup != null && !parentGroup.IsExpanded)
                        {
                            return(false);
                        }

                        dropGroup.NodeHoveringState = true;
                    }
                }