protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup faces, INode node) { // create faces var nodeData = (NodeData)node.Tag; var height = nodeData.Geometry.Height; var layout = node.Layout; var oldCache = faces.GetRenderDataCache <NodeRenderData>(); var newCache = new NodeRenderData(layout.X, layout.Y, layout.Width, layout.Height, height, nodeData.Color, context.Projection); if (!newCache.Equals(oldCache)) { faces.SetRenderDataCache(newCache); var corners = CalculateCorners(context.Projection, layout.X, layout.Y, layout.Width, layout.Height, height); SolidColorBrush topBrush = null; SolidColorBrush leftBrush = null; SolidColorBrush rightBrush = null; var pen = nodeData.Pen; var brush = nodeData.Brush; if (brush != null) { topBrush = brush; if (height > 0) { leftBrush = Darker(brush); rightBrush = Darker(leftBrush); } } if (height == 0 && faces.Children.Count > 1) { while (faces.Children.Count > 1) { faces.Children.RemoveAt(faces.Children.Count - 1); } } else if (height > 0) { // check which of the left, right, back and front faces are visible using the current projection var upVector = CalculateHeightVector(context.Projection); var useLeft = upVector.X > 0; var useBack = upVector.Y > 0; var leftFacePath = useLeft ? GetLeftFacePath(corners) : GetRightFacePath(corners); var rightFacePath = useBack ? GetBackFacePath(corners) : GetFrontFacePath(corners); if (faces.Children.Count == 1) { var faceLeft = leftFacePath.CreatePath(leftBrush, pen, null, FillMode.Always); faces.Children.Insert(0, faceLeft); var faceRight = rightFacePath.CreatePath(rightBrush, pen, null, FillMode.Always); faces.Children.Insert(1, faceRight); } else { var faceLeft = faces.Children[0] as Path; leftFacePath.UpdatePath(faceLeft, leftBrush, pen, null, FillMode.Always); var faceRight = faces.Children[1] as Path; rightFacePath.UpdatePath(faceRight, rightBrush, pen, null, FillMode.Always); } } var topFacePath = GetTopFacePath(corners); var faceTop = faces.Children.Last() as Path; topFacePath.UpdatePath(faceTop, topBrush, pen, null, FillMode.Always); } return(faces); }
private bool Equals(NodeRenderData other) { return(other.X == X && other.Y == Y && other.Width == Width && other.Height == Height && other.Depth == Depth && other.Color == Color && other.Projection == Projection); }