Beispiel #1
0
 private Rect AdjustPosition(AnchorPanel.ArrangeGrid arrangeGrid, AnchoredElement anchoredElement, Rect position)
 {
     if (!this.CollisionDetectionEnabled || !AnchorPanel.GetRepositionOverlapped(anchoredElement.UIElement) || !AnchorPanel.CheckPositionForCollision(arrangeGrid, anchoredElement, position))
         return position;
     Rect rect;
     if (anchoredElement.ContentPosition == ContentPositions.InsideEnd || anchoredElement.ContentPosition == ContentPositions.InsideCenter || (anchoredElement.ContentPosition == ContentPositions.InsideBase || anchoredElement.ContentPosition == ContentPositions.OutsideBase) || anchoredElement.ContentPosition == ContentPositions.OutsideEnd)
     {
         rect = this.AdjustAnchorRectPosition(arrangeGrid, anchoredElement, position);
         if (rect == position)
             rect = this.AdjustAnchoredPosition(arrangeGrid, anchoredElement, position);
     }
     else
     {
         rect = this.AdjustAnchoredPosition(arrangeGrid, anchoredElement, position);
         if (rect == position)
             rect = this.AdjustAnchorRectPosition(arrangeGrid, anchoredElement, position);
     }
     bool hideOverlapped = AnchorPanel.GetHideOverlapped(anchoredElement.UIElement);
     if (rect == position && hideOverlapped)
         rect = new Rect(double.MinValue, double.MinValue, 0.0, 0.0);
     return rect;
 }
Beispiel #2
0
 private void ArrangeChildren(Size arrangeSize)
 {
     AnchorPanel.ArrangeGrid arrangeGrid = new AnchorPanel.ArrangeGrid(arrangeSize, Enumerable.OfType<UIElement>((IEnumerable)this.Children));
     foreach (UIElement element in this.Children)
     {
         Rect rect = Rect.Empty;
         if (element.Visibility == Visibility.Visible)
         {
             if (!this.ShouldArrange(element))
             {
                 ILabelControl labelControl = element as ILabelControl;
                 if (labelControl != null)
                     labelControl.CalloutGeometry = (Geometry)null;
             }
             else
             {
                 AnchoredElement anchoredElement = new AnchoredElement(element, arrangeSize);
                 rect = AnchorPanel.CalculateContentPosition(anchoredElement);
                 rect = this.AdjustPosition(arrangeGrid, anchoredElement, rect);
                 ILabelControl labelControl = element as ILabelControl;
                 if (labelControl != null)
                 {
                     if (anchoredElement.Offset > anchoredElement.AnchorMargin && anchoredElement.ContentPosition != ContentPositions.InsideBase && (anchoredElement.ContentPosition != ContentPositions.InsideCenter && anchoredElement.ContentPosition != ContentPositions.InsideEnd) || (anchoredElement.ContentPosition == ContentPositions.BottomLeft || anchoredElement.ContentPosition == ContentPositions.BottomRight || (anchoredElement.ContentPosition == ContentPositions.TopLeft || anchoredElement.ContentPosition == ContentPositions.TopRight)))
                     {
                         Point calloutPoint = AnchorPanel.GetCalloutPoint(rect, anchoredElement.ContentPosition, anchoredElement.AnchorRectOrientation);
                         labelControl.UpdateCalloutGeometry(new Point(calloutPoint.X - rect.X, calloutPoint.Y - rect.Y), new Point(anchoredElement.AnchorPoint.X - rect.X, anchoredElement.AnchorPoint.Y - rect.Y));
                     }
                     else
                         labelControl.CalloutGeometry = (Geometry)null;
                 }
                 arrangeGrid.Add(element, rect);
                 if (ValueHelper.CanGraph(rect.Left) && ValueHelper.CanGraph(rect.Right) && (ValueHelper.CanGraph(rect.Width) && ValueHelper.CanGraph(rect.Height)))
                     element.Arrange(rect);
             }
         }
     }
 }
