ComponentFactory.Krypton.Toolkit.RenderGlassHelpers.DrawBackLinearRadial C# (CSharp) Method

DrawBackLinearRadial() private static method

private static DrawBackLinearRadial ( RectangleF drawRect, bool sigma, Color color1, Color color2, Color color3, VisualOrientation orientation, Graphics g, IDisposable memento ) : IDisposable
drawRect System.Drawing.RectangleF
sigma bool
color1 Color
color2 Color
color3 Color
orientation VisualOrientation
g System.Drawing.Graphics
memento IDisposable
return IDisposable
        private static IDisposable DrawBackLinearRadial(RectangleF drawRect,
                                                        bool sigma,
                                                        Color color1,
                                                        Color color2,
                                                        Color color3,
                                                        VisualOrientation orientation,
                                                        Graphics g,
                                                        IDisposable memento)
        {
            MementoDouble cache;

            if ((memento == null) || !(memento is MementoDouble))
            {
                if (memento != null)
                    memento.Dispose();

                cache = new MementoDouble();
                memento = cache;
            }
            else
            {
                cache = (MementoDouble)memento;
            }

            // Draw entire background in linear gradient effect
            cache.first = DrawBackLinear(drawRect, sigma, color1, color2, orientation, g, cache.first);

            bool generate = true;
            MementoBackLinearRadial cacheThis;

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

                cacheThis = new MementoBackLinearRadial(drawRect, color2, color3, orientation);
                cache.second = cacheThis;
            }
            else
            {
                cacheThis = (MementoBackLinearRadial)cache.second;
                generate = !cacheThis.UseCachedValues(drawRect, color2, color3, orientation);
            }

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

                float third;

                // Find the 1/3 height used for the ellipse
                if (VerticalOrientation(orientation))
                    third = drawRect.Height / 3;
                else
                    third = drawRect.Width / 3;

                // Find the bottom area rectangle
                RectangleF ellipseRect;
                PointF centerPoint;

                switch (orientation)
                {
                    case VisualOrientation.Left:
                        ellipseRect = new RectangleF(drawRect.Right - third, drawRect.Y + 1, third, drawRect.Height - 2);
                        centerPoint = new PointF(ellipseRect.Right, ellipseRect.Y + (ellipseRect.Height / 2));
                        break;
                    case VisualOrientation.Right:
                        ellipseRect = new RectangleF(drawRect.X - 1, drawRect.Y + 1, third, drawRect.Height - 2);
                        centerPoint = new PointF(ellipseRect.Left, ellipseRect.Y + (ellipseRect.Height / 2));
                        break;
                    case VisualOrientation.Bottom:
                        ellipseRect = new RectangleF(drawRect.X + 1, drawRect.Y - 1, drawRect.Width - 2, third);
                        centerPoint = new PointF(ellipseRect.X + (ellipseRect.Width / 2), ellipseRect.Top);
                        break;
                    case VisualOrientation.Top:
                    default:
                        ellipseRect = new RectangleF(drawRect.X + 1, drawRect.Bottom - third, drawRect.Width - 2, third);
                        centerPoint = new PointF(ellipseRect.X + (ellipseRect.Width / 2), ellipseRect.Bottom);
                        break;
                }

                cacheThis.ellipseRect = ellipseRect;

                // Cannot draw a path that contains a zero sized element
                if ((ellipseRect.Width > 0) && (ellipseRect.Height > 0))
                {
                    cacheThis.path = new GraphicsPath();
                    cacheThis.path.AddEllipse(ellipseRect);
                    cacheThis.bottomBrush = new PathGradientBrush(cacheThis.path);
                    cacheThis.bottomBrush.CenterColor = ControlPaint.Light(color3);
                    cacheThis.bottomBrush.CenterPoint = centerPoint;
                    cacheThis.bottomBrush.SurroundColors = new Color[] { color2 };
                }
            }

            if (cacheThis.bottomBrush != null)
                g.FillRectangle(cacheThis.bottomBrush, cacheThis.ellipseRect);

            return memento;
        }