protected virtual IDisposable DrawRibbonTabGlowing(PaletteRibbonShape shape,
RenderContext context,
Rectangle rect,
PaletteState state,
IPaletteRibbonBack palette,
VisualOrientation orientation,
IDisposable memento)
{
if ((rect.Width > 0) && (rect.Height > 0))
{
Color c1 = palette.GetRibbonBackColor1(state);
Color c2 = palette.GetRibbonBackColor2(state);
Color insideColor = Color.FromArgb(36, c2);
bool generate = true;
MementoRibbonTabGlowing cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonTabGlowing))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonTabGlowing(rect, c1, c2, insideColor, orientation);
memento = cache;
}
else
{
cache = (MementoRibbonTabGlowing)memento;
generate = !cache.UseCachedValues(rect, c1, c2, insideColor, orientation);
}
// Do we need to generate the contents of the cache?
if (generate)
{
// Dispose of existing values
cache.Dispose();
switch (orientation)
{
case VisualOrientation.Top:
DrawRibbonTabGlowingTop(rect, c1, c2, insideColor, cache);
break;
case VisualOrientation.Left:
DrawRibbonTabGlowingLeft(rect, c1, c2, insideColor, cache);
break;
case VisualOrientation.Right:
DrawRibbonTabGlowingRight(rect, c1, c2, insideColor, cache);
break;
case VisualOrientation.Bottom:
DrawRibbonTabGlowingBottom(rect, c1, c2, insideColor, cache);
break;
}
}
// Fill the path area with inside color
context.Graphics.FillPath(cache.insideBrush, cache.outsidePath);
switch (orientation)
{
case VisualOrientation.Top:
// Draw the missing line from the bottom of the inside area
context.Graphics.DrawLine(cache.insidePen, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
break;
case VisualOrientation.Left:
// Draw the missing line from the right of the inside area
context.Graphics.DrawLine(cache.insidePen, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
break;
}
// Draw the border over the edge of the inside color
using (AntiAlias aa = new AntiAlias(context.Graphics))
context.Graphics.DrawPath(cache.outsidePen, cache.outsidePath);
// Draw the top glass effect
context.Graphics.FillPath(cache.topBrush, cache.topPath);
// Cannot draw a path that contains a zero sized element
if ((cache.ellipseRect.Width > 0) && (cache.ellipseRect.Height > 0))
context.Graphics.FillRectangle(cache.ellipseBrush, cache.fullRect);
}
return memento;
}