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

DrawRibbonGroupCollapsedBorder() protected method

Internal rendering method.
protected DrawRibbonGroupCollapsedBorder ( 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 DrawRibbonGroupCollapsedBorder(RenderContext context,
                                                                     Rectangle rect,
                                                                     PaletteState state,
                                                                     IPaletteRibbonBack palette,
                                                                     IDisposable memento)
        {
            if ((rect.Width > 0) && (rect.Height > 0))
            {
                // Grab the colors needed for drawing
                Color c1 = palette.GetRibbonBackColor1(state);
                Color c2 = palette.GetRibbonBackColor2(state);
                Color c3 = palette.GetRibbonBackColor3(state);
                Color c4 = palette.GetRibbonBackColor4(state);

                bool generate = true;
                MementoRibbonGroupCollapsedBorder cache;

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

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

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

                    GraphicsPath solidPath = new GraphicsPath();
                    GraphicsPath insidePath = new GraphicsPath();

                    // Create the rounded complete border
                    solidPath.AddLine(rect.Left + 1.25f, rect.Top, rect.Right - 2, rect.Top);
                    solidPath.AddLine(rect.Right - 2, rect.Top, rect.Right - 1, rect.Top + 2);
                    solidPath.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom - 3);
                    solidPath.AddLine(rect.Right - 1, rect.Bottom - 3, rect.Right - 3, rect.Bottom - 1);
                    solidPath.AddLine(rect.Right - 3, rect.Bottom - 1, rect.Left + 2, rect.Bottom - 1);
                    solidPath.AddLine(rect.Left + 2, rect.Bottom - 1, rect.Left, rect.Bottom - 3);
                    solidPath.AddLine(rect.Left, rect.Bottom - 3, rect.Left, rect.Top + 1.25f);
                    solidPath.AddLine(rect.Left, rect.Top + 1.25f, rect.Left + 1.25f, rect.Top);

                    // Create the inside border
                    insidePath.AddLine(rect.Left + 2, rect.Top + 1, rect.Right - 3, rect.Top + 1);
                    insidePath.AddLine(rect.Right - 3, rect.Top + 1, rect.Right - 2, rect.Top + 2);
                    insidePath.AddLine(rect.Right - 2, rect.Top + 2, rect.Right - 2, rect.Bottom - 3);
                    insidePath.AddLine(rect.Right - 2, rect.Bottom - 3, rect.Right - 3, rect.Bottom - 2);
                    insidePath.AddLine(rect.Right - 3, rect.Bottom - 2, rect.Left + 2, rect.Bottom - 2);
                    insidePath.AddLine(rect.Left + 2, rect.Bottom - 2, rect.Left + 1, rect.Bottom - 3);
                    insidePath.AddLine(rect.Left + 1, rect.Bottom - 3, rect.Left + 1, rect.Top + 2);
                    insidePath.AddLine(rect.Left + 1, rect.Top + 2, rect.Left + 2, rect.Top + 1);

                    RectangleF solidRectF = new RectangleF(rect.Left - 1, rect.Top - 1, rect.Width + 2, rect.Height + 2);
                    RectangleF insideRectF = new RectangleF(rect.Left, rect.Top, rect.Width, rect.Height);

                    LinearGradientBrush solidBrush = new LinearGradientBrush(solidRectF, c1, c2, 90f);
                    LinearGradientBrush insideBrush = new LinearGradientBrush(insideRectF, c3, c4, 90f);

                    cache.solidPath = solidPath;
                    cache.insidePath = insidePath;
                    cache.solidPen = new Pen(solidBrush);
                    cache.insidePen = new Pen(insideBrush);
                }

                // Perform actual drawing using the cache values
                using (AntiAlias aa = new AntiAlias(context.Graphics))
                {
                    context.Graphics.DrawPath(cache.solidPen, cache.solidPath);
                    context.Graphics.DrawPath(cache.insidePen, cache.insidePath);
                }
            }

            return memento;
        }
RenderStandard