private void UpdateSelection(Collection <ISelectable> itemsToSelect, Rect rubberBand, DiagramDesignerCanvas dCanvas) { foreach (Control item in dCanvas.Children) { Rect itemRect = VisualTreeHelper.GetDescendantBounds(item); Rect itemBounds = item.TransformToAncestor(designerCanvas).TransformBounds(itemRect); // drag decorator requires this; itemBounds.Inflate(-DragDecoratorInflateValue, -DragDecoratorInflateValue); if (rubberBand.Contains(itemBounds)) { if (item is ISelectable) { itemsToSelect.Add(item as ISelectable); } } if (item is DiagramDesignerItem) { DiagramDesignerItem designerItem = item as DiagramDesignerItem; if (designerItem.IsDiagramLink) { continue; } DiagramDesignerCanvas canvas = DiagramHelper.GetChild(designerItem, typeof(DiagramDesignerCanvas)) as DiagramDesignerCanvas; if (canvas != null) { UpdateSelection(itemsToSelect, rubberBand, canvas); } } } }
/// <summary> /// Contructor. /// </summary> /// <param name="designerCanvas">Designer items canvas.</param> /// <param name="dragStartPoint">Start point.</param> public DiagramDesignerRubberbandAdorner(DiagramDesignerCanvas designerCanvas, Point?dragStartPoint) : base(designerCanvas) { this.designerCanvas = designerCanvas; this.designer = DiagramHelper.GetDiagramDesigner(this.designerCanvas); this.startPoint = dragStartPoint; rubberbandPen = new Pen(Brushes.LightSlateGray, 1); rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1); }
/// <summary> /// Contructor. /// </summary> /// <param name="designerCanvas">Designer items canvas.</param> /// <param name="dragStartPoint">Start point.</param> public DiagramDesignerRubberbandAdorner(DiagramDesignerCanvas designerCanvas, Point? dragStartPoint) : base(designerCanvas) { this.designerCanvas = designerCanvas; this.designer = DiagramHelper.GetDiagramDesigner(this.designerCanvas); this.startPoint = dragStartPoint; rubberbandPen = new Pen(Brushes.LightSlateGray, 1); rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1); }
/// <summary> /// Draw the rubberband. /// </summary> /// <param name="e"></param> /// <param name="control"></param> public static void DrawOnMouseMove(MouseEventArgs e, DiagramDesignerCanvas control) { if (IgnoreRubberbandSelectionOnce) { IgnoreRubberbandSelectionOnce = false; CancelRubberbandSelection(); return; } if (RubberbandSelectionStartPoint.HasValue) { // if mouse button is not pressed we have no drag operation, ... if (e.LeftButton != MouseButtonState.Pressed) RubberbandSelectionStartPoint = null; // ... but if mouse button is pressed and start // point value is set we do have one else { Point pCurrent = e.GetPosition(control); if (Math.Abs(pCurrent.X - RubberbandSelectionStartPoint.Value.X) > 5 || Math.Abs(pCurrent.Y - RubberbandSelectionStartPoint.Value.Y) > 5) { // create rubberband adorner AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(control); if (adornerLayer != null) { DiagramDesignerRubberbandAdorner adorner = new DiagramDesignerRubberbandAdorner(control, RubberbandSelectionStartPoint); if (adorner != null) { adornerLayer.Add(adorner); } } } } } }
/// <summary> /// Draw the rubberband. /// </summary> /// <param name="e"></param> /// <param name="control"></param> public static void DrawOnMouseMove(MouseEventArgs e, DiagramDesignerCanvas control) { if (IgnoreRubberbandSelectionOnce) { IgnoreRubberbandSelectionOnce = false; CancelRubberbandSelection(); return; } if (RubberbandSelectionStartPoint.HasValue) { // if mouse button is not pressed we have no drag operation, ... if (e.LeftButton != MouseButtonState.Pressed) { RubberbandSelectionStartPoint = null; } // ... but if mouse button is pressed and start // point value is set we do have one else { Point pCurrent = e.GetPosition(control); if (Math.Abs(pCurrent.X - RubberbandSelectionStartPoint.Value.X) > 5 || Math.Abs(pCurrent.Y - RubberbandSelectionStartPoint.Value.Y) > 5) { // create rubberband adorner AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(control); if (adornerLayer != null) { DiagramDesignerRubberbandAdorner adorner = new DiagramDesignerRubberbandAdorner(control, RubberbandSelectionStartPoint); if (adorner != null) { adornerLayer.Add(adorner); } } } } } }
/// <summary> /// Dragging has ended, see if VM is IDiagramDesignerItem and notify of moving end. /// </summary> void DragThumb_DragCompleted(object sender, DragCompletedEventArgs e) { if (!dragStarted) { return; } else { dragStarted = false; } DiagramItemsMovementInfo movementInfo = diagramDesignerVM.CalcMovementInfo(this.selectedItemsVM, e.HorizontalChange, e.VerticalChange); diagramDesignerVM.MoveElements(selectedItemsVM, movementInfo); List <DiagramDesignerCanvas> selectionParentCanvases = new List <DiagramDesignerCanvas>(); foreach (DiagramDesignerItem item in selectedItems) { /* * IDiagramItemViewModel designerItem = item.DataContext as IDiagramItemViewModel; * if (designerItem == null) * continue; * * // apply change * double left = designerItem.Left + dragAdorner.LeftOffset; * double top = designerItem.Top + dragAdorner.TopOffset; * designerItem.Location = new PointD(left, top); */ DiagramDesignerCanvas canvas = (item as DiagramDesignerItem).ParentCanvas; if (canvas != null) { if (!selectionParentCanvases.Contains(canvas)) { selectionParentCanvases.Add(canvas); } } } // update diagram surfaces foreach (DiagramDesignerCanvas canvas in selectionParentCanvases) { if (canvas != null) { canvas.InvalidateMeasure(); } } // remove drag adorner if (this.IsMouseCaptured) { this.ReleaseMouseCapture(); } AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.diagramDesigner); if (adornerLayer != null) { adornerLayer.Remove(this.dragAdorner); } e.Handled = false; }
private void UpdateSelection(Collection<ISelectable> itemsToSelect, Rect rubberBand, DiagramDesignerCanvas dCanvas) { foreach (Control item in dCanvas.Children) { Rect itemRect = VisualTreeHelper.GetDescendantBounds(item); Rect itemBounds = item.TransformToAncestor(designerCanvas).TransformBounds(itemRect); // drag decorator requires this; itemBounds.Inflate(-DragDecoratorInflateValue, -DragDecoratorInflateValue); if (rubberBand.Contains(itemBounds)) { if (item is ISelectable) itemsToSelect.Add(item as ISelectable); } if (item is DiagramDesignerItem) { DiagramDesignerItem designerItem = item as DiagramDesignerItem; if (designerItem.IsDiagramLink) continue; DiagramDesignerCanvas canvas = DiagramHelper.GetChild(designerItem, typeof(DiagramDesignerCanvas)) as DiagramDesignerCanvas; if (canvas != null) { UpdateSelection(itemsToSelect, rubberBand, canvas); } } } }