protected virtual IDisposable DrawRibbonAppTab(PaletteRibbonShape shape,
RenderContext context,
Rectangle rect,
PaletteState state,
Color baseColor1,
Color baseColor2,
IDisposable memento)
{
if ((rect.Width > 0) && (rect.Height > 0))
{
bool generate = true;
MementoRibbonAppTab cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonAppTab))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonAppTab(rect, baseColor1, baseColor2);
memento = cache;
}
else
{
cache = (MementoRibbonAppTab)memento;
generate = !cache.UseCachedValues(rect, baseColor1, baseColor2);
}
// Do we need to generate the contents of the cache?
if (generate)
{
// Dispose of existing values
cache.Dispose();
// Create common paths to all the app tab states
cache.GeneratePaths(rect, state);
cache.borderPen = new Pen(baseColor1);
// Create state specific colors/brushes/pens
switch (state)
{
case PaletteState.Normal:
cache.borderBrush = new SolidBrush(CommonHelper.MergeColors(baseColor1, 0.2f, baseColor2, 0.8f));
cache.insideFillBrush = new LinearGradientBrush(new RectangleF(rect.X, rect.Y + 1, rect.Width, rect.Height),
CommonHelper.MergeColors(baseColor1, 0.3f, baseColor2, 0.7f),
CommonHelper.MergeColors(baseColor1, 0.6f, baseColor2, 0.4f),
90f);
cache.insideFillBrush.SetSigmaBellShape(0.33f);
cache.highlightBrush.CenterColor = Color.FromArgb(64, Color.White);
break;
case PaletteState.Tracking:
cache.borderBrush = new SolidBrush(baseColor2);
cache.insideFillBrush = new LinearGradientBrush(new RectangleF(rect.X, rect.Y + 1, rect.Width, rect.Height),
CommonHelper.MergeColors(baseColor1, 0.3f, baseColor2, 0.7f),
CommonHelper.MergeColors(baseColor1, 0.6f, baseColor2, 0.4f),
90f);
cache.insideFillBrush.SetSigmaBellShape(0.33f);
cache.highlightBrush.CenterColor = Color.FromArgb(100, Color.White);
break;
case PaletteState.Tracking | PaletteState.FocusOverride:
cache.borderBrush = new SolidBrush(ControlPaint.LightLight(baseColor2));
cache.insideFillBrush = new LinearGradientBrush(new RectangleF(rect.X, rect.Y + 1, rect.Width, rect.Height),
CommonHelper.MergeColors(baseColor1, 0.3f, baseColor2, 0.7f),
CommonHelper.MergeColors(baseColor1, 0.6f, baseColor2, 0.4f),
90f);
cache.insideFillBrush.SetSigmaBellShape(0.33f);
cache.highlightBrush.CenterColor = ControlPaint.LightLight(baseColor2);
break;
case PaletteState.Pressed:
cache.borderBrush = new SolidBrush(CommonHelper.MergeColors(baseColor1, 0.5f, baseColor2, 0.5f));
cache.insideFillBrush = new LinearGradientBrush(new RectangleF(rect.X, rect.Y + 1, rect.Width, rect.Height),
CommonHelper.MergeColors(baseColor1, 0.3f, baseColor2, 0.7f),
CommonHelper.MergeColors(baseColor1, 0.75f, baseColor2, 0.25f),
90f);
cache.insideFillBrush.SetSigmaBellShape(0f);
cache.highlightBrush.CenterColor = Color.FromArgb(90, Color.White);
break;
}
}
// Fill the entire tab area and then add a border around the edge
context.Graphics.FillPath(cache.borderBrush, cache.borderFillPath);
// Draw the outside border
using (AntiAlias aa = new AntiAlias(context.Graphics))
context.Graphics.DrawPath(cache.borderPen, cache.borderPath);
// Fill inside area
context.Graphics.FillPath(cache.insideFillBrush, cache.insideFillPath);
// Draw highlight over bottom half
using(Clipping clip = new Clipping(context.Graphics, cache.insideFillPath))
context.Graphics.FillPath(cache.highlightBrush, cache.highlightPath);
}
return memento;
}