protected virtual IDisposable DrawRibbonTabContextSelected(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);
bool generate = true;
MementoRibbonTabContextSelected cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonTabContextSelected))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonTabContextSelected(rect, c1, c2, orientation);
memento = cache;
}
else
{
cache = (MementoRibbonTabContextSelected)memento;
generate = !cache.UseCachedValues(rect, c1, c2, orientation);
}
// Do we need to generate the contents of the cache?
if (generate)
{
// Dispose of existing values
cache.Dispose();
switch (orientation)
{
case VisualOrientation.Top:
DrawRibbonTabContextSelectedTop(rect, c2, cache);
break;
case VisualOrientation.Left:
DrawRibbonTabContextSelectedLeft(rect, c2, cache);
break;
case VisualOrientation.Right:
DrawRibbonTabContextSelectedRight(rect, c2, cache);
break;
case VisualOrientation.Bottom:
DrawRibbonTabContextSelectedBottom(rect, c2, cache);
break;
}
cache.outsidePen = new Pen(c1);
cache.l1 = new Pen(Color.FromArgb(100, c2));
cache.l2 = new Pen(Color.FromArgb(75, c2));
cache.l3 = new Pen(Color.FromArgb(48, c2));
cache.bottomInnerPen = new Pen(Color.FromArgb(70, c2));
cache.bottomOuterPen = new Pen(Color.FromArgb(100, c2));
}
// Fill the interior using a gradient brush
context.Graphics.FillRectangle(Brushes.White, cache.interiorRect);
context.Graphics.FillRectangle(cache.insideBrush, cache.interiorRect);
// Draw the actual border
using (AntiAlias aa = new AntiAlias(context.Graphics))
context.Graphics.DrawPath(cache.outsidePen, cache.outsidePath);
switch (orientation)
{
case VisualOrientation.Top:
DrawRibbonTabContextSelectedTopDraw(rect, cache, context.Graphics);
break;
case VisualOrientation.Left:
DrawRibbonTabContextSelectedLeftDraw(rect, cache, context.Graphics);
break;
case VisualOrientation.Right:
DrawRibbonTabContextSelectedRightDraw(rect, cache, context.Graphics);
break;
case VisualOrientation.Bottom:
DrawRibbonTabContextSelectedBottomDraw(rect, cache, context.Graphics);
break;
}
}
return memento;
}