/// <summary> /// Recolor a rendering element after it has been generated. Since rendering elements are /// immutable, the input element remains unmodified. /// </summary> /// <param name="element">the rendering element</param> /// <param name="color">the new color</param> /// <returns>recolored rendering element</returns> private static IRenderingElement Recolor(IRenderingElement element, Color color) { switch (element) { case ElementGroup orgGroup: var newGroup = new ElementGroup(); foreach (var child in orgGroup) { newGroup.Add(Recolor(child, color)); } return(newGroup); case LineElement lineElement: return(new LineElement(lineElement.FirstPoint, lineElement.SecondPoint, lineElement.Width, color)); case GeneralPath generalPath: return(generalPath.Recolor(color)); } throw new ArgumentException($"Cannot highlight rendering element, {element.GetType()}"); }
/// <summary> /// Generate an outer glow for the provided rendering element. The glow is defined by the glow /// width and the stroke size. /// </summary> /// <param name="element">rendering element</param> /// <param name="color">color of the glow</param> /// <param name="glowWidth">the width of the glow</param> /// <param name="stroke">the stroke width</param> /// <returns>generated outer glow</returns> internal static IRenderingElement OuterGlow(IRenderingElement element, Color color, double glowWidth, double stroke) { switch (element) { case ElementGroup orgGroup: var newGroup = new ElementGroup(); foreach (var child in orgGroup) { newGroup.Add(OuterGlow(child, color, glowWidth, stroke)); } return(newGroup); case LineElement lineElement: return(new LineElement(lineElement.FirstPoint, lineElement.SecondPoint, stroke + (2 * (glowWidth * stroke)), color)); case GeneralPath org: if (org.Fill) { return(org.Outline(2 * (glowWidth * stroke)).Recolor(color)); } else { return(org.Outline(stroke + (2 * (glowWidth * stroke))).Recolor(color)); } default: throw new ArgumentException($"Cannot generate glow for rendering element,{element.GetType()}"); } }