public void Draw(Color color) { Debug.DrawLine(Start, End, color); if (LeftChild != null) { LeftChild.Draw(); } if (RightChild != null) { RightChild.Draw(); } }
public Image Draw(out int center) { center = _lastImageLocationOfStarterNode; if (!IsChanged) // if the current node and it's childs are up to date, just return the last drawed image. { return(_lastImage); } var lCenter = 0; var rCenter = 0; Image lNodeImg = null, rNodeImg = null; if (LeftChild != null) // draw left node's image { lNodeImg = LeftChild.Draw(out lCenter); } if (RightChild != null) // draw right node's image { rNodeImg = RightChild.Draw(out rCenter); } // draw current node and it's childs (left node image and right node image) var lSize = new Size(); var rSize = new Size(); var under = (lNodeImg != null) || (rNodeImg != null);// if true the current node has childs if (lNodeImg != null) { lSize = lNodeImg.Size; } if (rNodeImg != null) { rSize = rNodeImg.Size; } var maxHeight = lSize.Height; if (maxHeight < rSize.Height) { maxHeight = rSize.Height; } if (lSize.Width <= 0) { lSize.Width = (_nodeBg.Width - _freeSpace.Width) / 2; } if (rSize.Width <= 0) { rSize.Width = (_nodeBg.Width - _freeSpace.Width) / 2; } var resSize = new Size { Width = lSize.Width + rSize.Width + _freeSpace.Width, Height = _nodeBg.Size.Height + (under ? maxHeight + _freeSpace.Height : 0) }; var result = new Bitmap(resSize.Width, resSize.Height); var g = Graphics.FromImage(result); g.SmoothingMode = SmoothingMode.HighQuality; g.FillRectangle(Brushes.White, new Rectangle(new Point(0, 0), resSize)); g.DrawImage(_nodeBg, lSize.Width - _nodeBg.Width / 2 + _freeSpace.Width / 2, 0); var str = Value.ToString(); g.DrawString(str, font, Brushes.Black, lSize.Width - _nodeBg.Width / 2 + _freeSpace.Width / 2 + (2 + (str.Length == 1 ? 10 : str.Length == 2 ? 5 : 0)) * Coef, _nodeBg.Height / 2f - 12 * Coef); center = lSize.Width + _freeSpace.Width / 2; var pen = new Pen(Brushes.Black, 1.2f * Coef) { EndCap = LineCap.ArrowAnchor, StartCap = LineCap.Round }; float x1 = center; float y1 = _nodeBg.Height; float y2 = _nodeBg.Height + _freeSpace.Height; float x2 = lCenter; var h = Math.Abs(y2 - y1); var w = Math.Abs(x2 - x1); if (lNodeImg != null) { g.DrawImage(lNodeImg, 0, _nodeBg.Size.Height + _freeSpace.Height); var points1 = new List <PointF> { new PointF(x1, y1), new PointF(x1 - w / 6, y1 + h / 3.5f), new PointF(x2 + w / 6, y2 - h / 3.5f), new PointF(x2, y2), }; g.DrawCurve(pen, points1.ToArray(), 0.5f); } if (rNodeImg != null) { g.DrawImage(rNodeImg, lSize.Width + _freeSpace.Width, _nodeBg.Size.Height + _freeSpace.Height); x2 = rCenter + lSize.Width + _freeSpace.Width; w = Math.Abs(x2 - x1); var points = new List <PointF> { new PointF(x1, y1), new PointF(x1 + w / 6, y1 + h / 3.5f), new PointF(x2 - w / 6, y2 - h / 3.5f), new PointF(x2, y2) }; g.DrawCurve(pen, points.ToArray(), 0.5f); } IsChanged = false; _lastImage = result; _lastImageLocationOfStarterNode = center; return(result); }