/// <summary> /// Draw a background for an expert style button has a square inside with highlight. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="backColor1">First color.</param> /// <param name="backColor2">Second color.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="path">Clipping path.</param> /// <param name="memento">Cache used for drawing.</param> /// <param name="light">Use the 'light' variation.</param> public static IDisposable DrawBackExpertSquareHighlight(RenderContext context, Rectangle rect, Color backColor1, Color backColor2, VisualOrientation orientation, GraphicsPath path, IDisposable memento, bool light) { using (Clipping clip = new Clipping(context.Graphics, path)) { // Cannot draw a zero length rectangle if ((rect.Width > 0) && (rect.Height > 0)) { bool generate = true; MementoBackExpertSquareHighlight cache; // Access a cache instance and decide if cache resources need generating if ((memento == null) || !(memento is MementoBackExpertSquareHighlight)) { if (memento != null) memento.Dispose(); cache = new MementoBackExpertSquareHighlight(rect, backColor1, backColor2, orientation); memento = cache; } else { cache = (MementoBackExpertSquareHighlight)memento; generate = !cache.UseCachedValues(rect, backColor1, backColor2, orientation); } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cache.Dispose(); cache.backBrush = new SolidBrush(CommonHelper.WhitenColor(backColor1, 0.8f, 0.8f, 0.8f)); cache.innerRect = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2); RectangleF ellipseRect; PointF ellipseCenter; int ellipseWidth = Math.Max(1, rect.Width / 8); int ellipseHeight = Math.Max(1, rect.Height / 8); switch (orientation) { default: case VisualOrientation.Top: cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 90f); ellipseRect = new RectangleF(rect.Left, rect.Top + (ellipseHeight * 2), rect.Width, ellipseHeight * 12); ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Bottom); break; case VisualOrientation.Bottom: cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 270f); ellipseRect = new RectangleF(rect.Left, rect.Top - (ellipseHeight * 6), rect.Width, ellipseHeight * 12); ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Top); break; case VisualOrientation.Left: cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 180f); ellipseRect = new RectangleF(rect.Left + (ellipseHeight * 2), rect.Top, ellipseWidth * 12, rect.Height); ellipseCenter = new PointF(ellipseRect.Right, ellipseRect.Top + (ellipseRect.Height / 2)); break; case VisualOrientation.Right: cache.innerBrush = new LinearGradientBrush(rect, backColor1, backColor2, 0f); ellipseRect = new RectangleF(rect.Left - (ellipseHeight * 6), rect.Top, ellipseWidth * 12, rect.Height); ellipseCenter = new PointF(ellipseRect.Left, ellipseRect.Top + (ellipseRect.Height / 2)); break; } cache.innerBrush.SetSigmaBellShape(0.5f); cache.ellipsePath = new GraphicsPath(); cache.ellipsePath.AddEllipse(ellipseRect); cache.insideLighten = new PathGradientBrush(cache.ellipsePath); cache.insideLighten.CenterPoint = ellipseCenter; cache.insideLighten.CenterColor = (light ? Color.FromArgb(64, Color.White) : Color.FromArgb(128, Color.White)); cache.insideLighten.Blend = _rounded2Blend; cache.insideLighten.SurroundColors = new Color[] { Color.Transparent }; } context.Graphics.FillRectangle(cache.backBrush, rect); context.Graphics.FillRectangle(cache.innerBrush, cache.innerRect); context.Graphics.FillRectangle(cache.insideLighten, cache.innerRect); } return memento; } }
/// <summary> /// Draw a background for an expert style button has a square inside with highlight. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="backColor1">First color.</param> /// <param name="backColor2">Second color.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="path">Clipping path.</param> /// <param name="memento">Cache used for drawing.</param> /// <param name="light">Use the 'light' variation.</param> public static IDisposable DrawBackExpertSquareHighlight(RenderContext context, Rectangle rect, Color backColor1, Color backColor2, VisualOrientation orientation, GraphicsPath path, IDisposable memento, bool light) { using Clipping clip = new(context.Graphics, path); // Cannot draw a zero length rectangle if ((rect.Width > 0) && (rect.Height > 0)) { var generate = true; MementoBackExpertSquareHighlight cache; // Access a cache instance and decide if cache resources need generating if (memento is MementoBackExpertSquareHighlight highlight) { cache = highlight; generate = !cache.UseCachedValues(rect, backColor1, backColor2, orientation); } else { memento?.Dispose(); cache = new MementoBackExpertSquareHighlight(rect, backColor1, backColor2, orientation); memento = cache; } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cache.Dispose(); cache.backBrush = new SolidBrush(CommonHelper.WhitenColor(backColor1, 0.8f, 0.8f, 0.8f)); cache.innerRect = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2); RectangleF ellipseRect; PointF ellipseCenter; var ellipseWidth = Math.Max(1, rect.Width / 8); var ellipseHeight = Math.Max(1, rect.Height / 8); switch (orientation) { default: case VisualOrientation.Top: cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 90f); ellipseRect = new RectangleF(rect.Left, rect.Top + (ellipseHeight * 2), rect.Width, ellipseHeight * 12); ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Bottom); break; case VisualOrientation.Bottom: cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 270f); ellipseRect = new RectangleF(rect.Left, rect.Top - (ellipseHeight * 6), rect.Width, ellipseHeight * 12); ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Top); break; case VisualOrientation.Left: cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 180f); ellipseRect = new RectangleF(rect.Left + (ellipseHeight * 2), rect.Top, ellipseWidth * 12, rect.Height); ellipseCenter = new PointF(ellipseRect.Right, ellipseRect.Top + (ellipseRect.Height / 2)); break; case VisualOrientation.Right: cache.innerBrush = new LinearGradientBrush(rect, backColor1, backColor2, 0f); ellipseRect = new RectangleF(rect.Left - (ellipseHeight * 6), rect.Top, ellipseWidth * 12, rect.Height); ellipseCenter = new PointF(ellipseRect.Left, ellipseRect.Top + (ellipseRect.Height / 2)); break; } cache.innerBrush.SetSigmaBellShape(0.5f); cache.ellipsePath = new GraphicsPath(); cache.ellipsePath.AddEllipse(ellipseRect); cache.insideLighten = new PathGradientBrush(cache.ellipsePath) { CenterPoint = ellipseCenter, CenterColor = light ? Color.FromArgb(64, Color.White) : Color.FromArgb(128, Color.White), Blend = _rounded2Blend, SurroundColors = new[] { Color.Transparent } }; } context.Graphics.FillRectangle(cache.backBrush, rect); context.Graphics.FillRectangle(cache.innerBrush, cache.innerRect); context.Graphics.FillRectangle(cache.insideLighten, cache.innerRect); } return(memento); }