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) { 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(); } }
public override void Visit(ShapeComposite shapeComposite) { // For now we know groups are always 2 shapes big int childCount = 2; for (int i = 0; i < childCount; i++) { currentLine = streamReader.ReadLine(); Shape shape = CreateShapeFromLine(currentLine); shape.Accept(this); shapeComposite.AddChild(shape); } }