protected virtual IDisposable DrawRibbonGroupGradientTwo(RenderContext context,
Rectangle rect,
PaletteState state,
IPaletteRibbonBack palette,
float percent,
IDisposable memento)
{
if ((rect.Width > 0) && (rect.Height > 0))
{
Color c1 = palette.GetRibbonBackColor1(state);
Color c2 = palette.GetRibbonBackColor2(state);
Color c3 = palette.GetRibbonBackColor3(state);
Color c4 = palette.GetRibbonBackColor4(state);
bool generate = true;
MementoRibbonGroupGradientTwo cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonGroupGradientTwo))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonGroupGradientTwo(rect, c1, c2, c3, c4);
memento = cache;
}
else
{
cache = (MementoRibbonGroupGradientTwo)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();
int topHeight = (int)(rect.Height * percent);
Rectangle topRect = new Rectangle(rect.Left, rect.Top, rect.Width, topHeight);
Rectangle bottomRect = new Rectangle(rect.Left, topRect.Bottom, rect.Width, rect.Height - topHeight);
RectangleF topRectF = new RectangleF(topRect.Left - 1, topRect.Top - 1, topRect.Width + 2, topRect.Height + 2);
RectangleF bottomRectF = new RectangleF(bottomRect.Left - 1, bottomRect.Top - 1, bottomRect.Width + 2, bottomRect.Height + 2);
cache.topBrush = new LinearGradientBrush(topRectF, c1, c2, 90f);
cache.bottomBrush = new LinearGradientBrush(bottomRectF, c3, c4, 90f);
cache.topRect = topRect;
cache.bottomRect = bottomRect;
}
// Perform actual drawing using the cache values
context.Graphics.FillRectangle(cache.topBrush, cache.topRect);
context.Graphics.FillRectangle(cache.bottomBrush, cache.bottomRect);
}
return memento;
}