public override void Abort() { _preferredPlacements = null; CurrentEditor.ReleaseMouseCapture(); CurrentAdorner = null; Target = null; MouseIsDown = false; IsDrawing = false; CurrentStatus = DefaultStatusText; }
private void RemoveRingAdorner() { if (_currentAdorner != null) { var layer = AdornerLayer.GetAdornerLayer(CurrentEditor); layer.Remove(_currentAdorner); _currentAdorner.MouseLeftButtonDown -= _currentAdorner_MouseLeftButtonDown; _currentAdorner.MouseLeftButtonUp -= _currentAdorner_MouseLeftButtonUp; _currentAdorner.PreviewKeyDown -= CurrentAdorner_KeyDown; _currentAdorner.MouseMove -= _currentAdorner_MouseMove; _currentAdorner = null; } }
protected override void OnDetaching() { CurrentAdorner = null; CurrentEditor.MouseLeftButtonDown -= CurrentEditor_MouseLeftButtonDown; CurrentEditor.MouseMove -= CurrentEditor_MouseMove; CurrentEditor.MouseLeftButtonUp -= CurrentEditor_MouseLeftButtonUp; CurrentEditor.PreviewKeyDown -= CurrentEditor_KeyDown; CurrentEditor = null; if (_parent != null) { _parent.MouseLeftButtonDown -= CurrentEditor_MouseLeftButtonDown; } _parent = null; }
private void CurrentEditor_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (MouseIsDown) { if (_preferredPlacements != null) { List<NewAtomPlacement> newAtomPlacements = new List<NewAtomPlacement>(); FillExistingAtoms(_preferredPlacements, newAtomPlacements, CurrentEditor); EditViewModel.DrawRing(newAtomPlacements, false); } } CurrentEditor.ReleaseMouseCapture(); CurrentAdorner = null; Target = null; MouseIsDown = false; IsDrawing = false; CurrentStatus = DefaultStatusText; }
private void CurrentEditor_MouseMove(object sender, MouseEventArgs e) { CurrentPoint = e.GetPosition(CurrentEditor); //check to see whether we've dragged off the target first if (MouseIsDown & IsDrawing) { CurrentStatus = "Drag along arrow to size ring: [Esc] to cancel"; double xamlBondSize = EditViewModel.Model.XamlBondLength; if (Target != null & GetTargetedVisual(e) != Target) //dragging off a bond or atom { //first, work out how far we've dragged the mouse switch (Target) { case AtomVisual av: RingSize = GetRingSize(av, CurrentPoint, xamlBondSize); IdentifyPlacements(av.ParentAtom, xamlBondSize, out _preferredPlacements, RingSize); if (_preferredPlacements != null) { Vector parallelToBV = GetProjection(av.ParentAtom.BalancingVector(), av.Position, CurrentPoint); Point endPoint = av.Position + parallelToBV; CurrentAdorner = new NRingAdorner(CurrentEditor, EditViewModel.EditBondThickness, _preferredPlacements, av.Position, endPoint); } break; case BondVisual bv: RingSize = GetRingSizeFromEdge(bv, CurrentPoint); Vector perpToBV = GetProjection(bv.ParentBond.BondVector.Perpendicular(), bv.ParentBond.MidPoint, CurrentPoint); IdentifyPlacements(bv.ParentBond, out _preferredPlacements, RingSize, perpToBV); if (_preferredPlacements != null) { Vector? perpToAV = bv.ParentBond.GetUncrowdedSideVector(); if (perpToAV != null) { var parentBondMidPoint = bv.ParentBond.MidPoint; Vector parallelToPerp = GetProjection(perpToAV.Value, parentBondMidPoint, CurrentPoint); Point endPoint = parentBondMidPoint + parallelToPerp; CurrentAdorner = new NRingAdorner(CurrentEditor, EditViewModel.EditBondThickness, _preferredPlacements, parentBondMidPoint, endPoint); } else { CurrentAdorner = null; } } else { CurrentAdorner = null; } break; } } else if (Target == null) //dragging in empty space { RingSize = GetRingSize(FirstPoint, CurrentPoint, xamlBondSize); _preferredPlacements = MarkOutAtoms(FirstPoint, CurrentPoint - FirstPoint, xamlBondSize, RingSize); CurrentAdorner = new NRingAdorner(CurrentEditor, EditViewModel.EditBondThickness, _preferredPlacements, FirstPoint, CurrentPoint); } else { switch (CurrentEditor.ActiveVisual) { case AtomVisual av: CurrentStatus = "Drag from atom to size ring."; break; case BondVisual bv: CurrentStatus = "Drag from bond to size ring."; break; default: CurrentStatus = DefaultStatusText; break; } } } }