/// <summary> /// Internal rendering method. /// </summary> protected virtual void DrawRibbonAppButtonLowerHalf(Graphics g, MementoRibbonAppButton memento, PaletteState state, Color bottomDark, Color bottomLight, Color bottomMedium) { Color[] colorsLowerHalf = new Color[] { bottomDark, bottomMedium, bottomLight, bottomLight, bottomMedium, bottomDark }; float[] posLowerHalf; if (state == PaletteState.Pressed) posLowerHalf = new float[] { 0.0f, 0.3f, 0.5f, 0.5f, 0.7f, 1.0f }; else posLowerHalf = new float[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f }; ColorBlend blendLowerHalf = new ColorBlend(); blendLowerHalf.Colors = colorsLowerHalf; blendLowerHalf.Positions = posLowerHalf; memento.brushLower.InterpolationColors = blendLowerHalf; g.FillPie(memento.brushLower, memento.rectLower.X, memento.rectLower.Y, memento.rectLower.Width, memento.rectLower.Height, 0, 180); }
/// <summary> /// Internal rendering method. /// </summary> protected virtual void DrawRibbonAppButtonUpperHalf(Graphics g, MementoRibbonAppButton memento, PaletteState state, Color topDark, Color bottomDark, Color topLight, Color topMedium, bool trackBorderAsPressed) { bool pressed = (state == PaletteState.Pressed); bool tracking = (state == PaletteState.Tracking); // Override tracking/pressed states? if (tracking && trackBorderAsPressed) { pressed = true; tracking = false; } if (!pressed) { Color[] colorsUpperHalf = new Color[] { topDark, topMedium, topLight, topLight, topMedium, topDark }; float[] posUpperHalf = new float[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f }; ColorBlend blendUpperHalf = new ColorBlend(); blendUpperHalf.Colors = colorsUpperHalf; blendUpperHalf.Positions = posUpperHalf; memento.brushUpper1.InterpolationColors = blendUpperHalf; g.FillPie(memento.brushUpper1, memento.rect.X, memento.rect.Y, memento.rect.Width, memento.rect.Height, 180, 180); } Color c1 = _whiten10; Color c2 = Color.FromArgb(100, topDark); if (tracking) { c1 = _whiten200; c2 = Color.FromArgb(200, bottomDark); } if (pressed) { c1 = Color.White; c2 = topDark; } using (LinearGradientBrush brushUpper2 = new LinearGradientBrush(memento.rect, c1, c2, LinearGradientMode.Vertical)) g.FillPie(brushUpper2, memento.rect.X, memento.rect.Y, memento.rect.Width, memento.rect.Height, 180, 180); }
/// <summary> /// Internal rendering method. /// </summary> protected virtual void DrawRibbonAppButtonGlowUpperBottom(Graphics g, MementoRibbonAppButton memento, PaletteState state, Color bottomLight, Color bottomMedium, Color bottomDark) { int lightTransparency = 50; int mediumTransparency = 50; if (state == PaletteState.Pressed || state == PaletteState.Tracking) { lightTransparency = 200; mediumTransparency = 200; } using (LinearGradientBrush brushUpperGlow = new LinearGradientBrush(memento.rectUpperGlow, Color.Transparent, Color.Transparent, LinearGradientMode.Horizontal)) { Color[] colorsUpperGlow = new Color[] { Color.FromArgb(180, bottomDark), Color.FromArgb(mediumTransparency, bottomMedium), Color.FromArgb(lightTransparency, bottomLight), Color.FromArgb(lightTransparency, bottomLight), Color.FromArgb(mediumTransparency, bottomMedium), Color.FromArgb(180, bottomDark) }; float[] posUpperGlow = new float[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f }; ColorBlend blendUpperGlow = new ColorBlend(); blendUpperGlow.Colors = colorsUpperGlow; blendUpperGlow.Positions = posUpperGlow; brushUpperGlow.InterpolationColors = blendUpperGlow; g.FillPie(brushUpperGlow, memento.rectUpperGlow.X, memento.rectUpperGlow.Y, memento.rectUpperGlow.Width, memento.rectUpperGlow.Height, 180, 180); } }
/// <summary> /// Internal rendering method. /// </summary> protected virtual void DrawRibbonAppButtonGlowCenter(Graphics g, MementoRibbonAppButton memento, PaletteState state, Color topLight, Color bottomLight) { using (LinearGradientBrush brushBottomGlow = new LinearGradientBrush(memento.rectBottomGlow, Color.FromArgb(50, Color.White), Color.FromArgb(30, Color.White), LinearGradientMode.Vertical)) { RectangleF rectBottomGlow = memento.rectBottomGlow; rectBottomGlow.X = memento.rect.X + (memento.rect.Width - rectBottomGlow.Width) / 2; rectBottomGlow.Y = memento.rect.Y + (memento.rect.Height - rectBottomGlow.Height - 2); if (state != PaletteState.Pressed) g.FillPie(brushBottomGlow, rectBottomGlow.X, rectBottomGlow.Y, rectBottomGlow.Width, rectBottomGlow.Height, 0, 360); if (state == PaletteState.Pressed) { rectBottomGlow.Height = memento.rect.Height * 0.2f; rectBottomGlow.Width = memento.rect.Width * 0.4f; rectBottomGlow.X = memento.rect.X + (memento.rect.Width - rectBottomGlow.Width) / 2; rectBottomGlow.Y = memento.rect.Y + (memento.rect.Height - rectBottomGlow.Height); using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(rectBottomGlow); using (PathGradientBrush pathGradient = new PathGradientBrush(path)) { pathGradient.CenterColor = topLight; pathGradient.SurroundColors = new Color[] { Color.FromArgb(100, bottomLight) }; g.FillEllipse(pathGradient, rectBottomGlow); } } } } }
/// <summary> /// Internal rendering method. /// </summary> protected virtual void DrawRibbonAppButtonBorder2(Graphics g, MementoRibbonAppButton memento, PaletteState state, Color bottomLight, bool trackBorderAsPressed) { bool pressed = (state == PaletteState.Pressed); bool tracking = (state == PaletteState.Tracking); // Override tracking/pressed states? if (tracking && trackBorderAsPressed) { pressed = true; tracking = false; } Color borderGlowColor; if (pressed) borderGlowColor = _whiten80; else if (tracking && !pressed) borderGlowColor = Color.FromArgb(200, bottomLight); else borderGlowColor = _whiten120; using (Pen p = new Pen(borderGlowColor)) g.DrawEllipse(p, memento.borderMain1); using (Pen p = new Pen(Color.FromArgb(100, 52, 59, 64))) g.DrawEllipse(p, memento.rect); if (pressed) { borderGlowColor = _whiten60; using (Pen p = new Pen(borderGlowColor)) g.DrawEllipse(p, memento.borderMain3); } borderGlowColor = (pressed ? _whiten50 : _whiten80); using (Pen p = new Pen(borderGlowColor)) g.DrawArc(p, memento.borderMain2, 180, 180); if (!pressed) { borderGlowColor = _whiten30; using (Pen p = new Pen(borderGlowColor)) g.DrawArc(p, memento.borderMain4, 180, 180); } if (tracking && !pressed) using (Pen p = new Pen(Color.FromArgb(100, borderGlowColor))) g.DrawEllipse(p, memento.rect); }
/// <summary> /// Internal rendering method. /// </summary> protected virtual void DrawRibbonAppButtonBorder1(Graphics g, MementoRibbonAppButton memento) { g.FillEllipse(_buttonBorder1Brush, memento.borderShadow1); g.FillEllipse(_buttonBorder2Brush, memento.borderShadow2); }
/// <summary> /// Internal rendering method. /// </summary> 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; }