public RubberbandAdorner(Functionality.DesignerCanvas designerCanvas, Point?dragStartPoint) : base(designerCanvas) { this.designerCanvas = designerCanvas; this.startPoint = dragStartPoint; rubberbandPen = new Pen(Brushes.LightSlateGray, 1); rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1); }
void DragThumb_DragDelta(object sender, DragDeltaEventArgs e) { DesignerItem designerItem = this.DataContext as DesignerItem; Functionality.DesignerCanvas designer = VisualTreeHelper.GetParent(designerItem) as Functionality.DesignerCanvas; if (designerItem != null && designer != null && designerItem.IsSelected) { double minLeft = double.MaxValue; double minTop = double.MaxValue; // we only move DesignerItems var designerItems = designer.SelectionService.CurrentSelection.OfType <DesignerItem>(); foreach (DesignerItem item in designerItems) { double left = Canvas.GetLeft(item); double top = Canvas.GetTop(item); minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft); minTop = double.IsNaN(top) ? 0 : Math.Min(top, minTop); } double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange); double deltaVertical = Math.Max(-minTop, e.VerticalChange); foreach (DesignerItem item in designerItems) { double left = Canvas.GetLeft(item); double top = Canvas.GetTop(item); if (double.IsNaN(left)) { left = 0; } if (double.IsNaN(top)) { top = 0; } Canvas.SetLeft(item, left + deltaHorizontal); Canvas.SetTop(item, top + deltaVertical); } // UPD: Check to create automatic links if the object being moved is one //if (designerItems.Count() == 1) CheckAutoCreateConnection(designerItem, designer); designer.InvalidateMeasure(); e.Handled = true; } }
public SelectionService(Functionality.DesignerCanvas canvas) { this.designerCanvas = canvas; }
void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e) { DesignerItem designerItem = this.DataContext as DesignerItem; Functionality.DesignerCanvas designer = VisualTreeHelper.GetParent(designerItem) as Functionality.DesignerCanvas; if (designerItem != null && designer != null && designerItem.IsSelected) { double minLeft, minTop, minDeltaHorizontal, minDeltaVertical; double dragDeltaVertical, dragDeltaHorizontal, scale; IEnumerable <DesignerItem> selectedDesignerItems = designer.SelectionService.CurrentSelection.OfType <DesignerItem>(); CalculateDragLimits(selectedDesignerItems, out minLeft, out minTop, out minDeltaHorizontal, out minDeltaVertical); foreach (DesignerItem item in selectedDesignerItems) { if (item != null && item.ParentID == Guid.Empty) { switch (base.VerticalAlignment) { case VerticalAlignment.Bottom: dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical); scale = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight; DragBottom(scale, item, designer.SelectionService); if (item.Proportional) { switch (base.HorizontalAlignment) { case HorizontalAlignment.Left: DragLeft(scale, item, designer.SelectionService); break; default: DragRight(scale, item, designer.SelectionService); break; } } break; case VerticalAlignment.Top: double top = Canvas.GetTop(item); dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical); scale = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight; DragTop(scale, item, designer.SelectionService); if (item.Proportional) { switch (base.HorizontalAlignment) { case HorizontalAlignment.Left: DragLeft(scale, item, designer.SelectionService); break; default: DragRight(scale, item, designer.SelectionService); break; } } break; default: break; } switch (base.HorizontalAlignment) { case HorizontalAlignment.Left: double left = Canvas.GetLeft(item); dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal); scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth; if (item.Proportional) { switch (base.VerticalAlignment) { case VerticalAlignment.Bottom: case VerticalAlignment.Top: break; default: DragLeft(scale, item, designer.SelectionService); DragBottom(scale, item, designer.SelectionService); break; } } else { DragLeft(scale, item, designer.SelectionService); } break; case HorizontalAlignment.Right: dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal); scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth; if (item.Proportional) { switch (base.VerticalAlignment) { case VerticalAlignment.Bottom: case VerticalAlignment.Top: break; default: DragRight(scale, item, designer.SelectionService); DragBottom(scale, item, designer.SelectionService); break; } } else { DragRight(scale, item, designer.SelectionService); } break; default: break; } } } e.Handled = true; } }