public void Draw( EdgeLayout layoutState ) { var styleState = myPresentation.GetPropertySetFor<EdgeStyle>().Get( Owner.Id ); var stream = new StreamGeometry(); var context = stream.Open(); context.BeginFigure( layoutState.Points.First(), false, false ); context.PolyBezierTo( layoutState.Points.Skip( 1 ).ToList(), true, false ); // draw arrow head var start = layoutState.Points.Last(); var v = start - layoutState.Points.ElementAt( layoutState.Points.Count() - 2 ); v.Normalize(); start = start - v * 0.15; context.BeginFigure( start + v * 0.28, true, true ); double t = v.X; v.X = v.Y; v.Y = -t; // Rotate 90° context.LineTo( start + v * 0.08, true, true ); context.LineTo( start + v * -0.08, true, true ); context.Close(); var pen = new Pen( styleState.Color, 0.016 ); // http://stackoverflow.com/questions/1755520/improve-drawingvisual-renders-speed Visual = new DrawingVisual(); var dc = Visual.RenderOpen(); dc.DrawGeometry( pen.Brush, pen, stream ); dc.Close(); Visual.SetValue( GraphItemProperty, Owner ); }
public void Draw( EdgeLayout layoutState ) { var styleState = myPresentation.GetPropertySetFor<EdgeStyle>().Get( Owner.Id ); var label = myPresentation.GetPropertySetFor<Caption>().Get( Owner.Id ); var stream = new StreamGeometry(); var context = stream.Open(); context.BeginFigure( layoutState.Points.First(), false, false ); context.PolyBezierTo( layoutState.Points.Skip( 1 ).ToList(), true, false ); // draw arrow head var start = layoutState.Points.Last(); var v = start - layoutState.Points.ElementAt( layoutState.Points.Count() - 2 ); v.Normalize(); start = start - v * 0.15; context.BeginFigure( start + v * 0.28, true, true ); double t = v.X; v.X = v.Y; v.Y = -t; // Rotate 90° context.LineTo( start + v * 0.08, true, true ); context.LineTo( start + v * -0.08, true, true ); context.Close(); var pen = new Pen( styleState.Color, 0.016 ); // http://stackoverflow.com/questions/1755520/improve-drawingvisual-renders-speed Visual = new DrawingVisual(); var dc = Visual.RenderOpen(); dc.DrawGeometry( pen.Brush, pen, stream ); if( label.DisplayText != label.OwnerId ) { var sourceLayoutState = myPresentation.GetModule<IGraphLayoutModule>().GetLayout( Owner.Source ); var tx = new FormattedText( label.DisplayText, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, myFont, sourceLayoutState.Height * 0.5, Brushes.Black ); dc.DrawText( tx, new Point( layoutState.LabelPosition.X - tx.Width, layoutState.LabelPosition.Y - tx.Height ) ); } dc.Close(); Visual.SetValue( GraphItemProperty, Owner ); }
// TODO: we should interpret the shape/style/color attributes ... public void Draw( NodeLayout layoutState ) { var style = myPresentation.GetPropertySetFor<NodeStyle>().Get( Owner.Id ); var label = myPresentation.GetPropertySetFor<Caption>().Get( Owner.Id ); Visual = new DrawingVisual(); var dc = Visual.RenderOpen(); dc.DrawEllipse( style.FillColor, new Pen( style.BorderColor, 0.016 ), layoutState.Center, layoutState.Width, layoutState.Height ); var tx = new FormattedText( label.DisplayText, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, myFont, layoutState.Height * 0.7, Brushes.Black ); dc.DrawText( tx, new Point( layoutState.Center.X - tx.Width / 2, layoutState.Center.Y - tx.Height / 2 ) ); dc.Close(); Visual.SetValue( GraphItemProperty, Owner ); }
//************************************************************************* // Method: SaveVertexOnDrawingVisual() // /// <summary> /// Saves a vertex on the DrawingVisual with which the vertex was drawn. /// </summary> /// /// <param name="oVertex"> /// The vertex that was drawn. /// </param> /// /// <param name="oDrawingVisual"> /// The DrawingVisual with which <paramref name="oVertex" /> was drawn. /// </param> /// /// <remarks> /// The vertex can be retrieved from the DrawingVisual with <see /// cref="RetrieveVertexFromDrawingVisual" />. /// </remarks> //************************************************************************* protected void SaveVertexOnDrawingVisual( IVertex oVertex, DrawingVisual oDrawingVisual ) { Debug.Assert(oVertex != null); Debug.Assert(oDrawingVisual != null); AssertValid(); // DrawingVisual has no Tag property, so use FrameworkElement's Tag // property as an attached property. oDrawingVisual.SetValue(FrameworkElement.TagProperty, oVertex); }