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

DrawRibbonGroupGradientOne() protected method

Internal rendering method.
protected DrawRibbonGroupGradientOne ( 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 DrawRibbonGroupGradientOne(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;
                MementoRibbonGroupGradientOne cache;

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

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

                    RectangleF rectF = new RectangleF(rect.Left - 1, rect.Top - 1, rect.Width + 2, rect.Height + 2);
                    cache.brush = new LinearGradientBrush(rectF, c1, c2, 90f);
                    cache.brush.Blend = _ribbonGroup8Blend;
                }

                // Perform actual drawing using the cache values
                context.Graphics.FillRectangle(cache.brush, rect);
            }

            return memento;
        }
RenderStandard