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

DrawRibbonLinearBorder() protected method

Internal rendering method.
protected DrawRibbonLinearBorder ( RenderContext context, Rectangle rect, PaletteState state, IPaletteRibbonBack palette, IDisposable memento ) : IDisposable
context RenderContext
rect System.Drawing.Rectangle
state PaletteState
palette IPaletteRibbonBack
memento IDisposable
return IDisposable
        protected virtual IDisposable DrawRibbonLinearBorder(RenderContext context,
                                                             Rectangle rect,
                                                             PaletteState state,
                                                             IPaletteRibbonBack palette,
                                                             IDisposable memento)
        {
            if ((rect.Width > 0) && (rect.Height > 0))
            {
                Color c1 = palette.GetRibbonBackColor1(state);
                Color c2 = palette.GetRibbonBackColor2(state);

                bool generate = true;
                MementoRibbonLinearBorder cache;

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

                    cache = new MementoRibbonLinearBorder(rect, c1, c2);
                    memento = cache;
                }
                else
                {
                    cache = (MementoRibbonLinearBorder)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();

                    cache.linearBrush = new LinearGradientBrush(new RectangleF(rect.X - 1, rect.Y - 1, rect.Width + 2, rect.Height + 2), c1, c2, 90f);
                    cache.linearPen = new Pen(cache.linearBrush);

                    // Create the rounded complete border
                    GraphicsPath borderPath = new GraphicsPath();
                    borderPath.AddLine(rect.Left + 2, rect.Top, rect.Right - 3, rect.Top);
                    borderPath.AddLine(rect.Right - 3, rect.Top, rect.Right - 1, rect.Top + 2);
                    borderPath.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom - 3);
                    borderPath.AddLine(rect.Right - 1, rect.Bottom - 3, rect.Right - 3, rect.Bottom - 1);
                    borderPath.AddLine(rect.Right - 3, rect.Bottom - 1, rect.Left + 2, rect.Bottom - 1);
                    borderPath.AddLine(rect.Left + 2, rect.Bottom - 1, rect.Left, rect.Bottom - 3);
                    borderPath.AddLine(rect.Left, rect.Bottom - 3, rect.Left, rect.Top + 2);
                    borderPath.AddLine(rect.Left, rect.Top + 2, rect.Left + 2, rect.Top);
                    cache.borderPath = borderPath;

                }

                context.Graphics.DrawPath(cache.linearPen, cache.borderPath);
            }

            return memento;
        }
RenderStandard