ComponentFactory.Krypton.Toolkit.RenderStandard.DrawRibbonGroupAreaBorder1And2 C# (CSharp) Method

DrawRibbonGroupAreaBorder1And2() protected method

Internal rendering method.
protected DrawRibbonGroupAreaBorder1And2 ( RenderContext context, Rectangle rect, PaletteState state, IPaletteRibbonBack palette, bool limited, bool fading, IDisposable memento ) : IDisposable
context RenderContext
rect System.Drawing.Rectangle
state PaletteState
palette IPaletteRibbonBack
limited bool
fading bool
memento IDisposable
return IDisposable
        protected virtual IDisposable DrawRibbonGroupAreaBorder1And2(RenderContext context, 
                                                                     Rectangle rect,
                                                                     PaletteState state,
                                                                     IPaletteRibbonBack palette,
                                                                     bool limited,
                                                                     bool fading,
                                                                     IDisposable memento)
        {
            if ((rect.Width > 0) && (rect.Height > 0))
            {
                Color c1 = palette.GetRibbonBackColor1(state);
                Color c2 = palette.GetRibbonBackColor2(state);
                Color c3 = palette.GetRibbonBackColor3(state);
                Color c4 = palette.GetRibbonBackColor4(state);
                Color c5 = palette.GetRibbonBackColor5(state);

                if (fading)
                    c5 = Color.FromArgb(146, c5);

                bool generate = true;
                MementoRibbonGroupAreaBorder cache;

                // Access a cache instance and decide if cache resources need generating
                if ((memento == null) || !(memento is MementoRibbonGroupAreaBorder))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoRibbonGroupAreaBorder(rect, c1, c2, c3, c4, c5);
                    memento = cache;
                }
                else
                {
                    cache = (MementoRibbonGroupAreaBorder)memento;
                    generate = !cache.UseCachedValues(rect, c1, c2, c3, c4, c5);
                }

                // Do we need to generate the contents of the cache?
                if (generate)
                {
                    // Dispose of existing values
                    cache.Dispose();

                    GraphicsPath outsidePath = new GraphicsPath();
                    GraphicsPath insidePathN = new GraphicsPath();
                    GraphicsPath insidePathL = new GraphicsPath();
                    GraphicsPath shadowPath = new GraphicsPath();

                    // Create path for the entire border
                    outsidePath.AddLine(rect.Left + 2, rect.Top, rect.Right - 3, rect.Top);
                    outsidePath.AddLine(rect.Right - 3, rect.Top, rect.Right - 1, rect.Top + 2);
                    outsidePath.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom - 3);
                    outsidePath.AddLine(rect.Right - 1, rect.Bottom - 3, rect.Right - 3, rect.Bottom - 1);
                    outsidePath.AddLine(rect.Right - 3, rect.Bottom - 1, rect.Left + 2, rect.Bottom - 1);
                    outsidePath.AddLine(rect.Left + 2, rect.Bottom - 1, rect.Left, rect.Bottom - 3);
                    outsidePath.AddLine(rect.Left, rect.Bottom - 3, rect.Left, rect.Top + 2);
                    outsidePath.AddLine(rect.Left, rect.Top + 2, rect.Left + 2, rect.Top);

                    // Create the path for the inside highlight
                    insidePathL.AddLine(rect.Left + 2, rect.Bottom - 2, rect.Right - 3, rect.Bottom - 2);
                    insidePathN.AddLine(rect.Left + 1, rect.Top + 3, rect.Left + 1, rect.Bottom - 3);
                    insidePathN.AddLine(rect.Left + 1, rect.Bottom - 3, rect.Left + 2, rect.Bottom - 2);
                    insidePathN.AddLine(rect.Left + 2, rect.Bottom - 2, rect.Right - 3, rect.Bottom - 2);
                    insidePathN.AddLine(rect.Right - 3, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 3);
                    insidePathN.AddLine(rect.Right - 2, rect.Bottom - 3, rect.Right - 2, rect.Top + 3);

                    // Create the path for the outside shadow
                    shadowPath.AddLine(rect.Left, rect.Bottom - 2, rect.Left + 2, rect.Bottom);
                    shadowPath.AddLine(rect.Left + 2, rect.Bottom, rect.Right - 3, rect.Bottom);
                    shadowPath.AddLine(rect.Right - 4, rect.Bottom, rect.Right, rect.Bottom - 3);
                    shadowPath.AddLine(rect.Right, rect.Bottom - 3, rect.Right, rect.Top + 3);

                    LinearGradientBrush insideBrush = new LinearGradientBrush(rect, Color.Transparent, c2, 95f);
                    cache.insidePen = new Pen(insideBrush);

                    Rectangle rectGradient = new Rectangle(rect.Left - 1, rect.Top, rect.Width + 2, rect.Height + 1);
                    LinearGradientBrush shadowBrushN = new LinearGradientBrush(rectGradient, _darken8, _darken38, 90f);
                    LinearGradientBrush shadowBrushL = new LinearGradientBrush(rectGradient, _darken8, _darken18, 90f);
                    cache.shadowPenN = new Pen(shadowBrushN);
                    cache.shadowPenL = new Pen(shadowBrushL);

                    cache.insidePathN = insidePathN;
                    cache.insidePathL = insidePathL;
                    cache.fillBrush = new LinearGradientBrush(rect, c3, c4, 90f);
                    cache.fillBrush.Blend = _ribbonGroup1Blend;
                    cache.fillTopBrush = new LinearGradientBrush(rect, c5, Color.Transparent, 90f);
                    cache.fillTopBrush.Blend = _ribbonGroup2Blend;
                    cache.outsidePath = outsidePath;
                    cache.shadowPath = shadowPath;
                    cache.outsidePen = new Pen(c1);
                }

                // Fill the inside area with a linear gradient
                context.Graphics.FillPath(cache.fillBrush, cache.outsidePath);

                // Clip drawing to the outside border
                using(Clipping clip = new Clipping(context.Graphics, cache.outsidePath))
                    context.Graphics.FillPath(cache.fillTopBrush, cache.outsidePath);

                using (AntiAlias aa = new AntiAlias(context.Graphics))
                {
                    // Draw the outside of the entire border line
                    context.Graphics.DrawPath(cache.outsidePen, cache.outsidePath);

                    // Draw the highlighting inside border
                    context.Graphics.DrawPath(cache.insidePen, (limited ? cache.insidePathL : cache.insidePathN));
                }

                Pen shadowMedium = (limited ? _lightShadowPen : _medium2ShadowPen);
                Pen shadowDark = (limited ? _medium2ShadowPen : _darkShadowPen);
                context.Graphics.DrawPath(limited ? cache.shadowPenL : cache.shadowPenN, cache.shadowPath);
                context.Graphics.DrawLine(shadowMedium, rect.Left, rect.Bottom, rect.Left, rect.Bottom - 1);
                context.Graphics.DrawLine(shadowMedium, rect.Left, rect.Bottom - 1, rect.Left + 1, rect.Bottom);
                context.Graphics.DrawLine(shadowDark, rect.Right, rect.Bottom - 2, rect.Right - 2, rect.Bottom);
                context.Graphics.DrawLine(shadowMedium, rect.Right, rect.Bottom - 1, rect.Right - 1, rect.Bottom);
            }

            return memento;
        }
RenderStandard