//************************************************************************* // 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_oBackColor = SystemColors.WindowColor; // Forward the events fired by the vertex and edge drawers. m_oVertexDrawer.RedrawRequired += delegate { this.FireRedrawRequired(); }; m_oVertexDrawer.LayoutRequired += delegate { this.FireLayoutRequired(); }; m_oEdgeDrawer.RedrawRequired += delegate { this.FireRedrawRequired(); }; m_oEdgeDrawer.LayoutRequired += delegate { this.FireLayoutRequired(); }; AssertValid(); }
//************************************************************************* // Method: CreateVisual() // /// <summary> /// Creates the Visual that should be used to represent the dragged /// vertices. /// </summary> /// /// <param name="currentMouseLocation"> /// The current mouse location. /// </param> /// /// <param name="backColor"> /// The graph's background color. /// </param> /// /// <param name="vertexDrawer"> /// The VertexDrawer that should be used to draw the dragged vertices. /// </param> /// /// <returns> /// The Visual that should be used to represent the dragged vertices. /// </returns> /// /// <remarks> /// The returned Visual can be retrieved later via the <see /// cref="MouseDragWithVisual.Visual" /> property. /// </remarks> //************************************************************************* public Visual 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); }