protected virtual IDisposable DrawRibbonQATMinibarSingle(RenderContext context,
Rectangle rect,
PaletteState state,
IPaletteRibbonBack palette,
bool composition,
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);
Color c5 = palette.GetRibbonBackColor5(state);
bool generate = true;
MementoRibbonQATMinibar cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonQATMinibar))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonQATMinibar(rect, c1, c2, c3, c4, c5);
memento = cache;
}
else
{
cache = (MementoRibbonQATMinibar)memento;
generate = !cache.UseCachedValues(rect, c1, c2, c3, c4, c5);
}
// Do we need to generate the contents of the cache?
if (generate)
{
// Dispose of existing values
cache.Dispose();
GraphicsPath borderPath = new GraphicsPath();
GraphicsPath topRight1 = new GraphicsPath();
GraphicsPath bottomLeft1 = new GraphicsPath();
// Find values needed for drawing the main border
int left = rect.X + 1;
int right = rect.Right - 3;
int top = rect.Y + 2;
int bottom = rect.Bottom - 3;
int middle = top + (bottom - top) / 2;
// Construct closed path for the main border
borderPath.AddLine(right - 8, bottom, left + 10.75f, bottom);
borderPath.AddLine(left + 10.75f, bottom, left + 10, bottom - 8f);
borderPath.AddLine(left + 10, bottom - 8f, left + 9, bottom - 11f);
borderPath.AddLine(left + 9, bottom - 11f, left + 8, bottom - 13f);
borderPath.AddLine(left + 8, bottom - 13f, left + 7, bottom - 15f);
borderPath.AddLine(left + 7, bottom - 15f, left + 1, top + 0.25f);
borderPath.AddLine(left + 1, top + 0.25f, left - 1, top + 0.25f);
borderPath.AddLine(left - 1, top + 0.25f, right - 8, top + 0.25f);
borderPath.AddLine(right - 8, top + 0.25f, right - 5, top + 1);
borderPath.AddLine(right - 5, top + 1, right - 1, top + 5);
borderPath.AddLine(right - 1, top + 5, right, top + 8);
borderPath.AddLine(right, top + 8, right + 0.40f, middle);
borderPath.AddLine(right + 0.40f, middle, right, bottom - 8.25f);
borderPath.AddLine(right, bottom - 8.25f, right - 1, bottom - 5.25f);
borderPath.AddLine(right - 1, bottom - 5.25f, right - 5, bottom - 1.25f);
borderPath.AddLine(right - 5, bottom - 1.25f, right - 8, bottom);
// Create the top right light paths
topRight1.AddLine(rect.Left - 1, rect.Top + 1.25f, rect.Right - 11, rect.Top + 1.25f);
topRight1.AddLine(rect.Right - 11, rect.Top + 1.5f, rect.Right - 8, rect.Top + 2.25f);
topRight1.AddLine(rect.Right - 8, rect.Top + 2.25f, rect.Right - 5, rect.Top + 5.75f);
// Create the bottom left light paths
bottomLeft1.AddLine(rect.Left + 10.75f, rect.Bottom - 11, rect.Left + 10.75f, rect.Bottom - 5);
bottomLeft1.AddLine(rect.Left + 10.75f, rect.Bottom - 5, rect.Left + 13, rect.Bottom - 2);
bottomLeft1.AddLine(rect.Left + 13, rect.Bottom - 2, rect.Right - 11, rect.Bottom - 2);
bottomLeft1.AddLine(rect.Right - 11, rect.Bottom - 2, rect.Right - 8.5f, rect.Bottom - 3);
bottomLeft1.AddLine(rect.Right - 8.5f, rect.Bottom - 3, rect.Right - 4.5f, rect.Bottom - 7);
bottomLeft1.AddLine(rect.Right - 4.5f, rect.Bottom - 7, rect.Right - 2.5f, rect.Bottom - 9);
bottomLeft1.AddLine(rect.Right - 2.5f, rect.Bottom - 9, rect.Right - 2, rect.Bottom - 11);
bottomLeft1.AddLine(rect.Right - 2, rect.Bottom - 11, rect.Right - 2, rect.Bottom - 15);
RectangleF gradientRect = rect;
gradientRect.Y += 1.5f;
gradientRect.Height *= 1.25f;
cache.innerBrush = new LinearGradientBrush(gradientRect, c2, c3, 90f);
cache.innerBrush.SetSigmaBellShape(0.5f);
cache.borderPath = borderPath;
cache.topRight1 = topRight1;
cache.bottomLeft1 = bottomLeft1;
cache.lightPen = new Pen(c4, 2f);
cache.borderPen = new Pen(c1);
cache.whitenPen = new Pen(c5);
}
using (AntiAlias aa = new AntiAlias(context.Graphics))
{
if (!composition)
{
// Draw the light borders
context.Graphics.DrawPath(cache.lightPen, cache.topRight1);
context.Graphics.DrawPath(cache.lightPen, cache.bottomLeft1);
// Draw the inside background and main border
context.Graphics.FillPath(cache.innerBrush, cache.borderPath);
context.Graphics.DrawPath(cache.borderPen, cache.borderPath);
// Overdraw top for lighter effect
context.Graphics.DrawLine(cache.whitenPen, rect.Left + 10, rect.Top + 2, rect.Right - 10, rect.Top + 2);
context.Graphics.DrawLine(cache.whitenPen, rect.Left + 12, rect.Top + 3, rect.Right - 8, rect.Top + 3);
context.Graphics.DrawLine(cache.whitenPen, rect.Left + 14, rect.Top + 4, rect.Right - 7, rect.Top + 4);
}
else
{
// Fill with a semi-transparent background/border
context.Graphics.FillPath(_compositionBrush, cache.borderPath);
context.Graphics.DrawPath(_compositionPen, cache.borderPath);
}
}
}
return memento;
}