/// <summary> /// PerformShapeDragEnd - Stores the ending position of the element in case of a undo command /// </summary> /// <param name="e">DragCompletedEvent</param> private void PerformShapeDragEnd(DragCompletedEventArgs e) { if (_shapeMode) { return; } var element = e.Source as FrameworkElement; if (element == null) { return; } var shape = element.DataContext as ShapeViewModel; _undoEndPositon = new Point(shape.X, shape.Y); // If we selected a shape, but we didn't move it, then we shouldn't insert it in undoRedo. if (!(Math.Abs(_undoEndPositon.X - _undoStartPosition.X) > 1) || !(Math.Abs(_undoEndPositon.Y - _undoStartPosition.Y) > 1)) { return; } IUndoRedoCommand cmd = new MoveShapeCommand(SelectedElements[SelectedElements.Count - 1], _undoStartPosition, _undoEndPositon); _undoRedo.InsertInUndoRedo(cmd); }
private void Form1_MouseUp(object sender, MouseEventArgs e) { bool hasMoved = mouseDownLocation.X != e.X || mouseDownLocation.Y != e.Y; if (hasSelected) { if (hasSecondSelected) { ShapeComposite newGroup = new ShapeComposite("group"); newGroup.AddChild(SelectedShape); newGroup.AddChild(SecondSelectedShape); shapeList.Remove(SelectedShape); shapeList.Remove(SecondSelectedShape); SecondSelectedShape.selected = false; SecondSelectedShape = null; Command groupShape = new AddShapeCommand(shapeList, newGroup); history.Add(groupShape); Command selectShape = new SelectShapeCommand(newGroup, this); history.Add(selectShape); } if (hasMoved) { Point velocity = new Point(e.Location.X - mouseDownLocation.X, e.Location.Y - mouseDownLocation.Y); Command moveShape = new MoveShapeCommand(SelectedShape, velocity, shapeStartPosition); history.Add(moveShape); } Invalidate(); } }
private void Form1_MouseUp(object sender, MouseEventArgs e) { bool hasMoved = mouseDownLocation.X != e.X || mouseDownLocation.Y != e.Y; if (hasSelected && hasMoved) { Point velocity = new Point(e.Location.X - mouseDownLocation.X, e.Location.Y - mouseDownLocation.Y); Command moveShape = new MoveShapeCommand(SelectedShape, velocity, shapeStartPosition); history.Add(moveShape); Invalidate(); } }
private void Form1_MouseUp(object sender, MouseEventArgs e) { bool hasMoved = mouseDownLocation.X != e.X || mouseDownLocation.Y != e.Y; if (hasSelected) { if (hasSecondSelected) { ShapeComposite newGroup = new ShapeComposite(); newGroup.AddChild(SelectedShape); newGroup.AddChild(SecondSelectedShape); MacroCommand macroCommandSelectedShape = new MacroCommand(); macroCommandSelectedShape.Add(new CustomCommand( () => { shapeList.Remove(SelectedShape); shapeList.Remove(SecondSelectedShape); }, () => { shapeList.Add(newGroup.groupMembers[0]); shapeList.Add(newGroup.groupMembers[1]); } )); SecondSelectedShape.selected = false; SecondSelectedShape = null; macroCommandSelectedShape.Add(new AddShapeCommand(shapeList, newGroup)); history.Add(macroCommandSelectedShape); } if (hasMoved) { Point velocity = new Point(e.Location.X - mouseDownLocation.X, e.Location.Y - mouseDownLocation.Y); Command moveShape = new MoveShapeCommand(SelectedShape, velocity, shapeStartPosition); history.Add(moveShape); } Invalidate(); } }