internal bool HandleMouseRelease(object sender, MouseButtonEventArgs e) { if (e.ChangedButton != MouseButton.Left) { return(false); // We only handle left mouse button for now. } if (this.currentState == State.WindowSelection) { SetCurrentState(State.None); return(true); // Mouse event handled. } else if (this.currentState == State.NodeReposition) { Point mouseCursor = e.GetPosition(sender as IInputElement); var operation = DynCmd.DragSelectionCommand.Operation.EndDrag; var command = new DynCmd.DragSelectionCommand(mouseCursor, operation); var dynamoViewModel = dynSettings.Controller.DynamoViewModel; dynamoViewModel.ExecuteCommand(command); SetCurrentState(State.None); // Dragging operation ended. } else if (this.currentState == State.DragSetup) { SetCurrentState(State.None); } else if (this.currentState == State.PanMode) { // Change cursor back to Pan owningWorkspace.CurrentCursor = CursorLibrary.GetCursor(CursorSet.HandPan); } return(false); // Mouse event not handled. }
public void TestDragSelectionCommand() { Point point = new Point( randomizer.NextDouble() * 100, randomizer.NextDouble() * 100); var operation = ((randomizer.Next(2) == 0) ? DynCmd.DragSelectionCommand.Operation.BeginDrag : DynCmd.DragSelectionCommand.Operation.EndDrag); var cmdOne = new DynCmd.DragSelectionCommand(point, operation); var cmdTwo = DuplicateAndCompare(cmdOne); Assert.AreEqual(cmdOne.MouseCursor.X, cmdTwo.MouseCursor.X, 0.000001); Assert.AreEqual(cmdOne.MouseCursor.Y, cmdTwo.MouseCursor.Y, 0.000001); Assert.AreEqual(cmdOne.DragOperation, cmdTwo.DragOperation); }
internal bool HandleMouseRelease(object sender, MouseButtonEventArgs e) { if (e.ChangedButton != MouseButton.Left) { return(false); // We only handle left mouse button for now. } if (this.currentState == State.WindowSelection) { SelectionBoxUpdateArgs args = null; args = new SelectionBoxUpdateArgs(Visibility.Collapsed); this.owningWorkspace.RequestSelectionBoxUpdate(this, args); this.currentState = State.None; this.owningWorkspace.RequestChangeCursorUsual(this, e); return(true); // Mouse event handled. } else if (this.currentState == State.NodeReposition) { Point mouseCursor = e.GetPosition(sender as IInputElement); var operation = DynCmd.DragSelectionCommand.Operation.EndDrag; var command = new DynCmd.DragSelectionCommand(mouseCursor, operation); var dynamoViewModel = dynSettings.Controller.DynamoViewModel; dynamoViewModel.ExecuteCommand(command); this.owningWorkspace.RequestChangeCursorUsual(this, e); this.currentState = State.None; // Dragging operation ended. } else if (this.currentState == State.DragSetup) { this.currentState = State.None; } return(false); // Mouse event not handled. }
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 Rect(x, y, width, height); var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection); DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel; 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); } // Record and begin the drag operation for selected nodes. var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag; var command = new DynCmd.DragSelectionCommand(mouseCursor, operation); DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel; 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); } return(false); // Mouse event not handled. }
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 Rect(x, y, width, height); var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection); DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel; 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; } // Record and begin the drag operation for selected nodes. var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag; var command = new DynCmd.DragSelectionCommand(mouseCursor, operation); DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel; 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); } return false; // Mouse event not handled. }
internal bool HandleMouseRelease(object sender, MouseButtonEventArgs e) { if (e.ChangedButton != MouseButton.Left) return false; // We only handle left mouse button for now. if (this.currentState == State.WindowSelection) { SetCurrentState(State.None); return true; // Mouse event handled. } else if (this.currentState == State.NodeReposition) { Point mouseCursor = e.GetPosition(sender as IInputElement); var operation = DynCmd.DragSelectionCommand.Operation.EndDrag; var command = new DynCmd.DragSelectionCommand(mouseCursor, operation); var dynamoViewModel = dynSettings.Controller.DynamoViewModel; dynamoViewModel.ExecuteCommand(command); SetCurrentState(State.None); // Dragging operation ended. } else if (this.currentState == State.DragSetup) SetCurrentState(State.None); else if (this.currentState == State.PanMode) { // Change cursor back to Pan owningWorkspace.CurrentCursor = CursorLibrary.GetCursor(CursorSet.HandPan); } return false; // Mouse event not handled. }