protected virtual IDisposable DrawRibbonAppButton(PaletteRibbonShape shape,
RenderContext context,
Rectangle rect,
PaletteState state,
IPaletteRibbonBack palette,
bool trackBorderAsPressed,
IDisposable memento)
{
// Reduce the area of the actual button as the extra space is used for shadow
rect.Width -= 3;
rect.Height -= 3;
if ((rect.Width > 0) && (rect.Height > 0))
{
// Get the colors from the palette
Color topLight = palette.GetRibbonBackColor1(state);
Color topMedium = palette.GetRibbonBackColor2(state);
Color topDark = palette.GetRibbonBackColor3(state);
Color bottomLight = palette.GetRibbonBackColor4(state);
Color bottomMedium = palette.GetRibbonBackColor5(state);
Color bottomDark = CommonHelper.MergeColors(topDark, 0.78f, Color.Empty, 0.22f);
bool generate = true;
MementoRibbonAppButton cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonAppButton))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonAppButton(rect, topLight, topMedium,
topDark, bottomLight, bottomMedium);
memento = cache;
}
else
{
cache = (MementoRibbonAppButton)memento;
generate = !cache.UseCachedValues(rect, topLight, topMedium,
topDark, bottomLight, bottomMedium);
}
// Do we need to generate the contents of the cache?
if (generate)
{
// Dispose of existing values
cache.Dispose();
cache.borderShadow1 = new RectangleF(rect.X, rect.Y, rect.Width + 2, rect.Height + 2);
cache.borderShadow2 = new RectangleF(rect.X, rect.Y, rect.Width + 1, rect.Height + 1);
cache.borderMain1 = new RectangleF(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2);
cache.borderMain2 = new RectangleF(cache.borderMain1.X + 1, cache.borderMain1.Y + 1, cache.borderMain1.Width - 2, cache.borderMain1.Height - 2);
cache.borderMain3 = new RectangleF(cache.borderMain1.X + 1, cache.borderMain1.Y + 1, cache.borderMain1.Width - 2, cache.borderMain1.Height - 2);
cache.borderMain4 = new RectangleF(cache.borderMain2.X, cache.borderMain2.Y + 1, cache.borderMain2.Width, cache.borderMain2.Height - 2);
cache.rectBottomGlow = new RectangleF(0, 0, rect.Width * 0.75f, rect.Height * 0.75f);
cache.rectLower = new RectangleF(rect.X, rect.Y - 1, rect.Width, rect.Height + 1);
cache.rectUpperGlow = new RectangleF();
cache.rectUpperGlow.Width = rect.Width - 4;
cache.rectUpperGlow.Height = rect.Height / 8;
cache.rectUpperGlow.Y = rect.Y + (rect.Height - cache.rectUpperGlow.Height) / 2;
cache.rectUpperGlow.X = rect.X + (rect.Width - cache.rectUpperGlow.Width) / 2;
cache.brushUpper1 = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, LinearGradientMode.Horizontal);
cache.brushLower = new LinearGradientBrush(cache.rectLower, Color.Transparent, Color.Transparent, LinearGradientMode.Horizontal);
}
using (AntiAlias aa = new AntiAlias(context.Graphics))
{
DrawRibbonAppButtonBorder1(context.Graphics, cache);
DrawRibbonAppButtonUpperHalf(context.Graphics, cache, state, topDark, bottomDark, topLight, topMedium, trackBorderAsPressed);
DrawRibbonAppButtonLowerHalf(context.Graphics, cache, state, bottomDark, bottomLight, bottomMedium);
DrawRibbonAppButtonGlowCenter(context.Graphics, cache, state, topLight, bottomLight);
DrawRibbonAppButtonGlowUpperBottom(context.Graphics, cache, state, bottomLight, bottomMedium, bottomDark);
DrawRibbonAppButtonBorder2(context.Graphics, cache, state, bottomLight, trackBorderAsPressed);
}
}
return memento;
}