//************************************************************************* // Constructor: GraphDrawer() // /// <summary> /// Initializes a new instance of the <see cref="GraphDrawer" /> class. /// </summary> /// /// <param name="parentVisual"> /// The parent of the contained <see /// cref="GraphDrawer.VisualCollection" />. This is usually a /// FrameworkElement that is hosting the collection. /// </param> //************************************************************************* public GraphDrawer ( Visual parentVisual ) { Debug.Assert(parentVisual != null); m_oVisualCollection = new VisualCollection(parentVisual); m_oAllVertexDrawingVisuals = null; m_oUnselectedEdgeDrawingVisuals = null; m_oSelectedEdgeDrawingVisuals = null; m_oVertexDrawer = new VertexDrawer(); m_oEdgeDrawer = new EdgeDrawer(); m_oGroupDrawer = new GroupDrawer(); m_oBackColor = SystemColors.WindowColor; m_oBackgroundImage = null; AssertValid(); }
CreateVisual ( Point currentMouseLocation, Color backColor, VertexDrawer vertexDrawer ) { Debug.Assert(vertexDrawer != null); Debug.Assert(m_bDragIsInProgress); AssertValid(); // This method redraws the dragged vertices at an offset location, and // adds the resulting Visuals to a ContainerVisual. // // Figure out the offset. Double dOffsetX = currentMouseLocation.X - m_oMouseDownLocation.X; Double dOffsetY = currentMouseLocation.Y - m_oMouseDownLocation.Y; GraphDrawingContext oGraphDrawingContext = new GraphDrawingContext( m_oGraphRectangle, m_iMargin, backColor); ContainerVisual oContainerVisual = new ContainerVisual(); foreach (IVertex oVertex in m_aoVertices) { System.Drawing.PointF oOriginalLocation = GetOriginalVertexLocation(oVertex); oVertex.Location = new System.Drawing.PointF( oOriginalLocation.X + (Single)dOffsetX, oOriginalLocation.Y + (Single)dOffsetY ); VertexDrawingHistory oVertexDrawingHistory; if ( vertexDrawer.TryDrawVertex(oVertex, oGraphDrawingContext, out oVertexDrawingHistory) ) { oContainerVisual.Children.Add( oVertexDrawingHistory.DrawingVisual); } } m_oVisual = oContainerVisual; return (m_oVisual); }