Beispiel #3
0
 private Rect AdjustAnchorRectPosition(AnchorPanel.ArrangeGrid arrangeGrid, AnchoredElement anchoredElement, Rect position)
 {
     if (!anchoredElement.AnchorRect.IsEmpty && ValueHelper.CanGraph(anchoredElement.AnchorRect.X) && (ValueHelper.CanGraph(anchoredElement.AnchorRect.Y) && ValueHelper.CanGraph(anchoredElement.AnchorRect.Right)) && ValueHelper.CanGraph(anchoredElement.AnchorRect.Left))
     {
         ContentPositions[] contentPositionsArray;
         switch (anchoredElement.ContentPosition)
         {
             case ContentPositions.InsideEnd:
                 contentPositionsArray = new ContentPositions[5]
                 {
       ContentPositions.InsideEnd,
       ContentPositions.InsideCenter,
       ContentPositions.InsideBase,
       ContentPositions.OutsideEnd,
       ContentPositions.OutsideBase
                 };
                 break;
             case ContentPositions.OutsideBase:
                 contentPositionsArray = new ContentPositions[5]
                 {
       ContentPositions.OutsideBase,
       ContentPositions.InsideBase,
       ContentPositions.InsideCenter,
       ContentPositions.InsideEnd,
       ContentPositions.OutsideEnd
                 };
                 break;
             case ContentPositions.OutsideEnd:
                 contentPositionsArray = new ContentPositions[5]
                 {
       ContentPositions.OutsideEnd,
       ContentPositions.InsideEnd,
       ContentPositions.InsideCenter,
       ContentPositions.InsideBase,
       ContentPositions.OutsideBase
                 };
                 break;
             case ContentPositions.InsideCenter:
                 contentPositionsArray = new ContentPositions[5]
                 {
       ContentPositions.InsideCenter,
       ContentPositions.InsideEnd,
       ContentPositions.InsideBase,
       ContentPositions.OutsideEnd,
       ContentPositions.OutsideBase
                 };
                 break;
             case ContentPositions.InsideBase:
                 contentPositionsArray = new ContentPositions[5]
                 {
       ContentPositions.InsideBase,
       ContentPositions.InsideCenter,
       ContentPositions.InsideEnd,
       ContentPositions.OutsideBase,
       ContentPositions.OutsideEnd
                 };
                 break;
             default:
                 contentPositionsArray = new ContentPositions[6]
                 {
       anchoredElement.ContentPosition,
       ContentPositions.TopCenter,
       ContentPositions.BottomCenter,
       ContentPositions.MiddleRight,
       ContentPositions.MiddleLeft,
       ContentPositions.MiddleCenter
                 };
                 break;
         }
         if (contentPositionsArray != null)
         {
             Size desiredSize = AnchorPanel.GetDesiredSize(anchoredElement.UIElement);
             for (int index = 0; index < contentPositionsArray.Length; ++index)
             {
                 if ((anchoredElement.ValidContentPositions & contentPositionsArray[index]) == contentPositionsArray[index])
                 {
                     double val1 = anchoredElement.MaximumMovingDistance;
                     double num1 = Math.Max(anchoredElement.MinimumMovingDistance, anchoredElement.AnchorMargin);
                     bool flag = false;
                     switch (contentPositionsArray[index])
                     {
                         case ContentPositions.InsideCenter:
                             num1 = anchoredElement.MinimumMovingDistance;
                             flag = true;
                             val1 = anchoredElement.AnchorRectOrientation == RectOrientation.LeftRight || anchoredElement.AnchorRectOrientation == RectOrientation.RightLeft ? (anchoredElement.AnchorRect.Width - desiredSize.Width) / 2.0 : (anchoredElement.AnchorRect.Height - AnchorPanel.GetDesiredSize(anchoredElement.UIElement).Height) / 2.0;
                             break;
                         case ContentPositions.InsideBase:
                         case ContentPositions.InsideEnd:
                             val1 = anchoredElement.AnchorRectOrientation == RectOrientation.LeftRight || anchoredElement.AnchorRectOrientation == RectOrientation.RightLeft ? anchoredElement.AnchorRect.Width - AnchorPanel.GetDesiredSize(anchoredElement.UIElement).Width : anchoredElement.AnchorRect.Height - AnchorPanel.GetDesiredSize(anchoredElement.UIElement).Height;
                             break;
                     }
                     double num2 = Math.Min(val1, anchoredElement.MaximumMovingDistance);
                     double offset = num1;
                     while (DoubleHelper.LessOrEqualWithPrecision(offset, num2))
                     {
                         Rect position1 = AnchorPanel.CalculateContentPosition(anchoredElement, contentPositionsArray[index], desiredSize, offset);
                         if (!AnchorPanel.CheckPositionForCollision(arrangeGrid, anchoredElement, position1))
                         {
                             anchoredElement.Offset = offset;
                             anchoredElement.ContentPosition = contentPositionsArray[index];
                             return position1;
                         }
                         if (flag)
                         {
                             Rect position2 = AnchorPanel.CalculateContentPosition(anchoredElement, contentPositionsArray[index], desiredSize, -offset);
                             if (!AnchorPanel.CheckPositionForCollision(arrangeGrid, anchoredElement, position2))
                             {
                                 anchoredElement.Offset = offset;
                                 anchoredElement.ContentPosition = contentPositionsArray[index];
                                 return position2;
                             }
                         }
                         offset += this.MovingStep;
                     }
                 }
             }
         }
     }
     return position;
 }
