示例#1
0
    /// <summary>
    /// Draws the diagram using GDI+, centering and scaling within the specified bounds.
    /// </summary>
    /// <param name="graphics">GDI+ Graphics surface.</param>
    /// <param name="bounds">Bounds in which to draw the diagram.</param>
    public void Draw(GraphicsContext graphics, Rectangle bounds)
    {
        Point center = new Point(bounds.X + (bounds.Width / 2), bounds.Y + (bounds.Height / 2));

        // determine the scaling factor
        Rectangle logicalBounds = GetDiagramBounds();
        double scale = 1;
        if (logicalBounds.Width > logicalBounds.Height)
        {
            if (logicalBounds.Width != 0)
                scale = (double)Math.Min(bounds.Width, bounds.Height) / (double)logicalBounds.Width;
        }
        else
        {
            if (logicalBounds.Height != 0)
                scale = (double)Math.Min(bounds.Width, bounds.Height) / (double)logicalBounds.Height;
        }

        // draw all of the connectors first
        foreach (Node node in mNodes)
        {
            Point source = ScalePoint(node.Location, scale);

            // connectors
            foreach (Node other in node.Connections)
            {
                Point destination = ScalePoint(other.Location, scale);
                node.DrawConnector(graphics, new Point(center.X + source.X, center.Y + source.Y), new Point(center.X + destination.X, center.Y + destination.Y), other);
            }
        }

        // then draw all of the nodes
        foreach (Node node in mNodes)
        {
            Point destination = ScalePoint(node.Location, scale);

            System.Windows.Size nodeSize = node.Size;
            Rectangle nodeBounds = new Rectangle((int)(center.X + destination.X - (nodeSize.Width / 2)),
                                                 (int)(center.Y + destination.Y - (nodeSize.Height / 2)),
                                                 (int)nodeSize.Width,
                                                 (int)nodeSize.Height);
            node.DrawNode(graphics, nodeBounds);
        }
    }
示例#2
0
 /// <summary>
 /// Draws the node using GDI+, within the specified bounds.
 /// </summary>
 /// <param name="graphics">GDI+ Graphics surface.</param>
 /// <param name="bounds">The bounds in which to draw the node.</param>
 public abstract void DrawNode(GraphicsContext graphics, Rectangle bounds);
示例#3
0
 /// <summary>
 /// Draws the node using GDI+.
 /// </summary>
 /// <param name="graphics">GDI+ Graphics surface.</param>
 /// <param name="bounds">The bounds in which to draw the node.</param>
 public override void DrawNode(GraphicsContext graphics, Rectangle bounds)
 {
     graphics.PrimitiveBatch
 }
示例#4
0
 /// <summary>
 /// Draws a connector between this node and the specified child node using GDI+. 
 /// The source and destination coordinates (relative to the Graphics surface) are also specified.
 /// </summary>
 /// <param name="graphics">GDI+ Graphics surface.</param>
 /// <param name="from">Source coodinate.</param>
 /// <param name="to">Destination coordinate.</param>
 /// <param name="other">The other node.</param>
 public virtual void DrawConnector(GraphicsContext graphics, Microsoft.Xna.Framework.Point from, Microsoft.Xna.Framework.Point to, Node other)
 {
     graphics.PrimitiveBatch.AddVertex(new Vector2(from.X, from.Y), Color.White);
     graphics.PrimitiveBatch.AddVertex(new Vector2(to.X, to.Y), Color.White);
 }