public void ArrangeTree() { if (NodesFrom.Count > 0) { switch (TAnchor) { case TreeAnchor.Up: NodesFrom[0].Location = Root.Location + new Vector2(Root.Width / 2, Root.Height / 2) - new Vector2((NodesFrom.Count * NodesFrom[0].Width + 20 * (NodesFrom.Count - 1)) / 2, -44); break; case TreeAnchor.Down: NodesFrom[0].Location = Root.Location + new Vector2(Root.Width / 2, Root.Height / 2) - new Vector2((NodesFrom.Count * NodesFrom[0].Width + 20 * (NodesFrom.Count - 1)) / 2, 76); break; case TreeAnchor.Right: NodesFrom[0].Location = Root.Location + new Vector2(Root.Width / 2, Root.Height / 2) - new Vector2(76, (NodesFrom.Count * NodesFrom[0].Height + 20 * (NodesFrom.Count - 1)) / 2); break; case TreeAnchor.Left: NodesFrom[0].Location = Root.Location + new Vector2(Root.Width / 2, Root.Height / 2) - new Vector2(-44, (NodesFrom.Count * NodesFrom[0].Height + 20 * (NodesFrom.Count - 1)) / 2); break; default: break; } } if (NodesTo.Count > 0) { switch (TAnchor) { case TreeAnchor.Up: NodesTo[0].Location = Root.Location + new Vector2(Root.Width / 2, Root.Height / 2) - new Vector2((NodesTo.Count * NodesTo[0].Width + 20 * (NodesTo.Count - 1)) / 2, 76); break; case TreeAnchor.Down: NodesTo[0].Location = Root.Location + new Vector2(Root.Width / 2, Root.Height / 2) - new Vector2((NodesTo.Count * NodesTo[0].Width + 20 * (NodesTo.Count - 1)) / 2, -44); break; case TreeAnchor.Right: NodesTo[0].Location = Root.Location + new Vector2(Root.Width / 2, Root.Height / 2) - new Vector2(-44, (NodesTo.Count * NodesTo[0].Height + 20 * (NodesTo.Count - 1)) / 2); break; case TreeAnchor.Left: NodesTo[0].Location = Root.Location + new Vector2(Root.Width / 2, Root.Height / 2) - new Vector2(76, (NodesTo.Count * NodesTo[0].Height + 20 * (NodesTo.Count - 1)) / 2); break; default: break; } } for (int i = 1; i < NodesFrom.Count; i++) { var n = NodesFrom[i]; var prev = NodesFrom[i - 1]; switch (TAnchor) { case TreeAnchor.Up: case TreeAnchor.Down: n.Location = prev.Location + new Vector2(prev.Width + 20, 0); break; case TreeAnchor.Right: case TreeAnchor.Left: n.Location = prev.Location + new Vector2(0, prev.Height + 20); break; default: break; } } for (int i = 1; i < NodesTo.Count; i++) { var n = NodesTo[i]; var prev = NodesTo[i - 1]; switch (TAnchor) { case TreeAnchor.Up: case TreeAnchor.Down: n.Location = prev.Location + new Vector2(prev.Width + 20, 0); break; case TreeAnchor.Right: case TreeAnchor.Left: n.Location = prev.Location + new Vector2(0, prev.Height + 20); break; default: break; } } { //to strech int l1 = 0, l2 = 0; switch (TAnchor) { case TreeAnchor.Up: case TreeAnchor.Down: { l2 = 400; int t = Math.Max(NodesFrom.Count, NodesTo.Count); l1 = t * 32 + (t - 1) * 20 + 100; } break; case TreeAnchor.Right: case TreeAnchor.Left: { l1 = 600; int t = Math.Max(NodesFrom.Count, NodesTo.Count); l2 = t * 32 + (t - 1) * 20 + 100; } break; default: break; } { float jX1 = NodesFrom.Count > 0 ? NodesFrom.Min(u => u.Location.X) : float.MaxValue; float jY1 = NodesFrom.Count > 0 ? NodesFrom.Min(u => u.Location.Y) : float.MaxValue; float jX2 = NodesTo.Count > 0 ? NodesTo.Min(u => u.Location.X) : float.MaxValue; float jY2 = NodesTo.Count > 0 ? NodesTo.Min(u => u.Location.Y) : float.MaxValue; float jX = Math.Min(Math.Min(jX1, jX2), Root.X); float jY = Math.Min(Math.Min(jY1, jY2), Root.Y); var d = new Vector2(200, 50) - new Vector2(jX, jY); MoveTree(d); } } }
public void DrawNodeLines() { { //From foreach (var n in NodesFrom) { switch (TAnchor) { case TreeAnchor.Up: { Vector2 start = n.Location + new Vector2(n.Width / 2, 0) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 end = start - new Vector2(0, 13); DrawLine(start, end, LineColor, 2); } break; case TreeAnchor.Down: { Vector2 start = n.Location + new Vector2(n.Width / 2 + 2, n.Height) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 end = start + new Vector2(0, 13); DrawLine(start, end, LineColor, 2); } break; case TreeAnchor.Right: { Vector2 start = n.Location + new Vector2(n.Width, n.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 end = start + new Vector2(13, 0); DrawLine(start, end, LineColor, 2); } break; case TreeAnchor.Left: { Vector2 start = n.Location + new Vector2(0, n.Height / 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 end = start - new Vector2(13, 0); DrawLine(start, end, LineColor, 2); } break; default: break; } } if (NodesFrom.Count > 0) { var head = NodesFrom.First(); var tail = NodesFrom.Last(); switch (TAnchor) { case TreeAnchor.Up: { Vector2 b = head.Location + new Vector2(head.Width / 2, -15) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 e = tail.Location + new Vector2(tail.Width / 2, -15) - new Vector2(OriginToWorld.X, OriginToWorld.Y); DrawLine(b, e, LineColor, 2); Vector2 center = (b + e) / 2; Vector2 centerEnd = center - new Vector2(0, 11); DrawLine(center, centerEnd, LineColor, 2); } break; case TreeAnchor.Down: { Vector2 b = head.Location + new Vector2(head.Width / 2, head.Height + 15) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 e = tail.Location + new Vector2(tail.Width / 2, head.Height + 15) - new Vector2(OriginToWorld.X, OriginToWorld.Y); DrawLine(b, e, LineColor, 2); Vector2 center = (b + e) / 2 + new Vector2(2, 0); Vector2 centerEnd = center + new Vector2(0, 11); DrawLine(center, centerEnd, LineColor, 2); } break; case TreeAnchor.Right: { Vector2 b = head.Location + new Vector2(head.Width + 15, head.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 e = tail.Location + new Vector2(tail.Width + 15, head.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); DrawLine(b, e, LineColor, 2); Vector2 center = (b + e) / 2; Vector2 centerEnd = center + new Vector2(11, 0); DrawLine(center, centerEnd, LineColor, 2); } break; case TreeAnchor.Left: { Vector2 b = head.Location + new Vector2(-15, head.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 e = tail.Location + new Vector2(-15, head.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); DrawLine(b, e, LineColor, 2); Vector2 center = (b + e) / 2 + new Vector2(0, 2); Vector2 centerEnd = center - new Vector2(11, 0); DrawLine(center, centerEnd, LineColor, 2); } break; default: break; } } } { //To foreach (var n in NodesTo) { switch (TAnchor) { case TreeAnchor.Up: { Vector2 start = n.Location + new Vector2(n.Width / 2 + 2, n.Height) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 end = start + new Vector2(0, 13); DrawLine(start, end, LineColor, 2); } break; case TreeAnchor.Down: { Vector2 start = n.Location + new Vector2(n.Width / 2, 0) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 end = start - new Vector2(0, 13); DrawLine(start, end, LineColor, 2); } break; case TreeAnchor.Right: { Vector2 start = n.Location + new Vector2(0, n.Height / 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 end = start - new Vector2(13, 0); DrawLine(start, end, LineColor, 2); } break; case TreeAnchor.Left: { Vector2 start = n.Location + new Vector2(n.Width, n.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 end = start + new Vector2(13, 0); DrawLine(start, end, LineColor, 2); } break; default: break; } } if (NodesTo.Count > 0) { var head = NodesTo.First(); var tail = NodesTo.Last(); switch (TAnchor) { case TreeAnchor.Up: { Vector2 b = head.Location + new Vector2(head.Width / 2, head.Height + 15) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 e = tail.Location + new Vector2(tail.Width / 2, head.Height + 15) - new Vector2(OriginToWorld.X, OriginToWorld.Y); DrawLine(b, e, LineColor, 2); Vector2 center = (b + e) / 2 + new Vector2(2, 0); Vector2 centerEnd = center + new Vector2(0, 11); DrawLine(center, centerEnd, LineColor, 2); } break; case TreeAnchor.Down: { Vector2 b = head.Location + new Vector2(head.Width / 2, -15) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 e = tail.Location + new Vector2(tail.Width / 2, -15) - new Vector2(OriginToWorld.X, OriginToWorld.Y); DrawLine(b, e, LineColor, 2); Vector2 center = (b + e) / 2; Vector2 centerEnd = center - new Vector2(0, 11); DrawLine(center, centerEnd, LineColor, 2); } break; case TreeAnchor.Right: { Vector2 b = head.Location + new Vector2(-15, head.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 e = tail.Location + new Vector2(-15, head.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); DrawLine(b, e, LineColor, 2); Vector2 center = (b + e) / 2 + new Vector2(0, 2); Vector2 centerEnd = center - new Vector2(11, 0); DrawLine(center, centerEnd, LineColor, 2); } break; case TreeAnchor.Left: { Vector2 b = head.Location + new Vector2(head.Width + 15, head.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); Vector2 e = tail.Location + new Vector2(tail.Width + 15, head.Height / 2 - 2) - new Vector2(OriginToWorld.X, OriginToWorld.Y); DrawLine(b, e, LineColor, 2); Vector2 center = (b + e) / 2; Vector2 centerEnd = center + new Vector2(11, 0); DrawLine(center, centerEnd, LineColor, 2); } break; default: break; } } } }