/// <summary> /// Update the width to the newwidth and the left location to newleft. /// </summary> /// <param name="newwidth"></param> /// <param name="newleft"></param> private void UpdateWidth(double newwidth, double newleft) { // if within the min width and a location greater than or equal to zero then update the width and the left location if ((newwidth >= mMinWidth) && (newleft >= 0)) { if (mWindow != null) { mWindow.SetValue(Window.WidthProperty, newwidth); mWindow.SetValue(Window.LeftProperty, newleft); } else { Canvas.SetLeft(AdornedElement, newleft); AdornedElement.SetValue(AnalysisChild.WidthProperty, newwidth); } } else // otherwise set the width the the min or max bound accordingly { if (mWindow != null) { double width = mWindow.Width; double left = mWindow.Left; if (!(newleft >= 0)) { mWindow.Left = 0; mWindow.Width = left + width; } else { mWindow.Left += (mWindow.Width - mMinWidth); mWindow.Width = mMinWidth; } } else { double width = (double)AdornedElement.GetValue(WidthProperty); double left = Canvas.GetLeft(AdornedElement); if (!(newleft >= 0)) { Canvas.SetLeft(AdornedElement, 0); AdornedElement.SetValue(AnalysisChild.WidthProperty, left + width); } else { Canvas.SetLeft(AdornedElement, left + (width - mMinWidth)); AdornedElement.SetValue(AnalysisChild.WidthProperty, mMinWidth); } } } }
/// <summary> /// Update the height to the newheight and the top location to newtop. /// </summary> /// <param name="newwidth"></param> /// <param name="newleft"></param> private void UpdateHeight(double newheight, double newtop) { // if within the min height and a location greater than or equal to zero then update the height and the top location if ((newheight >= mMinHeight) && (newtop >= 0)) { if (mWindow != null) { mWindow.Height = newheight; mWindow.Top = newtop; } else { Canvas.SetTop(AdornedElement, newtop); AdornedElement.SetValue(AnalysisChild.HeightProperty, newheight); } } else // otherwise set the height the the min or max bound accordingly { if (mWindow != null) { double height = mWindow.Height; double top = mWindow.Top; if (!(newtop >= 0)) { mWindow.Top = 0; mWindow.Height = top + height; } else { mWindow.Top += mWindow.Height - mMinHeight; mWindow.Height = mMinHeight; } } else { double height = (double)AdornedElement.GetValue(HeightProperty); double top = Canvas.GetTop(AdornedElement); if (!(newtop >= 0)) { Canvas.SetTop(AdornedElement, 0); AdornedElement.SetValue(AnalysisChild.HeightProperty, top + height); } else { Canvas.SetTop(AdornedElement, top + (height - mMinHeight)); AdornedElement.SetValue(AnalysisChild.HeightProperty, mMinHeight); } } } }
/// <summary> /// Update the size and location of the object based on the hotspot that is selected. /// </summary> /// <param name="hspot"></param> /// <param name="p"></param> private void UpdateSize(HotSpot hspot, Point p) { double width = (double)AdornedElement.GetValue(WidthProperty); double height = (double)AdornedElement.GetValue(HeightProperty); double left = Canvas.GetLeft(AdornedElement); double top = Canvas.GetTop(AdornedElement); if (mWindow != null) { width = mWindow.Width; height = mWindow.Height; left = mWindow.Left; top = mWindow.Top; } switch (hspot) { case HotSpot.TopLeft1: case HotSpot.TopLeft2: UpdateWidth(width + (mCurrentPoint.X - p.X), left + (p.X - mCurrentPoint.X)); UpdateHeight(height + (mCurrentPoint.Y - p.Y), top + (p.Y - mCurrentPoint.Y)); break; case HotSpot.Top: UpdateHeight(height + (mCurrentPoint.Y - p.Y), top + (p.Y - mCurrentPoint.Y)); break; case HotSpot.TopRight1: case HotSpot.TopRight2: UpdateWidth(width - (mLastPoint.X - p.X), p); UpdateHeight(height + (mCurrentPoint.Y - p.Y), top + (p.Y - mCurrentPoint.Y)); mLastPoint = p; break; case HotSpot.Right: UpdateWidth(width - (mLastPoint.X - p.X), p); mLastPoint = p; break; case HotSpot.BottomRight1: case HotSpot.BottomRight2: UpdateWidth(width - (mLastPoint.X - p.X), p); UpdateHeight(height - (mLastPoint.Y - p.Y), p); mLastPoint = p; break; case HotSpot.Bottom: UpdateHeight(height - (mLastPoint.Y - p.Y), p); mLastPoint = p; break; case HotSpot.BottomLeft1: case HotSpot.BottomLeft2: UpdateWidth(width + (mCurrentPoint.X - p.X), left + (p.X - mCurrentPoint.X)); UpdateHeight(height - (mLastPoint.Y - p.Y), p); mLastPoint = p; break; case HotSpot.Left: UpdateWidth(width + (mCurrentPoint.X - p.X), left + (p.X - mCurrentPoint.X)); break; default: break; } }