/// <summary> /// Computes the position of the arrow texts, following the arrow, to avoid text overlap /// </summary> protected virtual void ComputeArrowTextPosition() { BoxAllocation allocatedBoxes = new BoxAllocation(); // Allocate all boxes as non available foreach (BoxControl <TEnclosing, TBoxModel, TArrowModel> box in _boxes.Values) { Rectangle rectangle = box.Rectangle; allocatedBoxes.Allocate(rectangle); } foreach (ArrowControl <TEnclosing, TBoxModel, TArrowModel> arrow in _arrows.Values) { Point center = arrow.GetCenter(); Point upSlide = Slide(allocatedBoxes, arrow, SlideDirection.Up); Point downSlide = Slide(allocatedBoxes, arrow, SlideDirection.Down); Rectangle boundingBox; if (Distance(center, upSlide) <= Distance(center, downSlide)) { boundingBox = arrow.GetTextBoundingBox(upSlide); } else { boundingBox = arrow.GetTextBoundingBox(downSlide); } arrow.Location = new Point(boundingBox.X, boundingBox.Y); allocatedBoxes.Allocate(boundingBox); } }
/// <summary> /// Tries to slide the arrow up following the arrow to avoid any collision /// with the already allocated bounding boxes /// </summary> /// <param name="allocatedBoxes">The boxes that already have been allocated</param> /// <param name="arrow">The arrow to consider</param> /// <param name="direction">Indicates whether the sliding should be done upward or downard the arrow orientation</param> /// <returns></returns> private Point Slide(BoxAllocation allocatedBoxes, ArrowControl <TEnclosing, TBoxModel, TArrowModel> arrow, SlideDirection direction) { Point retVal = arrow.GetCenter(); Rectangle colliding = allocatedBoxes.Intersects(arrow.GetTextBoundingBox(retVal)); while (colliding != Rectangle.Empty) { retVal = arrow.Slide(retVal, colliding, direction); colliding = allocatedBoxes.Intersects(arrow.GetTextBoundingBox(retVal)); } return(retVal); }
/// <summary> /// Computes the position of the transition texts, following the transition arrow, to avoid text overlap /// </summary> private void ComputeTransitionTextPosition() { AllocatedBoxes = new BoxAllocation(); foreach (TransitionControl transition in transitions.Values) { Point center = transition.getCenter(); Point upSlide = Slide(transition, center, TransitionControl.SlideDirection.Up); Point downSlide = Slide(transition, center, TransitionControl.SlideDirection.Down); Rectangle boundingBox; if (distance(center, upSlide) <= distance(center, downSlide)) { boundingBox = transition.getTextBoundingBox(upSlide); } else { boundingBox = transition.getTextBoundingBox(downSlide); } transition.Location = new Point(boundingBox.X, boundingBox.Y); AllocatedBoxes.Allocate(boundingBox); } }