protected virtual IDisposable DrawRibbonQATFullbarRound(RenderContext context,
Rectangle rect,
PaletteState state,
IPaletteRibbonBack palette,
IDisposable memento)
{
// We never draw the top line
rect.Y++;
rect.Height--;
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;
MementoRibbonQATFullbarRound cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonQATFullbarRound))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonQATFullbarRound(rect, c1, c2, c3);
memento = cache;
}
else
{
cache = (MementoRibbonQATFullbarRound)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();
cache.innerRect = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2);
cache.innerBrush = new LinearGradientBrush(rect, c1, c2, 90f);
cache.darkPen = new Pen(c3);
GraphicsPath darkPath = new GraphicsPath();
GraphicsPath lightPath1 = new GraphicsPath();
GraphicsPath lightPath2 = new GraphicsPath();
// Create the dark border
darkPath.AddLine(rect.Left, rect.Top + 0.75f, rect.Left + 1, rect.Top);
darkPath.AddLine(rect.Left + 1, rect.Top, rect.Right - 3.5f, rect.Top);
darkPath.AddLine(rect.Right - 3.5f, rect.Top, rect.Right - 2, rect.Top + 2);
darkPath.AddLine(rect.Right - 2, rect.Top + 2, rect.Right - 2, rect.Bottom - 3.25f);
darkPath.AddLine(rect.Right - 2, rect.Bottom - 3.25f, rect.Right - 3.25f, rect.Bottom - 2);
darkPath.AddLine(rect.Right - 3.25f, rect.Bottom - 2, rect.Left, rect.Bottom - 2);
// Create the first light border
lightPath1.AddLine(rect.Left, rect.Bottom - 3, rect.Left, rect.Top + 2.5f);
lightPath1.AddLine(rect.Left, rect.Top + 2.5f, rect.Left + 1, rect.Top + 1);
lightPath1.AddLine(rect.Left + 1, rect.Top + 1, rect.Right - 4, rect.Top + 1);
// Create the second light border
lightPath2.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom - 2);
lightPath2.AddLine(rect.Right - 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 1);
lightPath2.AddLine(rect.Right - 2, rect.Bottom - 1, rect.Left + 1, rect.Bottom - 1);
cache.darkPath = darkPath;
cache.lightPath1 = lightPath1;
cache.lightPath2 = lightPath2;
}
// Draw a gradient for the inside of the area
context.Graphics.FillRectangle(cache.innerBrush, cache.innerRect);
// Draw the dark/light lines
using (AntiAlias aa = new AntiAlias(context.Graphics))
{
context.Graphics.DrawPath(cache.darkPen, cache.darkPath);
context.Graphics.DrawPath(_light1Pen, cache.lightPath1);
context.Graphics.DrawPath(_light2Pen, cache.lightPath2);
}
}
return memento;
}