private static IDisposable DrawBackGlassCenter(RectangleF drawRect,
Color color1,
Color color2,
Color glassColor1,
Color glassColor2,
float factorX,
float factorY,
VisualOrientation orientation,
Graphics g,
float glassPercent,
IDisposable memento)
{
// Cannot draw a path that contains a zero sized element
if ((drawRect.Width > 0) && (drawRect.Height > 0))
{
MementoDouble cache;
if ((memento == null) || !(memento is MementoDouble))
{
if (memento != null)
memento.Dispose();
cache = new MementoDouble();
memento = cache;
}
else
{
cache = (MementoDouble)memento;
}
// Draw the gradient effect background
DrawBackGlassBasic(drawRect, color1, color2,
glassColor1, glassColor2,
factorX, factorY,
orientation, g,
glassPercent,
ref cache.first);
bool generate = true;
MementoBackGlassCenter cacheThis;
// Access a cache instance and decide if cache resources need generating
if ((cache.second == null) || !(cache.second is MementoBackGlassCenter))
{
if (cache.second != null)
cache.second.Dispose();
cacheThis = new MementoBackGlassCenter(drawRect, color2);
cache.second = cacheThis;
}
else
{
cacheThis = (MementoBackGlassCenter)cache.second;
generate = !cacheThis.UseCachedValues(drawRect, color2);
}
// Do we need to generate the contents of the cache?
if (generate)
{
// Dispose of existing values
cacheThis.Dispose();
cacheThis.path = new GraphicsPath();
cacheThis.path.AddEllipse(drawRect);
cacheThis.bottomBrush = new PathGradientBrush(cacheThis.path);
cacheThis.bottomBrush.CenterColor = color2;
cacheThis.bottomBrush.CenterPoint = new PointF(drawRect.X + (drawRect.Width / 2), drawRect.Y + (drawRect.Height / 2));
cacheThis.bottomBrush.SurroundColors = new Color[] { Color.Transparent };
}
g.FillRectangle(cacheThis.bottomBrush, drawRect);
}
return memento;
}