protected virtual IDisposable DrawRibbonGroupAreaBorderContext(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);
Color c3 = palette.GetRibbonBackColor3(state);
bool generate = true;
MementoRibbonGroupAreaBorderContext cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonGroupAreaBorderContext))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonGroupAreaBorderContext(rect, c1, c2, c3);
memento = cache;
}
else
{
cache = (MementoRibbonGroupAreaBorderContext)memento;
generate = !cache.UseCachedValues(rect, c1, c2, c3);
}
// Do we need to generate the contents of the cache?
if (generate)
{
// Dispose of existing values
cache.Dispose();
GraphicsPath outsidePath = new GraphicsPath();
GraphicsPath insidePath = new GraphicsPath();
GraphicsPath shadowPath = new GraphicsPath();
// Create path for the entire border
outsidePath.AddLine(rect.Left + 2, rect.Top, rect.Right - 3, rect.Top);
outsidePath.AddLine(rect.Right - 3, rect.Top, rect.Right - 1, rect.Top + 2);
outsidePath.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom - 3);
outsidePath.AddLine(rect.Right - 1, rect.Bottom - 3, rect.Right - 3, rect.Bottom - 1);
outsidePath.AddLine(rect.Right - 3, rect.Bottom - 1, rect.Left + 2, rect.Bottom - 1);
outsidePath.AddLine(rect.Left + 2, rect.Bottom - 1, rect.Left, rect.Bottom - 3);
outsidePath.AddLine(rect.Left, rect.Bottom - 3, rect.Left, rect.Top + 2);
outsidePath.AddLine(rect.Left, rect.Top + 2, rect.Left + 2, rect.Top);
// Create the path for the inside highlight
insidePath.AddLine(rect.Left + 1, rect.Top + 3, rect.Left + 1, rect.Bottom - 3);
insidePath.AddLine(rect.Left + 1, rect.Bottom - 3, rect.Left + 2, rect.Bottom - 2);
insidePath.AddLine(rect.Left + 2, rect.Bottom - 2, rect.Right - 3, rect.Bottom - 2);
insidePath.AddLine(rect.Right - 3, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 3);
insidePath.AddLine(rect.Right - 2, rect.Bottom - 3, rect.Right - 2, rect.Top + 3);
// Create the path for the outside shadow
shadowPath.AddLine(rect.Left, rect.Bottom - 2, rect.Left + 2, rect.Bottom);
shadowPath.AddLine(rect.Left + 2, rect.Bottom, rect.Right - 3, rect.Bottom);
shadowPath.AddLine(rect.Right - 4, rect.Bottom, rect.Right, rect.Bottom - 3);
shadowPath.AddLine(rect.Right, rect.Bottom - 3, rect.Right, rect.Top + 3);
LinearGradientBrush insideBrush = new LinearGradientBrush(rect, Color.Transparent, c2, 95f);
cache.insidePen = new Pen(insideBrush);
Rectangle rectGradient = new Rectangle(rect.Left - 1, rect.Top, rect.Width + 2, rect.Height + 1);
LinearGradientBrush shadowBrush = new LinearGradientBrush(rectGradient, _darken8, _darken38, 90f);
cache.shadowPen = new Pen(shadowBrush);
cache.fillBrush = new LinearGradientBrush(rect, Color.White, _242, 90f);
cache.fillBrush.Blend = _ribbonGroup3Blend;
cache.fillTopBrush = new LinearGradientBrush(rect, Color.FromArgb(75, c3), Color.Transparent, 90f);
cache.fillTopBrush.Blend = _ribbonGroup4Blend;
cache.outsidePath = outsidePath;
cache.insidePath = insidePath;
cache.shadowPath = shadowPath;
cache.outsidePen = new Pen(c1);
}
// Fill the inside area with a linear gradient
context.Graphics.FillPath(cache.fillBrush, cache.outsidePath);
// Clip drawing to the outside border
using (Clipping clip = new Clipping(context.Graphics, cache.outsidePath))
context.Graphics.FillPath(cache.fillTopBrush, cache.outsidePath);
using (AntiAlias aa = new AntiAlias(context.Graphics))
{
// Draw the outside of the entire border line
context.Graphics.DrawPath(cache.outsidePen, cache.outsidePath);
// Draw the highlighting inside border
context.Graphics.DrawPath(cache.insidePen, cache.insidePath);
}
// Draw the shadow outside the bottom and right edges
context.Graphics.DrawPath(cache.shadowPen, cache.shadowPath);
context.Graphics.DrawLine(_medium2ShadowPen, rect.Left, rect.Bottom, rect.Left, rect.Bottom - 1);
context.Graphics.DrawLine(_medium2ShadowPen, rect.Left, rect.Bottom - 1, rect.Left + 1, rect.Bottom);
context.Graphics.DrawLine(_darkShadowPen, rect.Right, rect.Bottom - 2, rect.Right - 2, rect.Bottom);
context.Graphics.DrawLine(_medium2ShadowPen, rect.Right, rect.Bottom - 1, rect.Right - 1, rect.Bottom);
}
return memento;
}