/// <summary> /// Internal rendering method. /// </summary> protected override IDisposable DrawRibbonTabContext(RenderContext context, Rectangle rect, IPaletteRibbonGeneral paletteGeneral, IPaletteRibbonBack paletteBack, IDisposable memento) { if ((rect.Width > 0) && (rect.Height > 0)) { Color c1 = paletteGeneral.GetRibbonTabSeparatorContextColor(PaletteState.Normal); Color c2 = paletteBack.GetRibbonBackColor5(PaletteState.ContextCheckedNormal); bool generate = true; MementoRibbonTabContextOffice cache; // Access a cache instance and decide if cache resources need generating if (!(memento is MementoRibbonTabContextOffice)) { memento?.Dispose(); cache = new MementoRibbonTabContextOffice(rect, c1, c2); memento = cache; } else { cache = (MementoRibbonTabContextOffice)memento; generate = !cache.UseCachedValues(rect, c1, c2); } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cache.Dispose(); Rectangle borderRect = new Rectangle(rect.X - 1, rect.Y - 1, rect.Width + 2, rect.Height + 2); cache.fillRect = new Rectangle(rect.X + 1, rect.Y, rect.Width - 2, rect.Height - 1); LinearGradientBrush borderBrush = new LinearGradientBrush(borderRect, c1, Color.Transparent, 270f) { Blend = _ribbonGroup5Blend }; cache.borderPen = new Pen(borderBrush); LinearGradientBrush underlineBrush = new LinearGradientBrush(borderRect, Color.Transparent, Color.FromArgb(200, c2), 0f) { Blend = _ribbonGroup7Blend }; cache.underlinePen = new Pen(underlineBrush); cache.fillBrush = new LinearGradientBrush(borderRect, Color.FromArgb(106, c2), Color.Transparent, 270f) { Blend = _ribbonGroup6Blend }; } // Draw the left and right border lines context.Graphics.DrawLine(cache.borderPen, rect.X, rect.Y, rect.X, rect.Bottom - 1); context.Graphics.DrawLine(cache.borderPen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 1); // Fill the inner area with a gradient context specific color context.Graphics.FillRectangle(cache.fillBrush, cache.fillRect); // Overdraw the brighter line at bottom context.Graphics.DrawLine(cache.underlinePen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2); } 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 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 is MementoBackExpertSquareHighlight)) { 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) { CenterPoint = ellipseCenter, CenterColor = (light ? Color.FromArgb(64, Color.White) : Color.FromArgb(128, Color.White)), Blend = _rounded2Blend, 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); } }