protected virtual IDisposable DrawRibbonGroupCollapsedFrameBorder(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;
MementoRibbonGroupCollapsedFrameBorder cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonGroupCollapsedFrameBorder))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonGroupCollapsedFrameBorder(rect, c1, c2);
memento = cache;
}
else
{
cache = (MementoRibbonGroupCollapsedFrameBorder)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();
GraphicsPath solidPath = new GraphicsPath();
// Create the rounded complete border
solidPath.AddLine(rect.Left + 2, rect.Top, rect.Right - 3, rect.Top);
solidPath.AddLine(rect.Right - 3, rect.Top, rect.Right - 1, rect.Top + 2);
solidPath.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom - 3);
solidPath.AddLine(rect.Right - 1, rect.Bottom - 3, rect.Right - 3, rect.Bottom - 1);
solidPath.AddLine(rect.Right - 3, rect.Bottom - 1, rect.Left + 2, rect.Bottom - 1);
solidPath.AddLine(rect.Left + 2, rect.Bottom - 1, rect.Left, rect.Bottom - 3);
solidPath.AddLine(rect.Left, rect.Bottom - 3, rect.Left, rect.Top + 2);
solidPath.AddLine(rect.Left, rect.Top + 2, rect.Left + 2, rect.Top);
cache.solidPath = solidPath;
cache.titleBrush = new SolidBrush(c2);
cache.solidPen = new Pen(c1);
}
// Perform actual drawing using the cache values
Rectangle titleRect = new Rectangle(rect.Left + 1, rect.Bottom - _groupFrameTitleHeight, rect.Width - 2, _groupFrameTitleHeight - 1);
context.Graphics.FillRectangle(cache.titleBrush, titleRect);
using (AntiAlias aa = new AntiAlias(context.Graphics))
context.Graphics.DrawPath(cache.solidPen, cache.solidPath);
}
return memento;
}