/// <summary> /// Draw a background for an expert style button with pressed effect. /// </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> public static IDisposable DrawBackExpertPressed(RenderContext context, Rectangle rect, Color backColor1, Color backColor2, VisualOrientation orientation, GraphicsPath path, IDisposable memento) { using (Clipping clip = new Clipping(context.Graphics, path)) { // Cannot draw a zero length rectangle if ((rect.Width > 0) && (rect.Height > 0)) { bool generate = true; MementoBackExpertShadow cache; // Access a cache instance and decide if cache resources need generating if (!(memento is MementoBackExpertShadow)) { memento?.Dispose(); cache = new MementoBackExpertShadow(rect, backColor1, backColor2); memento = cache; } else { cache = (MementoBackExpertShadow)memento; generate = !cache.UseCachedValues(rect, backColor1, backColor2); } // Do we need to generate the contents of the cache? if (generate) { rect.X -= 1; rect.Y -= 1; rect.Width += 2; rect.Height += 2; // Dispose of existing values cache.Dispose(); cache.path1 = CreateBorderPath(rect, ITEM_CUT); cache.path2 = CreateBorderPath(new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2), ITEM_CUT); cache.path3 = CreateBorderPath(new Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 4, rect.Height - 4), ITEM_CUT); cache.brush1 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.4f, backColor1, 0.6f)); cache.brush2 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.2f, backColor1, 0.8f)); cache.brush3 = new SolidBrush(backColor1); } using (AntiAlias aa = new AntiAlias(context.Graphics)) { context.Graphics.FillRectangle(cache.brush3, rect); context.Graphics.FillPath(cache.brush1, cache.path1); context.Graphics.FillPath(cache.brush2, cache.path2); context.Graphics.FillPath(cache.brush3, cache.path3); } } return(memento); } }
/// <summary> /// Draw a background for an expert style button with pressed effect. /// </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> public static IDisposable DrawBackExpertPressed(RenderContext context, Rectangle rect, Color backColor1, Color backColor2, VisualOrientation orientation, GraphicsPath path, IDisposable memento) { using (Clipping clip = new Clipping(context.Graphics, path)) { // Cannot draw a zero length rectangle if ((rect.Width > 0) && (rect.Height > 0)) { bool generate = true; MementoBackExpertShadow cache; // Access a cache instance and decide if cache resources need generating if ((memento == null) || !(memento is MementoBackExpertShadow)) { if (memento != null) memento.Dispose(); cache = new MementoBackExpertShadow(rect, backColor1, backColor2); memento = cache; } else { cache = (MementoBackExpertShadow)memento; generate = !cache.UseCachedValues(rect, backColor1, backColor2); } // Do we need to generate the contents of the cache? if (generate) { rect.X -= 1; rect.Y -= 1; rect.Width += 2; rect.Height += 2; // Dispose of existing values cache.Dispose(); cache.path1 = CreateBorderPath(rect, _itemCut); cache.path2 = CreateBorderPath(new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2), _itemCut); cache.path3 = CreateBorderPath(new Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 4, rect.Height - 4), _itemCut); cache.brush1 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.4f, backColor1, 0.6f)); cache.brush2 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.2f, backColor1, 0.8f)); cache.brush3 = new SolidBrush(backColor1); } using (AntiAlias aa = new AntiAlias(context.Graphics)) { context.Graphics.FillRectangle(cache.brush3, rect); context.Graphics.FillPath(cache.brush1, cache.path1); context.Graphics.FillPath(cache.brush2, cache.path2); context.Graphics.FillPath(cache.brush3, cache.path3); } } return memento; } }