Beispiel #4
0
 private Rect AdjustAnchoredPosition(AnchorPanel.ArrangeGrid arrangeGrid, AnchoredElement anchoredElement, Rect position)
 {
     if (ValueHelper.CanGraph(anchoredElement.AnchorPoint.X) && ValueHelper.CanGraph(anchoredElement.AnchorPoint.Y))
     {
         ContentPositions[] contentPositionsArray = new ContentPositions[9]
         {
       ContentPositions.BottomCenter,
       ContentPositions.TopCenter,
       ContentPositions.MiddleRight,
       ContentPositions.MiddleLeft,
       ContentPositions.BottomRight,
       ContentPositions.BottomLeft,
       ContentPositions.TopRight,
       ContentPositions.TopLeft,
       ContentPositions.MiddleCenter
         };
         Size desiredSize = AnchorPanel.GetDesiredSize(anchoredElement.UIElement);
         double offset = Math.Max(anchoredElement.MinimumMovingDistance, anchoredElement.AnchorMargin);
         while (DoubleHelper.LessOrEqualWithPrecision(offset, anchoredElement.MaximumMovingDistance))
         {
             for (int index = 0; index < contentPositionsArray.Length; ++index)
             {
                 if ((contentPositionsArray[index] != ContentPositions.MiddleCenter || offset == anchoredElement.MinimumMovingDistance) && (anchoredElement.ValidContentPositions & contentPositionsArray[index]) == contentPositionsArray[index])
                 {
                     Rect position1 = AnchorPanel.CalculateContentPosition(anchoredElement, contentPositionsArray[index], desiredSize, offset);
                     if (!AnchorPanel.CheckPositionForCollision(arrangeGrid, anchoredElement, position1))
                     {
                         anchoredElement.Offset = offset;
                         anchoredElement.ContentPosition = contentPositionsArray[index];
                         return position1;
                     }
                 }
             }
             offset += this.MovingStep;
         }
     }
     return position;
 }
Beispiel #5
0
 private static bool CheckPositionForCollision(AnchorPanel.ArrangeGrid arrangeGrid, AnchoredElement anchoredElement, Rect position)
 {
     if (arrangeGrid.HasConflict(position))
         return true;
     Rect rect = RectExtensions.Expand(new Rect(new Point(0.0, 0.0), anchoredElement.ArrangeSize), 5.0, 3.0);
     switch (anchoredElement.OutsidePlacement)
     {
         case OutsidePlacement.Disallowed:
             rect.Intersect(position);
             if (!DoubleHelper.LessWithPrecision(rect.Width, position.Width))
                 return DoubleHelper.LessWithPrecision(rect.Height, position.Height);
             return true;
         case OutsidePlacement.Partial:
             rect.Intersect(position);
             if (!DoubleHelper.LessWithPrecision(rect.Width, position.Width / 2.0))
                 return DoubleHelper.LessWithPrecision(rect.Height, position.Height / 2.0);
             return true;
         default:
             return false;
     }
 }
Beispiel #6
0
 private static Rect CalculateContentPosition(AnchoredElement anchoredElement, ContentPositions contentPosition, Size contentSize, double offset)
 {
     if (contentPosition == ContentPositions.InsideEnd || contentPosition == ContentPositions.InsideCenter || (contentPosition == ContentPositions.InsideBase || contentPosition == ContentPositions.OutsideBase) || contentPosition == ContentPositions.OutsideEnd)
         return AnchorPanel.CalculateContentPosition(anchoredElement.AnchorRect, anchoredElement.AnchorRectOrientation, contentPosition, contentSize, offset);
     return AnchorPanel.CalculateContentPosition(anchoredElement.AnchorPoint, contentPosition, contentSize, offset);
 }
Beispiel #7
0
 private static Rect CalculateContentPosition(AnchoredElement anchoredElement)
 {
     return AnchorPanel.CalculateContentPosition(anchoredElement, anchoredElement.ContentPosition, AnchorPanel.GetDesiredSize(anchoredElement.UIElement), anchoredElement.AnchorMargin);
 }