// Arrange the Adorners. protected override Size ArrangeOverride(Size finalSize) { // desiredWidth and desiredHeight are the width and height of the element that's being adorned. // These will be used to place the ResizingAdorner at the corners of the adorned element. double desiredWidth = AdornedElement.DesiredSize.Width; double desiredHeight = AdornedElement.DesiredSize.Height; // adornerWidth & adornerHeight are used for placement as well. double adornerWidth = this.DesiredSize.Width; double adornerHeight = this.DesiredSize.Height; switch (m_strelement_prefix) { case "DC": if (AdornedElement.GetType() == typeof(Line) || AdornedElement.GetType() == typeof(Ellipse)) { if (AdornedElement.GetType() == typeof(Ellipse)) { contextData = ((List <Point>)((AdornedElement as FrameworkElement).DataContext)); } Line selectedLine = ((AdornedElement.GetType() == typeof(Ellipse)) && contextData.Count != 0) ? new Line() { X1 = contextData[0].X, Y1 = contextData[0].Y, X2 = contextData[1].X, Y2 = contextData[1].Y } : (AdornedElement as Line); double left = Math.Min(selectedLine.X1, selectedLine.X2); double top = Math.Min(selectedLine.Y1, selectedLine.Y2); var startRect = new Rect(selectedLine.X1 - (Left.Width / 2), selectedLine.Y1 - (Left.Width / 2), Left.Width, Left.Height); var endRect = new Rect(selectedLine.X2 - (Right.Width / 2), selectedLine.Y2 - (Right.Height / 2), Right.Width, Right.Height); Left.Arrange(startRect); Right.Arrange(endRect); } break; case "RC": if (AdornedElement.GetType() == typeof(Line) || AdornedElement.GetType() == typeof(Ellipse)) { if (AdornedElement.GetType() == typeof(Ellipse)) { contextData = ((List <Point>)((AdornedElement as FrameworkElement).DataContext)); } Line selectedLine = ((AdornedElement.GetType() == typeof(Ellipse)) && contextData.Count != 0) ? new Line() { X1 = contextData[0].X, Y1 = contextData[0].Y, X2 = contextData[1].X, Y2 = contextData[1].Y } : (AdornedElement as Line); double top = Math.Min(selectedLine.Y1, selectedLine.Y2); var endRect = new Rect(selectedLine.X2 - (Right.Width / 2), selectedLine.Y2 - (Right.Height / 2), Right.Width, Right.Height); Right.Arrange(endRect); } break; } return(finalSize); }
void onDragDeltaLeft(object sender, DragDeltaEventArgs args) { FrameworkElement adornedElement = AdornedElement as FrameworkElement; System.Windows.Controls.Primitives.Thumb hitThumb = sender as System.Windows.Controls.Primitives.Thumb; if (adornedElement == null || hitThumb == null) { return; } Point position = Mouse.GetPosition(this); double distance = 0; Point _startPoint = new Point(); switch (m_strelement_prefix) { #region Diameter Circle case "DC": foreach (UIElement ui in multiObject) { if (ui.GetType() != AdornedElement.GetType()) { switch (ui.GetType().ToString()) { //Selected Element is Ellipse case "System.Windows.Shapes.Line": _startPoint = new Point(); distance = getMidPoint(new Point(((Line)ui).X2, ((Line)ui).Y2), position, out _startPoint, true); ((Line)ui).X2 = position.X; ((Line)ui).Y2 = position.Y; ((Ellipse)adornedElement).Height = ((Ellipse)adornedElement).Width = distance * 2; Canvas.SetLeft(ui, (new Thickness((_startPoint.X - ((distance * 2) / 2)), (_startPoint.Y - ((distance * 2) / 2)), 0, 0)).Left); Canvas.SetTop(ui, (new Thickness((_startPoint.X - ((distance * 2) / 2)), (_startPoint.Y - ((distance * 2) / 2)), 0, 0)).Top); break; //Selected Element is Line case "System.Windows.Shapes.Ellipse": _startPoint = new Point(); distance = getMidPoint(new Point(((Line)adornedElement).X2, ((Line)adornedElement).Y2), position, out _startPoint, true); ((Line)adornedElement).X2 = position.X; ((Line)adornedElement).Y2 = position.Y; ((Ellipse)ui).Height = ((Ellipse)ui).Width = distance * 2; Canvas.SetLeft(ui, (new Thickness((_startPoint.X - ((distance * 2) / 2)), (_startPoint.Y - ((distance * 2) / 2)), 0, 0)).Left); Canvas.SetTop(ui, (new Thickness((_startPoint.X - ((distance * 2) / 2)), (_startPoint.Y - ((distance * 2) / 2)), 0, 0)).Top); break; } } } break; #endregion } }
/// <summary> /// Constructor used when a attached MwiChild is being resized. /// </summary> /// <param name="adornedElement"></param> public ResizeAdorner(UIElement adornedElement) : base(adornedElement) { if (AdornedElement.GetType().Equals(typeof(AnalysisChild))) { mMinWidth = ((AnalysisChild)AdornedElement).MinSize.Width; mMinHeight = ((AnalysisChild)AdornedElement).MinSize.Height; } }
private void OpenToolTip() { var toolTip = ToolTipService.GetToolTip(this) as ToolTip; if (toolTip == null) { return; } if (AdornedElement != null) { toolTip.PlacementTarget = AdornedElement; Debug.Print("Set placement target: {0}", AdornedElement?.GetType().Name ?? "null"); } toolTip.IsOpen = true; }
/// <summary> /// When the left mouse button is down get the current point and capture the mouse. /// </summary> /// <param name="e"></param> protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnPreviewMouseLeftButtonDown(e); if (!mIsDown && mCurrentHotSpot != HotSpot.None) { if (AdornedElement.GetType().Equals(typeof(AnalysisChild))) { ((AnalysisChild)AdornedElement).IsSelected = true; // promote the child to the front since it has been selected. } mIsDown = true; // mouse button is down mCurrentPoint = e.GetPosition(this); mLastPoint = mCurrentPoint; this.CaptureMouse(); } }
/// <summary> /// Update the height with the newheight based on the current mouse point. /// </summary> /// <param name="newheight"></param> /// <param name="p"></param> private void UpdateHeight(double newheight, Point p) { if (AdornedElement.GetType().Equals(typeof(AnalysisChild))) { mMaxHeight = ((AnalysisChild)AdornedElement).MwiParent.ActualHeight - 3 - Canvas.GetTop(AdornedElement); } // if within the min and max height then update the height to the new height if ((newheight >= mMinHeight && p.Y >= mMinHeight) && (newheight <= mMaxHeight && p.Y <= mMaxHeight)) { if (mWindow != null) { mWindow.Height = newheight; } else { AdornedElement.SetValue(AnalysisChild.HeightProperty, newheight); } } else // otherwise set the height to the min or max bound accordingly { if (mWindow != null) { if (!(newheight <= mMaxHeight && p.Y <= mMaxHeight)) { mWindow.Height = mMaxHeight; } else { mWindow.Height = mMinHeight; } } else { if (!(newheight <= mMaxHeight && p.Y <= mMaxHeight)) { AdornedElement.SetValue(AnalysisChild.HeightProperty, mMaxHeight); } else { AdornedElement.SetValue(AnalysisChild.HeightProperty, mMinHeight); } } } }
/// <summary> /// Updates the width to the newwidth provided based on the current mouse point. /// </summary> /// <param name="newwidth"></param> /// <param name="p"></param> private void UpdateWidth(double newwidth, Point p) { if (AdornedElement.GetType().Equals(typeof(AnalysisChild))) { mMaxWidth = ((AnalysisChild)AdornedElement).MwiParent.ActualWidth - 3 - Canvas.GetLeft(AdornedElement); } // if within the min and max width then update the width to the new width if ((newwidth >= mMinWidth && p.X >= mMinWidth) && (newwidth <= mMaxWidth && p.X <= mMaxWidth)) { if (mWindow != null) { mWindow.Width = newwidth; } else { AdornedElement.SetValue(AnalysisChild.WidthProperty, newwidth); } } else // otherwise set the width to the min or max bound accordingly { if (mWindow != null) { if (!(newwidth <= mMaxWidth && p.X <= mMaxWidth)) { mWindow.Width = mMaxWidth; } else { mWindow.Width = mMinWidth; } } else { if (!(newwidth <= mMaxWidth && p.X <= mMaxWidth)) { AdornedElement.SetValue(AnalysisChild.WidthProperty, mMaxWidth); } else { AdornedElement.SetValue(AnalysisChild.WidthProperty, mMinWidth); } } } }
// Arrange the Adorners. protected override Size ArrangeOverride(Size finalSize) { // desiredWidth and desiredHeight are the width and height of the element that's being adorned. // These will be used to place the ResizingAdorner at the corners of the adorned element. double desiredWidth = AdornedElement.DesiredSize.Width; double desiredHeight = AdornedElement.DesiredSize.Height; // adornerWidth & adornerHeight are used for placement as well. double adornerWidth = this.DesiredSize.Width; double adornerHeight = this.DesiredSize.Height; if (AdornedElement.GetType() == typeof(Line) && AdornedElement.Uid.Contains("DC")) { var selectedLine = AdornedElement as Line; double left = Math.Min(selectedLine.X1, selectedLine.X2); double top = Math.Min(selectedLine.Y1, selectedLine.Y2); var startRect = new Rect(selectedLine.X1 - (Left.Width / 2), selectedLine.Y1 - (Left.Width / 2), Left.Width, Left.Height); Left.Arrange(startRect); var endRect = new Rect(selectedLine.X2 - (Right.Width / 2), selectedLine.Y2 - (Right.Height / 2), Right.Width, Right.Height); Right.Arrange(endRect); } else if (AdornedElement.GetType() == typeof(Ellipse) && AdornedElement.Uid.Contains("DC")) { FrameworkElement adornedElement = AdornedElement as FrameworkElement; List <Point> elipsendPoints = ((List <Point>)(adornedElement.DataContext)); if (elipsendPoints.Count == 0) { return(finalSize); } Line selectedLine = new Line() { X1 = elipsendPoints[0].X, Y1 = elipsendPoints[0].Y, X2 = elipsendPoints[1].X, Y2 = elipsendPoints[1].Y }; double left = Math.Min(selectedLine.X1, selectedLine.X2); double top = Math.Min(selectedLine.Y1, selectedLine.Y2); var startRect = new Rect(selectedLine.X1 - (Left.Width / 2), selectedLine.Y1 - (Left.Width / 2), Left.Width, Left.Height); var endRect = new Rect(selectedLine.X2 - (Right.Width / 2), selectedLine.Y2 - (Right.Height / 2), Right.Width, Right.Height); Left.Arrange(startRect); Right.Arrange(endRect); } // Return the final size. return(finalSize); }
void onDragDeltaLeft(object sender, DragDeltaEventArgs args) { FrameworkElement adornedElement = AdornedElement as FrameworkElement; System.Windows.Controls.Primitives.Thumb hitThumb = sender as System.Windows.Controls.Primitives.Thumb; if (adornedElement == null || hitThumb == null) { return; } Point position = Mouse.GetPosition(this); double left, top, distance = 0; Point _startPoint = new Point(), l_pMidPoint = new Point(); switch (AdornedElement.GetType().ToString()) { case "System.Windows.Shapes.Line": _startPoint = new Point(((Line)adornedElement).X2, ((Line)adornedElement).Y2); l_pMidPoint = new Point(((_startPoint.X + position.X) / 2), ((_startPoint.Y + position.Y) / 2)); distance = getDistanceBetweenTwoPoints(l_pMidPoint, position); foreach (UIElement ui in _ownerPanel.Children) { if (ui.Uid == AdornedElement.Uid && ui.GetType() != AdornedElement.GetType()) { ((Ellipse)ui).Height = ((Ellipse)ui).Width = distance * 2; left = l_pMidPoint.X - ((distance * 2) / 2); top = l_pMidPoint.Y - ((distance * 2) / 2); Canvas.SetLeft(ui, (new Thickness(left, top, 0, 0)).Left); Canvas.SetTop(ui, (new Thickness(left, top, 0, 0)).Top); break; } } ((Line)adornedElement).X1 = position.X; ((Line)adornedElement).Y1 = position.Y; break; case "System.Windows.Shapes.Ellipse": foreach (UIElement ui in _ownerPanel.Children) { if (ui.Uid == AdornedElement.Uid && ui.GetType() != AdornedElement.GetType()) { ((Line)ui).X1 = position.X; ((Line)ui).Y1 = position.Y; _startPoint = new Point(((Line)ui).X1, ((Line)ui).Y1); l_pMidPoint = new Point(((_startPoint.X + position.X) / 2), ((_startPoint.Y + position.Y) / 2)); distance = getDistanceBetweenTwoPoints(l_pMidPoint, position); break; } } ((Ellipse)adornedElement).Height = ((Ellipse)adornedElement).Width = distance * 2; left = l_pMidPoint.X - ((distance * 2) / 2); top = l_pMidPoint.Y - ((distance * 2) / 2); Canvas.SetLeft(adornedElement, (new Thickness(left, top, 0, 0)).Left); Canvas.SetTop(adornedElement, (new Thickness(left, top, 0, 0)).Top); break; } }
private void Log(string format, params object[] args) { Trace.WriteLine("[" + AdornedElement.GetType().Name + "] " + string.Format(format, args)); }