private void Collapse(GraphExplorer.GraphNode node) { foreach (var childNode in node.ChildNodes) { childNode.ParentNodes.Remove(node); } node.ChildNodes.Clear(); graph.Invalidate(); }
private void graph_NodeDoubleClick(object sender, GraphExplorer.GraphNode node) { if (node.ChildNodes.Count > 0) { Collapse(node); } else { Expand(node); } }
private void Expand(GraphExplorer.GraphNode n) { MethodBase mb = (MethodBase)n.Tag; var memberCache = (MethodBaseCache)AnalysisManager.Instance.GetMemberCache(mb); foreach (var call in memberCache.Uses.Select(entry => entry.Member).Where(m => m is MethodBase)) { if (!chkOnlySameAssembly.Checked || call.DeclaringType.Assembly == ((MethodBase)graph.RootNode.Tag).DeclaringType.Assembly) { //expand GraphExplorer.GraphNode child; child = new GraphExplorer.GraphNode() { Tag = call }; n.ChildNodes.Add(child); child.ParentNodes.Add(n); } } }
public CallGraph(IAssemblyBrowser browser, MethodBase mb) { this.browser = browser; InitializeComponent(); imgs.Images.AddRange(IconHelper.GetIcons().ToArray()); graph.Orientation = Orientation.Vertical; graph.NodePaintHandler = PaintNode; GraphExplorer.GraphNode n = new GraphExplorer.GraphNode() { Tag = mb }; graph.RootNode = n; graph.SelectedNode = n; graph_SelectionChanged(graph, EventArgs.Empty); graph.Invalidate(); }
private void PaintNode(GraphExplorer.GraphNode node, PaintEventArgs e, RectangleF bounds) { Graphics g = e.Graphics; RectangleF zoomedBounds = bounds; zoomedBounds.X *= graph.Zoom; zoomedBounds.Y *= graph.Zoom; zoomedBounds.Width *= graph.Zoom; zoomedBounds.Height *= graph.Zoom; if (zoomedBounds.IntersectsWith(e.ClipRectangle)) { Color fillColor; if (graph.SelectedNode == node) { fillColor = Color.Gold; } else { fillColor = Color.SkyBlue; } GraphicsPath roundedRect = GetRoundedRect(bounds, 5, 5); using (LinearGradientBrush brush = new LinearGradientBrush(bounds, fillColor, Color.White, LinearGradientMode.Vertical)) g.FillPath(brush, roundedRect); using (Pen p = new Pen(Color.Black)) g.DrawPath(p, roundedRect); if (node.Tag != null) { if (bounds.Width > 0 && bounds.Height > 0) { bounds.Inflate(-3, -3); MethodBase mb = (MethodBase)node.Tag; try { var typeIcon = imgs.Images[IconHelper.GetIcon(mb.DeclaringType)]; var mbIcon = imgs.Images[IconHelper.GetIcon(mb)]; var typeStringBounds = new RectangleF(bounds.Left + 20, bounds.Top, bounds.Width, bounds.Height / 2); var methodStringBounds = new RectangleF(bounds.Left + 20, bounds.Top + bounds.Height / 2, bounds.Width, bounds.Height / 2); g.DrawImage(typeIcon, new PointF(bounds.Left, bounds.Top + (typeStringBounds.Height / 2 - typeIcon.Height / 2))); using (StringFormat sf = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center }) g.DrawString(mb.DeclaringType.ToSignatureString(true), Font, Brushes.Black, typeStringBounds, sf); g.DrawImage(mbIcon, new PointF(bounds.Left, bounds.Top + bounds.Height / 2 + (methodStringBounds.Height / 2 - mbIcon.Height / 2))); using (StringFormat sf = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center }) g.DrawString(mb.ToSignatureString(), Font, Brushes.Black, methodStringBounds, sf); } catch (Exception) { } } } } }