DotNet 4.8.1 build of DotNetBar
This commit is contained in:
102
PROMS/DotNetBar Source Code/Metro/Rendering/DrawingHelpers.cs
Normal file
102
PROMS/DotNetBar Source Code/Metro/Rendering/DrawingHelpers.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal static class DrawingHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws the border.
|
||||
/// </summary>
|
||||
/// <param name="g">Graphics canvas.</param>
|
||||
/// <param name="bounds">Bounds for border.</param>
|
||||
/// <param name="borderThickness">Border thickness.</param>
|
||||
/// <param name="borderColor">Border color.</param>
|
||||
public static void DrawBorder(Graphics g, RectangleF bounds, Thickness borderThickness, BorderColors borderColor)
|
||||
{
|
||||
if (borderColor.IsEmpty || borderThickness.IsZero) return;
|
||||
|
||||
bounds.Width -= (float)borderThickness.Right;
|
||||
bounds.Height -= (float)borderThickness.Bottom;
|
||||
if (borderThickness.Right > 1) bounds.Width++;
|
||||
if (borderThickness.Bottom > 1) bounds.Height++;
|
||||
|
||||
System.Drawing.Drawing2D.SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
|
||||
|
||||
if (borderThickness.Left > 0d && !borderColor.Left.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(borderColor.Left, (float)borderThickness.Left))
|
||||
{
|
||||
pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
|
||||
g.DrawLine(pen, bounds.X, bounds.Y, bounds.X, bounds.Bottom);
|
||||
}
|
||||
}
|
||||
|
||||
if (borderThickness.Top > 0d && !borderColor.Top.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(borderColor.Top, (float)borderThickness.Top))
|
||||
{
|
||||
pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
|
||||
g.DrawLine(pen, bounds.X, bounds.Y, bounds.Right, bounds.Y);
|
||||
}
|
||||
}
|
||||
|
||||
if (borderThickness.Right > 0d && !borderColor.Right.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(borderColor.Right, (float)borderThickness.Right))
|
||||
{
|
||||
pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
|
||||
g.DrawLine(pen, bounds.Right, bounds.Y, bounds.Right, bounds.Bottom + (float)borderThickness.Bottom / 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (borderThickness.Bottom > 0d && !borderColor.Bottom.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(borderColor.Bottom, (float)borderThickness.Bottom))
|
||||
{
|
||||
pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
|
||||
g.DrawLine(pen, bounds.X, bounds.Bottom, bounds.Right, bounds.Bottom);
|
||||
}
|
||||
}
|
||||
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
/// <summary>
|
||||
/// Draws background.
|
||||
/// </summary>
|
||||
/// <param name="g">Graphics canvas.</param>
|
||||
/// <param name="bounds">Background bounds.</param>
|
||||
/// <param name="color">Background color</param>
|
||||
public static void DrawBackground(Graphics g, RectangleF bounds, string color)
|
||||
{
|
||||
if (string.IsNullOrEmpty(color)) return;
|
||||
|
||||
using (SolidBrush brush = new SolidBrush(ColorScheme.GetColor(color)))
|
||||
g.FillRectangle(brush, bounds);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deflates the rectangle by the border thickness.
|
||||
/// </summary>
|
||||
/// <param name="bounds">Rectangle.</param>
|
||||
/// <param name="borderThickness">Border thickness</param>
|
||||
/// <returns>Rectangle deflated by the border thickness</returns>
|
||||
public static RectangleF Deflate(RectangleF bounds, Thickness borderThickness)
|
||||
{
|
||||
if (borderThickness.IsZero) return bounds;
|
||||
|
||||
bounds.X += (float)borderThickness.Left;
|
||||
bounds.Width -= (float)(borderThickness.Left + borderThickness.Right);
|
||||
bounds.Y += (float)borderThickness.Top;
|
||||
bounds.Height -= (float)(borderThickness.Top + borderThickness.Bottom);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DevComponents.DotNetBar.Rendering;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroAppButtonPainter : Office2007ButtonItemPainter
|
||||
{
|
||||
public override Office2007ButtonItemColorTable GetColorTable(ButtonItem button, eButtonContainer buttonCont)
|
||||
{
|
||||
Office2007ColorTable colorTable = this.ColorTable;
|
||||
Office2007ButtonItemColorTable buttonColorTable = null;
|
||||
|
||||
if (button.CustomColorName != "")
|
||||
buttonColorTable = colorTable.ApplicationButtonColors[button.CustomColorName];
|
||||
|
||||
if (buttonColorTable == null)
|
||||
buttonColorTable = colorTable.ApplicationButtonColors[button.GetColorTableName()];
|
||||
|
||||
if (buttonColorTable == null && colorTable.ApplicationButtonColors.Count > 0)
|
||||
buttonColorTable = colorTable.ApplicationButtonColors[0];
|
||||
|
||||
if (buttonColorTable == null) // Return fall back static table
|
||||
buttonColorTable = DevComponents.DotNetBar.Metro.ColorTables.MetroOfficeColorTableInitializer.GetAppFallBackColorTable();
|
||||
|
||||
return buttonColorTable;
|
||||
}
|
||||
|
||||
protected override Rectangle GetDisplayRectangle(ButtonItem button)
|
||||
{
|
||||
Rectangle r = button.DisplayRectangle;
|
||||
if (button is ApplicationButton && ((ApplicationButton)button).IsMenuOverlayPaint)
|
||||
{
|
||||
r.Width += 4;
|
||||
r.Height += 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private static readonly int RibbonFormWidthOffset = 2;
|
||||
public override void PaintButtonText(ButtonItem button, ItemPaintArgs pa, Color textColor, CompositeImage image)
|
||||
{
|
||||
Rectangle r = GetDisplayRectangle(button);
|
||||
r.Inflate(-1, -1);
|
||||
r.Width--;
|
||||
|
||||
if (pa.ContainerControl.FindForm() is RibbonForm)
|
||||
r.Width -= RibbonFormWidthOffset+2;
|
||||
|
||||
if (button is ApplicationButton && ((ApplicationButton)button).IsMenuOverlayPaint)
|
||||
{
|
||||
r.Height -= 1;
|
||||
r.Width +=3;
|
||||
}
|
||||
|
||||
eTextFormat format = eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter | eTextFormat.HidePrefix;
|
||||
TextDrawing.DrawString(pa.Graphics, button.Text, pa.Font, textColor, r, format);
|
||||
}
|
||||
|
||||
protected override Color GetTextColor(ButtonItem button, ItemPaintArgs pa)
|
||||
{
|
||||
return base.GetTextColor(button, pa, GetColorTable(button, eButtonContainer.RibbonStrip));
|
||||
}
|
||||
|
||||
public override void PaintButtonImage(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle imagebounds)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(button.Text)) return;
|
||||
Rectangle r = GetDisplayRectangle(button);
|
||||
r.X = r.X + (r.Width - imagebounds.Width) / 2;
|
||||
r.Y = r.Y + (r.Height - imagebounds.Height) / 2;
|
||||
r.Width = imagebounds.Width;
|
||||
r.Height = imagebounds.Height;
|
||||
base.PaintButtonImage(button, pa, image, r);
|
||||
}
|
||||
|
||||
public override void PaintButtonBackground(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
|
||||
{
|
||||
Office2007ButtonItemColorTable colors = GetColorTable(button, eButtonContainer.RibbonStrip);
|
||||
Office2007ButtonItemStateColorTable stateColors = colors.Default;
|
||||
|
||||
if (button.IsMouseDown)
|
||||
stateColors = colors.Pressed;
|
||||
else if (button.IsMouseOver)
|
||||
stateColors = colors.MouseOver;
|
||||
Rectangle bounds = GetDisplayRectangle(button);
|
||||
bounds.Width--;
|
||||
//bounds.Height--;
|
||||
Graphics g = pa.Graphics;
|
||||
|
||||
if (pa.ContainerControl.FindForm() is RibbonForm)
|
||||
bounds.Width -= RibbonFormWidthOffset;
|
||||
|
||||
//using (GraphicsPath borderPath = DisplayHelp.GetRoundedRectanglePath(bounds, 0, 2, 2, 0))
|
||||
{
|
||||
//DisplayHelp.FillPath(g, borderPath, stateColors.Background);
|
||||
DisplayHelp.FillRectangle(g, bounds, stateColors.Background);
|
||||
|
||||
if (stateColors.BottomBackgroundHighlight != null && !stateColors.BottomBackgroundHighlight.IsEmpty)
|
||||
{
|
||||
Rectangle ellipse = new Rectangle(bounds.X - 12, bounds.Y + bounds.Height / 2 - 4, bounds.Width + 24, bounds.Height + 4);
|
||||
using (GraphicsPath path = new GraphicsPath())
|
||||
{
|
||||
path.AddEllipse(ellipse);
|
||||
using (PathGradientBrush brush = new PathGradientBrush(path))
|
||||
{
|
||||
brush.CenterColor = stateColors.BottomBackgroundHighlight.Start;
|
||||
brush.SurroundColors = new Color[] { stateColors.BottomBackgroundHighlight.End };
|
||||
brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, bounds.Bottom - 1);
|
||||
|
||||
g.FillRectangle(brush, bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stateColors.InnerBorder != null && !stateColors.InnerBorder.IsEmpty)
|
||||
{
|
||||
Rectangle innerBorder = bounds;
|
||||
innerBorder.Inflate(-1, -1);
|
||||
using (GraphicsPath innerBorderPath = new GraphicsPath())
|
||||
{
|
||||
innerBorderPath.AddRectangle(innerBorder);
|
||||
DisplayHelp.DrawGradientPath(g, innerBorderPath, innerBorder, stateColors.InnerBorder, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (stateColors.OuterBorder != null && !stateColors.OuterBorder.IsEmpty)
|
||||
DisplayHelp.DrawRectangle(g, stateColors.OuterBorder.Start, bounds); //DisplayHelp.DrawGradientPathBorder(g, borderPath, stateColors.OuterBorder, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
using DevComponents.DotNetBar.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroButtonItemPainter : Office2007ButtonItemPainter
|
||||
{
|
||||
private static RoundRectangleShapeDescriptor _DefaultMetroShape = new RoundRectangleShapeDescriptor(0);
|
||||
private static RoundRectangleShapeDescriptor _DefaultMobileShape = new RoundRectangleShapeDescriptor(2);
|
||||
protected override IShapeDescriptor GetButtonShape(ButtonItem button, ItemPaintArgs pa)
|
||||
{
|
||||
IShapeDescriptor shape = MetroButtonItemPainter.GetButtonShape(button);
|
||||
|
||||
if (pa.ContainerControl is ButtonX)
|
||||
shape = ((ButtonX)pa.ContainerControl).GetButtonShape();
|
||||
else if (pa.ContainerControl is NavigationBar)
|
||||
shape = ((NavigationBar)pa.ContainerControl).ButtonShape;
|
||||
return shape;
|
||||
}
|
||||
private static IShapeDescriptor GetButtonShape(ButtonItem button)
|
||||
{
|
||||
if (button.Shape != null)
|
||||
return button.Shape;
|
||||
else if(StyleManager.Style == eStyle.OfficeMobile2014)
|
||||
return _DefaultMobileShape;
|
||||
return _DefaultMetroShape;
|
||||
}
|
||||
|
||||
public override DotNetBar.Rendering.Office2007ButtonItemColorTable GetColorTable(ButtonItem button, eButtonContainer buttonCont)
|
||||
{
|
||||
if (buttonCont == eButtonContainer.MetroTabStrip)
|
||||
{
|
||||
Office2007ColorTable colorTable = this.ColorTable;
|
||||
object st = null;
|
||||
if (colorTable.ContextualTables.TryGetValue(Office2007ColorTable.GetContextualKey(ButtonColorTableType, "MetroTabStrip"), out st))
|
||||
return (Office2007ButtonItemColorTable)st;
|
||||
}
|
||||
else if (buttonCont == eButtonContainer.NavigationPane)
|
||||
{
|
||||
Office2007ColorTable colorTable = this.ColorTable;
|
||||
object st = null;
|
||||
if (colorTable.ContextualTables.TryGetValue(Office2007ColorTable.GetContextualKey(ButtonColorTableType, "NavigationBar"), out st))
|
||||
return (Office2007ButtonItemColorTable)st;
|
||||
}
|
||||
|
||||
return base.GetColorTable(button, buttonCont);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,161 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using DevComponents.DotNetBar.Rendering;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Text;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroCaptionItemPainter : Office2007SystemCaptionItemPainter
|
||||
{
|
||||
#region Internal Implementation
|
||||
protected override Rectangle GetSignRect(Rectangle r, Size s)
|
||||
{
|
||||
if (r.Height < 10)
|
||||
return Rectangle.Empty;
|
||||
|
||||
return new Rectangle(r.X + (r.Width - s.Width) / 2, r.Y + (int)Math.Ceiling((double)(r.Height - s.Height)/2), s.Width, s.Height);
|
||||
//return new Rectangle(r.X + (r.Width - s.Width) / 2, r.Bottom - r.Height / 4 - s.Height - 3, s.Width, s.Height);
|
||||
}
|
||||
|
||||
protected override void PaintMinimize(Graphics g, Rectangle r, Office2007SystemButtonStateColorTable ct, bool isEnabled, LinearGradientColorTable foregroundOverride)
|
||||
{
|
||||
Size s = new Size(Dpi.Width9, Dpi.Height2);
|
||||
Rectangle rm = GetSignRect(r, s);
|
||||
LinearGradientColorTable foreground = foregroundOverride ?? ct.Foreground;
|
||||
if (isEnabled)
|
||||
DisplayHelp.FillRectangle(g, rm, foreground);
|
||||
else
|
||||
DisplayHelp.FillRectangle(g, rm, GetDisabledColor(foreground.Start), GetDisabledColor(foreground.End), foreground.GradientAngle);
|
||||
}
|
||||
|
||||
internal static Color GetDisabledColor(Color color)
|
||||
{
|
||||
if (color.IsEmpty) return color;
|
||||
return Color.FromArgb(128, color);
|
||||
}
|
||||
|
||||
|
||||
protected override void PaintRestore(Graphics g, Rectangle r, Office2007SystemButtonStateColorTable ct, bool isEnabled, LinearGradientColorTable foregroundOverride)
|
||||
{
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
|
||||
Size s = new Size(Dpi.Width10, Dpi.Height10);
|
||||
Rectangle rm = GetSignRect(r, s);
|
||||
Region oldClip = g.Clip;
|
||||
|
||||
LinearGradientColorTable foreground = foregroundOverride ?? ct.Foreground;
|
||||
LinearGradientColorTable buttonTable = isEnabled ? foreground : new LinearGradientColorTable(GetDisabledColor(foreground.Start), GetDisabledColor(foreground.End), foreground.GradientAngle);
|
||||
using (Brush fill = DisplayHelp.CreateBrush(rm, foreground))
|
||||
{
|
||||
Rectangle inner = new Rectangle(rm.X + Dpi.Width4, rm.Y + Dpi.Width2, Dpi.Width6, Dpi.Height4);
|
||||
g.SetClip(inner, CombineMode.Exclude);
|
||||
g.SetClip(new Rectangle(rm.X + Dpi.Width1, rm.Y + Dpi.Height5, Dpi.Width6, Dpi.Height4), CombineMode.Exclude);
|
||||
|
||||
g.FillRectangle(fill, rm.X + Dpi.Width3, rm.Y, Dpi.Width8, Dpi.Height7);
|
||||
g.ResetClip();
|
||||
|
||||
inner = new Rectangle(rm.X + Dpi.Width1, rm.Y + Dpi.Height5, Dpi.Width6, Dpi.Height4);
|
||||
g.SetClip(inner, CombineMode.Exclude);
|
||||
g.FillRectangle(fill, rm.X, rm.Y + Dpi.Height3, Dpi.Width8, Dpi.Height7);
|
||||
g.ResetClip();
|
||||
}
|
||||
if (oldClip != null)
|
||||
{
|
||||
g.Clip = oldClip;
|
||||
oldClip.Dispose();
|
||||
}
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
|
||||
protected override void PaintMaximize(Graphics g, Rectangle r, Office2007SystemButtonStateColorTable ct, bool isEnabled, LinearGradientColorTable foregroundOverride)
|
||||
{
|
||||
Size s = new Size(Dpi.Width10, Dpi.Height10);
|
||||
Rectangle rm = GetSignRect(r, s);
|
||||
Region oldClip = g.Clip;
|
||||
|
||||
Rectangle inner = new Rectangle(rm.X + Dpi.Width1, rm.Y + Dpi.Height3, (ct.DarkShade.IsEmpty ? Dpi.Width8 : Dpi.Width7), (ct.DarkShade.IsEmpty ? Dpi.Height6 : Dpi.Height5));
|
||||
g.SetClip(inner, CombineMode.Exclude);
|
||||
LinearGradientColorTable foreground = foregroundOverride ?? ct.Foreground;
|
||||
if (isEnabled)
|
||||
DisplayHelp.FillRectangle(g, rm, foreground);
|
||||
else
|
||||
DisplayHelp.FillRectangle(g, rm, GetDisabledColor(foreground.Start), GetDisabledColor(foreground.End), foreground.GradientAngle);
|
||||
|
||||
if (oldClip != null)
|
||||
{
|
||||
g.Clip = oldClip;
|
||||
oldClip.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PaintClose(Graphics g, Rectangle r, Office2007SystemButtonStateColorTable ct, bool isEnabled, LinearGradientColorTable foregroundOverride)
|
||||
{
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.Default;
|
||||
|
||||
Size s = new Size(Dpi.Width8, Dpi.Height8);
|
||||
Rectangle rm = GetSignRect(r, s);
|
||||
|
||||
Rectangle r1 = rm;
|
||||
r1.Offset(0, -1);
|
||||
|
||||
LinearGradientColorTable foreground = foregroundOverride ?? ct.Foreground;
|
||||
if (isEnabled)
|
||||
{
|
||||
using (Pen pen = new Pen(foreground.Start, Dpi.Width2))
|
||||
{
|
||||
g.DrawLine(pen, r1.X, r1.Y, r1.Right, r1.Bottom);
|
||||
g.DrawLine(pen, r1.Right, r1.Y, r1.X, r1.Bottom);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (Pen pen = new Pen(GetDisabledColor(foreground.Start), Dpi.Width2))
|
||||
{
|
||||
g.DrawLine(pen, r1.X, r1.Y, r1.Right, r1.Bottom);
|
||||
g.DrawLine(pen, r1.Right, r1.Y, r1.X, r1.Bottom);
|
||||
}
|
||||
}
|
||||
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
|
||||
protected override void PaintHelp(Graphics g, Rectangle r, Office2007SystemButtonStateColorTable ct, bool isEnabled, LinearGradientColorTable foregroundOverride)
|
||||
{
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
TextRenderingHint th = g.TextRenderingHint;
|
||||
g.SmoothingMode = SmoothingMode.Default;
|
||||
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||
#if FRAMEWORK20
|
||||
using (Font font = new Font(SystemFonts.DefaultFont, FontStyle.Bold))
|
||||
#else
|
||||
using(Font font = new Font("Arial", 10, FontStyle.Bold))
|
||||
#endif
|
||||
{
|
||||
Size s = TextDrawing.MeasureString(g, "?", font);
|
||||
s.Width += Dpi.Width4;
|
||||
s.Height -= Dpi.Width2;
|
||||
Rectangle rm = GetSignRect(r, s);
|
||||
|
||||
rm.Offset(1, 1);
|
||||
Color color = isEnabled ? ct.DarkShade : GetDisabledColor(ct.DarkShade);
|
||||
using (SolidBrush brush = new SolidBrush(color))
|
||||
g.DrawString("?", font, brush, rm);
|
||||
rm.Offset(-1, -1);
|
||||
LinearGradientColorTable foreground = foregroundOverride ?? ct.Foreground;
|
||||
color = isEnabled ? foreground.Start : GetDisabledColor(foreground.Start);
|
||||
using (SolidBrush brush = new SolidBrush(color))
|
||||
g.DrawString("?", font, brush, rm);
|
||||
|
||||
}
|
||||
g.SmoothingMode = sm;
|
||||
g.TextRenderingHint = th;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using DevComponents.DotNetBar.Metro.ColorTables;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroFormRenderer : MetroRenderer
|
||||
{
|
||||
public override void Render(MetroRendererInfo renderingInfo)
|
||||
{
|
||||
MetroAppForm form = renderingInfo.Control as MetroAppForm;
|
||||
BorderOverlay overlay = renderingInfo.Control as BorderOverlay;
|
||||
if (form == null && overlay != null) form = overlay.Parent as MetroAppForm;
|
||||
Graphics g = renderingInfo.PaintEventArgs.Graphics;
|
||||
MetroAppFormColorTable fct = renderingInfo.ColorTable.MetroAppForm;
|
||||
|
||||
Thickness borderThickness = form.BorderThickness;
|
||||
BorderColors colors = form.BorderColor;
|
||||
if (borderThickness.IsZero && colors.IsEmpty)
|
||||
{
|
||||
// Get it from table
|
||||
borderThickness = form.IsGlassEnabled ? fct.BorderThickness : fct.BorderPlainThickness;
|
||||
colors = form.IsActive ? fct.BorderColors : fct.BorderColorsInactive;
|
||||
}
|
||||
|
||||
if (overlay == null) // If overlay is being rendered it does not need fill
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(form.BackColor))
|
||||
g.FillRectangle(brush, new Rectangle(0, 0, form.Width, form.Height));
|
||||
}
|
||||
|
||||
|
||||
if (!borderThickness.IsZero && !colors.IsEmpty)
|
||||
{
|
||||
RectangleF br = new RectangleF(0, 0, form.Width, form.Height);
|
||||
DrawingHelpers.DrawBorder(g, br, borderThickness, colors);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroKeyTipsPainter : Office2007KeyTipsPainter
|
||||
{
|
||||
public override void PaintKeyTips(KeyTipsRendererEventArgs e)
|
||||
{
|
||||
Rectangle r = e.Bounds;
|
||||
r.Inflate(1, 1);
|
||||
|
||||
Color textColor = ColorTable.KeyTips.KeyTipText;
|
||||
Color backColor = ColorTable.KeyTips.KeyTipBackground;
|
||||
|
||||
if (e.ReferenceObject is BaseItem && !((BaseItem)e.ReferenceObject).Enabled)
|
||||
{
|
||||
int alpha = 128;
|
||||
backColor = Color.FromArgb(alpha, backColor);
|
||||
textColor = Color.FromArgb(alpha, textColor);
|
||||
}
|
||||
|
||||
Graphics g = e.Graphics;
|
||||
string keyTip = e.KeyTip;
|
||||
Font font = e.Font;
|
||||
|
||||
using (SolidBrush brush = new SolidBrush(backColor))
|
||||
DisplayHelp.FillRoundedRectangle(g, brush, r, 1);
|
||||
using (Pen pen = new Pen(textColor, 1))
|
||||
DisplayHelp.DrawRoundedRectangle(g, pen, r, 1);
|
||||
|
||||
//DisplayHelp.FillRectangle(g, r, backColor);
|
||||
//using (Pen pen = new Pen(textColor, 1))
|
||||
// DisplayHelp.DrawRoundedRectangle(g, pen, r, 2);
|
||||
TextDrawing.DrawString(g, keyTip, font, textColor, r, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
|
||||
}
|
||||
}
|
||||
}
|
229
PROMS/DotNetBar Source Code/Metro/Rendering/MetroRender.cs
Normal file
229
PROMS/DotNetBar Source Code/Metro/Rendering/MetroRender.cs
Normal file
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using DevComponents.DotNetBar.Metro.ColorTables;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
public static class MetroRender
|
||||
{
|
||||
private static MetroRenderer[] _Renderers;
|
||||
static MetroRender()
|
||||
{
|
||||
_Renderers = new MetroRenderer[Enum.GetNames(typeof(Renderers)).Length];
|
||||
_Renderers[(int)Renderers.MetroForm] = new MetroFormRenderer();
|
||||
_Renderers[(int)Renderers.MetroTabItem] = new MetroTabItemPainter();
|
||||
_Renderers[(int)Renderers.MetroTabStrip] = new MetroTabStripPainter();
|
||||
_Renderers[(int)Renderers.MetroStatusBar] = new MetroStatusBarPainter();
|
||||
_Renderers[(int)Renderers.MetroToolbar] = new MetroToolbarPainter();
|
||||
_Renderers[(int)Renderers.MetroTileItem] = new MetroTileItemPainter();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the MetroTileItem.
|
||||
/// </summary>
|
||||
/// <param name="item">MetroTileItem to render.</param>
|
||||
/// <param name="e">Rendering event arguments.</param>
|
||||
public static void Paint(MetroTileItem item, ItemPaintArgs pa)
|
||||
{
|
||||
MetroRenderer renderer = GetRenderer(Renderers.MetroTileItem);
|
||||
renderer.Render(GetRenderingInfo(item, pa, GetColorTable()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the MetroForm.
|
||||
/// </summary>
|
||||
/// <param name="form">Form to render.</param>
|
||||
/// <param name="e">Rendering event arguments.</param>
|
||||
public static void Paint(MetroAppForm form, PaintEventArgs e)
|
||||
{
|
||||
MetroRenderer renderer = GetRenderer(Renderers.MetroForm);
|
||||
renderer.Render(GetRenderingInfo(form, e, GetColorTable()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the MetroForm.
|
||||
/// </summary>
|
||||
/// <param name="formOverlay">Form to render.</param>
|
||||
/// <param name="e">Rendering event arguments.</param>
|
||||
internal static void Paint(BorderOverlay formOverlay, PaintEventArgs e)
|
||||
{
|
||||
MetroRenderer renderer = GetRenderer(Renderers.MetroForm);
|
||||
renderer.Render(GetRenderingInfo(formOverlay, e, GetColorTable()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the MetroTabItem.
|
||||
/// </summary>
|
||||
/// <param name="tab">Form to render.</param>
|
||||
/// <param name="e">Rendering event arguments.</param>
|
||||
public static void Paint(MetroTabItem tab, ItemPaintArgs pa)
|
||||
{
|
||||
MetroRenderer renderer = GetRenderer(Renderers.MetroTabItem);
|
||||
renderer.Render(GetRenderingInfo(tab, pa, GetColorTable()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the MetroTabStrip
|
||||
/// </summary>
|
||||
/// <param name="tabStrip">TabStrip to render.</param>
|
||||
/// <param name="pa">Paint args</param>
|
||||
public static void Paint(MetroTabStrip tabStrip, ItemPaintArgs pa)
|
||||
{
|
||||
MetroRenderer renderer = GetRenderer(Renderers.MetroTabStrip);
|
||||
MetroRendererInfo info = GetRenderingInfo(tabStrip, pa, GetColorTable());
|
||||
renderer.Render(info);
|
||||
}
|
||||
/// <summary>
|
||||
/// Renders the MetroStatusBar.
|
||||
/// </summary>
|
||||
/// <param name="bar">Status bar to render</param>
|
||||
/// <param name="pa">Paint args</param>
|
||||
public static void Paint(MetroStatusBar bar, ItemPaintArgs pa)
|
||||
{
|
||||
MetroRenderer renderer = GetRenderer(Renderers.MetroStatusBar);
|
||||
renderer.Render(GetRenderingInfo(bar, pa, GetColorTable()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the MetroStatusBar.
|
||||
/// </summary>
|
||||
/// <param name="bar">Status bar to render</param>
|
||||
/// <param name="pa">Paint args</param>
|
||||
public static void Paint(MetroToolbar bar, ItemPaintArgs pa)
|
||||
{
|
||||
MetroRenderer renderer = GetRenderer(Renderers.MetroToolbar);
|
||||
renderer.Render(GetRenderingInfo(bar, pa, GetColorTable()));
|
||||
}
|
||||
|
||||
private static MetroRenderer GetRenderer(Renderers renderer)
|
||||
{
|
||||
return _Renderers[(int)renderer];
|
||||
}
|
||||
|
||||
private static MetroRendererInfo _RenderingInfo = new MetroRendererInfo();
|
||||
private static MetroRendererInfo GetRenderingInfo(Control control, PaintEventArgs e, MetroColorTable colorTable)
|
||||
{
|
||||
_RenderingInfo.Control = control;
|
||||
_RenderingInfo.PaintEventArgs = e;
|
||||
_RenderingInfo.ColorTable = colorTable;
|
||||
_RenderingInfo.DefaultFont = control.Font;
|
||||
_RenderingInfo.RightToLeft = (control.RightToLeft == RightToLeft.Yes);
|
||||
return _RenderingInfo;
|
||||
}
|
||||
private static MetroRendererInfo GetRenderingInfo(Control control, ItemPaintArgs e, MetroColorTable colorTable)
|
||||
{
|
||||
_RenderingInfo.Control = control;
|
||||
_RenderingInfo.PaintEventArgs = e.PaintEventArgs;
|
||||
_RenderingInfo.DefaultFont = e.Font;
|
||||
_RenderingInfo.ColorTable = colorTable;
|
||||
_RenderingInfo.RightToLeft = e.RightToLeft;
|
||||
_RenderingInfo.ItemPaintArgs = e;
|
||||
return _RenderingInfo;
|
||||
}
|
||||
private static MetroRendererInfo GetRenderingInfo(MetroTabStrip control, ItemPaintArgs e, MetroColorTable colorTable)
|
||||
{
|
||||
_RenderingInfo.Control = control;
|
||||
_RenderingInfo.PaintEventArgs = e.PaintEventArgs;
|
||||
_RenderingInfo.DefaultFont = e.Font;
|
||||
if (e.Font.Bold)
|
||||
_RenderingInfo.DefaultPlainFont = new Font(e.Font, FontStyle.Regular);
|
||||
_RenderingInfo.ColorTable = colorTable;
|
||||
_RenderingInfo.RightToLeft = e.RightToLeft;
|
||||
_RenderingInfo.ItemPaintArgs = e;
|
||||
return _RenderingInfo;
|
||||
}
|
||||
private static MetroRendererInfo GetRenderingInfo(object control, ItemPaintArgs e, MetroColorTable colorTable)
|
||||
{
|
||||
_RenderingInfo.Control = control;
|
||||
_RenderingInfo.PaintEventArgs = e.PaintEventArgs;
|
||||
_RenderingInfo.DefaultFont = e.Font;
|
||||
_RenderingInfo.ColorTable = colorTable;
|
||||
_RenderingInfo.RightToLeft = e.RightToLeft;
|
||||
_RenderingInfo.ItemPaintArgs = e;
|
||||
return _RenderingInfo;
|
||||
}
|
||||
|
||||
private static MetroColorTable _ColorTable = null;
|
||||
public static MetroColorTable GetColorTable()
|
||||
{
|
||||
if (_ColorTable == null)
|
||||
{
|
||||
UpdateColorTable(MetroColorGeneratorParameters.Default);
|
||||
}
|
||||
return _ColorTable;
|
||||
}
|
||||
|
||||
internal static void UpdateColorTable(MetroColorGeneratorParameters colorParams)
|
||||
{
|
||||
if (StyleManager.IsVisualStudio2012(StyleManager.Style))
|
||||
_ColorTable = VisualStudio2012ColorTableInitializer.CreateColorTable(colorParams);
|
||||
else if (StyleManager.Style == eStyle.OfficeMobile2014)
|
||||
_ColorTable = OfficeMobile2014MetroInitializer.CreateColorTable(colorParams);
|
||||
else if (StyleManager.Style == eStyle.Office2016)
|
||||
_ColorTable = Office2016MetroInitializer.CreateColorTable(colorParams);
|
||||
else
|
||||
_ColorTable = MetroColorTableInitializer.CreateColorTable(colorParams);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines class for passing rendering information to renderer.
|
||||
/// </summary>
|
||||
public class MetroRendererInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the control to render.
|
||||
/// </summary>
|
||||
public object Control = null;
|
||||
/// <summary>
|
||||
/// Gets or sets the paint event arguments to use to render out control.
|
||||
/// </summary>
|
||||
public PaintEventArgs PaintEventArgs = null;
|
||||
/// <summary>
|
||||
/// Gets or sets the current color table.
|
||||
/// </summary>
|
||||
public MetroColorTable ColorTable;
|
||||
/// <summary>
|
||||
/// Gets or sets default font.
|
||||
/// </summary>
|
||||
public Font DefaultFont = SystemFonts.DefaultFont;
|
||||
/// <summary>
|
||||
/// Gets or sets default plain font.
|
||||
/// </summary>
|
||||
public Font DefaultPlainFont = null;
|
||||
/// <summary>
|
||||
/// Gets or sets right-to-left setting.
|
||||
/// </summary>
|
||||
public bool RightToLeft = false;
|
||||
/// <summary>
|
||||
/// Gets or sets the paint information for items.
|
||||
/// </summary>
|
||||
public ItemPaintArgs ItemPaintArgs = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Abstract renderer for rendering Metro-UI controls.
|
||||
/// </summary>
|
||||
public abstract class MetroRenderer
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Renders the
|
||||
/// </summary>
|
||||
/// <param name="renderingInfo"></param>
|
||||
public abstract void Render(MetroRendererInfo renderingInfo);
|
||||
}
|
||||
|
||||
public enum Renderers : int
|
||||
{
|
||||
MetroForm,
|
||||
MetroTabItem,
|
||||
MetroTabStrip,
|
||||
MetroStatusBar,
|
||||
MetroToolbar,
|
||||
MetroTileItem
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroRibbonTabGroupPainter : Office2007RibbonTabGroupPainter
|
||||
{
|
||||
protected override void PaintTabGroupBackground(System.Drawing.Graphics g, DevComponents.DotNetBar.Rendering.Office2007RibbonTabGroupColorTable colorTable, System.Drawing.Rectangle bounds, System.Drawing.Rectangle groupBounds, bool glassEnabled)
|
||||
{
|
||||
DisplayHelp.FillRectangle(g, groupBounds, colorTable.Background);
|
||||
|
||||
if (StyleManager.Style != eStyle.Office2016)
|
||||
{
|
||||
Rectangle top = new Rectangle(groupBounds.X, groupBounds.Y, groupBounds.Width, 3);
|
||||
DisplayHelp.FillRectangle(g, top, colorTable.Border);
|
||||
if (StyleManager.Style == eStyle.OfficeMobile2014)
|
||||
{
|
||||
DisplayHelp.DrawGradientLine(g, groupBounds.X, groupBounds.Y, groupBounds.X, 24, colorTable.Border, 1);
|
||||
DisplayHelp.DrawGradientLine(g, groupBounds.Right - 1, groupBounds.Y, groupBounds.Right - 1, 24, colorTable.Border, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,234 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DevComponents.DotNetBar.ScrollBar;
|
||||
using DevComponents.DotNetBar.Rendering;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroScrollBarPainter : ScrollBarPainter, IOffice2007Painter
|
||||
{
|
||||
#region Private Variables
|
||||
private Office2007ColorTable m_ColorTable = null;
|
||||
private bool m_AppStyleScrollBar = false;
|
||||
private Presentation.ShapeBorder m_ThumbOuterBorder = new Presentation.ShapeBorder(1);
|
||||
private Presentation.ShapeBorder m_ThumbInnerBorder = new Presentation.ShapeBorder(1);
|
||||
private Presentation.ShapeFill m_ThumbInnerFill = new Presentation.ShapeFill();
|
||||
private Presentation.ShapeFill m_ThumbSignFill = new Presentation.ShapeFill();
|
||||
private Presentation.Shape m_ThumbShape = null;
|
||||
private Presentation.ShapePath m_ThumbSignShape = null;
|
||||
private Size m_ThumbSignSize = new Size(9, 5);
|
||||
|
||||
private Presentation.Shape m_TrackShape = null;
|
||||
private Presentation.ShapeBorder m_TrackOuterBorder = new Presentation.ShapeBorder(1);
|
||||
private Presentation.ShapeBorder m_TrackInnerBorder = new Presentation.ShapeBorder(1);
|
||||
private Presentation.ShapeFill m_TrackInnerFill = new Presentation.ShapeFill();
|
||||
|
||||
private Presentation.Shape m_BackgroundShape = null;
|
||||
private Presentation.ShapeBorder m_BackgroundBorder = new Presentation.ShapeBorder(1);
|
||||
private Presentation.ShapeFill m_BackgroundFill = new Presentation.ShapeFill();
|
||||
#endregion
|
||||
|
||||
#region IOffice2007Painter Members
|
||||
|
||||
public DevComponents.DotNetBar.Rendering.Office2007ColorTable ColorTable
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ColorTable;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_ColorTable = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Implemementation
|
||||
public MetroScrollBarPainter()
|
||||
{
|
||||
m_ThumbShape = GetThumbShape();
|
||||
m_TrackShape = GetTrackShape();
|
||||
m_BackgroundShape = GetBackgroundShape();
|
||||
}
|
||||
|
||||
public override void PaintThumb(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, eScrollThumbPosition position, eScrollBarState state)
|
||||
{
|
||||
Office2007ScrollBarStateColorTable ct = GetColorTable(state);
|
||||
if (ct == null) return;
|
||||
|
||||
// Initialize Colors
|
||||
m_ThumbOuterBorder.Width = Dpi.Width1;
|
||||
m_ThumbOuterBorder.Apply(ct.ThumbOuterBorder);
|
||||
m_ThumbSignFill.Apply(ct.ThumbSignBackground);
|
||||
|
||||
m_ThumbSignShape.Path = GetThumbSignPath(position);
|
||||
m_ThumbShape.Paint(new Presentation.ShapePaintInfo(g, bounds));
|
||||
m_ThumbSignShape.Path.Dispose();
|
||||
m_ThumbSignShape.Path = null;
|
||||
}
|
||||
|
||||
private Office2007ScrollBarStateColorTable GetColorTable(eScrollBarState state)
|
||||
{
|
||||
Office2007ScrollBarColorTable csb = m_AppStyleScrollBar ? m_ColorTable.AppScrollBar : m_ColorTable.ScrollBar;
|
||||
if (state == eScrollBarState.Normal)
|
||||
return csb.Default;
|
||||
else if (state == eScrollBarState.Disabled)
|
||||
return csb.Disabled;
|
||||
else if (state == eScrollBarState.ControlMouseOver)
|
||||
return csb.MouseOverControl;
|
||||
else if (state == eScrollBarState.PartMouseOver)
|
||||
return csb.MouseOver;
|
||||
else if (state == eScrollBarState.Pressed)
|
||||
return csb.Pressed;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void PaintTrackHorizontal(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, eScrollBarState state)
|
||||
{
|
||||
Office2007ScrollBarStateColorTable ct = GetColorTable(state);
|
||||
if (ct == null) return;
|
||||
|
||||
// Apply Colors...
|
||||
// Apply Colors...
|
||||
m_TrackInnerFill.Apply(ct.TrackSignBackground);
|
||||
m_TrackOuterBorder.Width = Dpi.Width1;
|
||||
m_TrackOuterBorder.Apply(ct.TrackOuterBorder);
|
||||
m_TrackShape.Paint(new Presentation.ShapePaintInfo(g, bounds));
|
||||
}
|
||||
|
||||
public override void PaintTrackVertical(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, eScrollBarState state)
|
||||
{
|
||||
Office2007ScrollBarStateColorTable ct = GetColorTable(state);
|
||||
if (ct == null) return;
|
||||
|
||||
// Apply Colors...
|
||||
m_TrackInnerFill.Apply(ct.TrackSignBackground);
|
||||
m_TrackOuterBorder.Apply(ct.TrackOuterBorder);
|
||||
m_TrackShape.Paint(new Presentation.ShapePaintInfo(g, bounds));
|
||||
}
|
||||
|
||||
public override void PaintBackground(Graphics g, Rectangle bounds, eScrollBarState state, bool horizontal, bool sideBorderOnly, bool rtl)
|
||||
{
|
||||
Office2007ScrollBarStateColorTable ct = GetColorTable(state);
|
||||
if (ct == null) return;
|
||||
|
||||
// Apply Colors...
|
||||
m_BackgroundBorder.Width = Dpi.Width1;
|
||||
if (sideBorderOnly)
|
||||
m_BackgroundBorder.Apply(null);
|
||||
else
|
||||
m_BackgroundBorder.Apply(ct.Border);
|
||||
|
||||
m_BackgroundFill.Apply(ct.Background);
|
||||
m_BackgroundFill.GradientAngle = horizontal ? 90 : 0;
|
||||
|
||||
m_BackgroundShape.Paint(new Presentation.ShapePaintInfo(g, bounds));
|
||||
if (sideBorderOnly && !ct.Border.Start.IsEmpty)
|
||||
{
|
||||
if (horizontal)
|
||||
DisplayHelp.DrawLine(g, bounds.X, bounds.Y, bounds.Right, bounds.Y, ct.Border.Start, Dpi.Width1);
|
||||
else
|
||||
{
|
||||
if (rtl)
|
||||
DisplayHelp.DrawLine(g, bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Bottom, ct.Border.Start, Dpi.Width1);
|
||||
else
|
||||
DisplayHelp.DrawLine(g, 0, bounds.Y, 0, bounds.Bottom, ct.Border.Start, Dpi.Width1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Presentation.Shape GetBackgroundShape()
|
||||
{
|
||||
Presentation.Rectangle b = new Presentation.Rectangle();
|
||||
b.Border = m_BackgroundBorder;
|
||||
b.Fill = m_BackgroundFill;
|
||||
return b;
|
||||
}
|
||||
|
||||
private Presentation.Shape GetThumbShape()
|
||||
{
|
||||
Presentation.Rectangle thumb = new Presentation.Rectangle();
|
||||
thumb.Border = m_ThumbOuterBorder;
|
||||
thumb.Padding = new Presentation.PaddingInfo(1,1,1,1);
|
||||
m_ThumbSignShape = new Presentation.ShapePath();
|
||||
m_ThumbSignShape.Fill = m_ThumbSignFill;
|
||||
thumb.Children.Add(m_ThumbSignShape);
|
||||
|
||||
return thumb;
|
||||
}
|
||||
|
||||
private Presentation.Shape GetTrackShape()
|
||||
{
|
||||
Presentation.Rectangle thumb = new Presentation.Rectangle();
|
||||
thumb.Padding = new DevComponents.DotNetBar.Presentation.PaddingInfo(1, 1, 1, 1);
|
||||
thumb.Border = m_TrackOuterBorder;
|
||||
Presentation.Rectangle innerRect = new Presentation.Rectangle();
|
||||
innerRect.Padding = new Presentation.PaddingInfo(2, 2, 2, 2);
|
||||
innerRect.Fill = m_TrackInnerFill;
|
||||
thumb.Children.Add(innerRect);
|
||||
|
||||
return thumb;
|
||||
}
|
||||
|
||||
private GraphicsPath GetThumbSignPath(eScrollThumbPosition pos)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
Size signSize = Dpi.Size(m_ThumbSignSize);
|
||||
|
||||
if (pos == eScrollThumbPosition.Left || pos == eScrollThumbPosition.Right)
|
||||
{
|
||||
int w = signSize.Width;
|
||||
signSize.Width = signSize.Height;
|
||||
signSize.Height = w;
|
||||
}
|
||||
|
||||
if (pos == eScrollThumbPosition.Top)
|
||||
{
|
||||
path.AddPolygon(new PointF[] {new PointF(-Dpi.Width1, signSize.Height),
|
||||
new PointF(signSize.Width / 2 , -Dpi.Width1),
|
||||
new PointF(signSize.Width / 2, -Dpi.Width1), new PointF(signSize.Width, signSize.Height),
|
||||
new PointF(signSize.Width, signSize.Height), new PointF(-1, signSize.Height)});
|
||||
path.CloseAllFigures();
|
||||
}
|
||||
else if (pos == eScrollThumbPosition.Bottom)
|
||||
{
|
||||
path.AddLine(signSize.Width / 2, signSize.Height + Dpi.Width1, signSize.Width, Dpi.Width1);
|
||||
path.AddLine(signSize.Width, Dpi.Width1, 0, Dpi.Width1);
|
||||
path.AddLine(0, 1, signSize.Width / 2, signSize.Height + Dpi.Width1);
|
||||
path.CloseAllFigures();
|
||||
}
|
||||
else if (pos == eScrollThumbPosition.Left)
|
||||
{
|
||||
//signSize.Width++;
|
||||
signSize.Height += Dpi.Height1;
|
||||
int h2 = (int)(signSize.Height / 2);
|
||||
path.AddLine(0, h2, signSize.Width, 0);
|
||||
path.AddLine(signSize.Width, 0, signSize.Width, signSize.Height);
|
||||
path.AddLine(signSize.Width, signSize.Height, 0, h2);
|
||||
path.CloseAllFigures();
|
||||
}
|
||||
else if (pos == eScrollThumbPosition.Right)
|
||||
{
|
||||
signSize.Height += Dpi.Height1;
|
||||
path.AddLine(signSize.Width, signSize.Height / 2, 0, 0);
|
||||
path.AddLine(0, 0, 0, signSize.Height);
|
||||
path.AddLine(0, signSize.Height, signSize.Width, signSize.Height / 2);
|
||||
path.CloseAllFigures();
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public bool AppStyleScrollBar
|
||||
{
|
||||
get { return m_AppStyleScrollBar; }
|
||||
set { m_AppStyleScrollBar = value; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using DevComponents.DotNetBar.Metro.ColorTables;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroStatusBarPainter : MetroRenderer
|
||||
{
|
||||
public override void Render(MetroRendererInfo renderingInfo)
|
||||
{
|
||||
MetroStatusBar bar = (MetroStatusBar)renderingInfo.Control;
|
||||
Graphics g = renderingInfo.PaintEventArgs.Graphics;
|
||||
MetroStatusBarColorTable ct = renderingInfo.ColorTable.MetroStatusBar;
|
||||
Rectangle bounds = bar.ClientRectangle;
|
||||
|
||||
if (ct.BackgroundStyle != null)
|
||||
{
|
||||
ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(ct.BackgroundStyle, g, bounds);
|
||||
ElementStyleDisplay.PaintBackground(di);
|
||||
}
|
||||
|
||||
if (ct.TopBorders != null && ct.TopBorders.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < ct.TopBorders.Length; i++)
|
||||
{
|
||||
using (Pen pen = new Pen(ct.TopBorders[i]))
|
||||
g.DrawLine(pen, bounds.X, bounds.Y + i, bounds.Right, bounds.Y + i);
|
||||
}
|
||||
}
|
||||
|
||||
if (ct.BottomBorders != null && ct.BottomBorders.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < ct.BottomBorders.Length; i++)
|
||||
{
|
||||
using (Pen pen = new Pen(ct.BottomBorders[i]))
|
||||
g.DrawLine(pen, bounds.X, bounds.Bottom - i - 1, bounds.Right, bounds.Bottom - i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (bar.ResizeHandleVisible)
|
||||
{
|
||||
Form form = bar.FindForm();
|
||||
if (form != null && form.WindowState == FormWindowState.Normal)
|
||||
DevComponents.DotNetBar.Rendering.ResizeHandlePainter.DrawResizeHandle(
|
||||
g, bounds, ct.ResizeMarkerLightColor, ct.ResizeMarkerColor, (bar.RightToLeft == RightToLeft.Yes));
|
||||
}
|
||||
|
||||
#if TRIAL
|
||||
Rectangle tr = bounds;
|
||||
tr.Inflate(-2, -2);
|
||||
using(Font font=new Font(bar.Font.FontFamily, 8f, FontStyle.Regular))
|
||||
TextDrawing.DrawString(g, "DotNetBar Trial", font, Color.FromArgb(80, Color.Black), tr, eTextFormat.Bottom | eTextFormat.HorizontalCenter);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,177 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DevComponents.DotNetBar.Rendering;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using DevComponents.DotNetBar.Ribbon;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
class MetroSwitchButtonPainter : Office2010SwitchButtonPainter
|
||||
{
|
||||
public override void Paint(SwitchButtonRenderEventArgs e)
|
||||
{
|
||||
SwitchButtonItem switchButton = e.SwitchButtonItem;
|
||||
bool enabled = switchButton.Enabled;
|
||||
SwitchButtonColorTable colorTable = enabled ? this.ColorTable.SwitchButton.Default : this.ColorTable.SwitchButton.Disabled;
|
||||
if (colorTable == null) colorTable = new SwitchButtonColorTable();
|
||||
|
||||
Rectangle bounds = switchButton.Bounds;
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
int buttonWidth = Dpi.Width(switchButton.ButtonWidth);
|
||||
Padding margin = Dpi.Size(switchButton.Margin);
|
||||
if (e.ItemPaintArgs != null && e.ItemPaintArgs.ContainerControl is AdvTree.AdvTree)
|
||||
{
|
||||
if (switchButton.ItemAlignment == eItemAlignment.Far)
|
||||
bounds.X = bounds.Right - margin.Right - buttonWidth;
|
||||
else if (switchButton.ItemAlignment == eItemAlignment.Center)
|
||||
bounds.X += (bounds.Width - buttonWidth) / 2;
|
||||
}
|
||||
else
|
||||
bounds.X = bounds.Right - margin.Right - buttonWidth;
|
||||
bounds.Width = buttonWidth;
|
||||
int buttonHeight = Dpi.Height(switchButton.ButtonHeight);
|
||||
bounds.Y += margin.Top + (bounds.Height - margin.Vertical - buttonHeight) / 2;
|
||||
bounds.Height = buttonHeight;
|
||||
switchButton.ButtonBounds = bounds;
|
||||
bool rendersOnGlass = (e.ItemPaintArgs != null && e.ItemPaintArgs.GlassEnabled && (switchButton.Parent is CaptionItemContainer && !(e.ItemPaintArgs.ContainerControl is QatToolbar) || (switchButton.Parent is RibbonTabItemContainer && switchButton.EffectiveStyle == eDotNetBarStyle.Office2010)));
|
||||
|
||||
if (switchButton.TextVisible && !string.IsNullOrEmpty(switchButton.Text))
|
||||
{
|
||||
Rectangle textRect = switchButton.Bounds;
|
||||
Padding textPadding = Dpi.Size(switchButton.TextPadding);
|
||||
textRect.Width -= buttonWidth + margin.Right + textPadding.Horizontal;
|
||||
textRect.Y += textPadding.Top;
|
||||
textRect.X += textPadding.Left;
|
||||
textRect.Height -= textPadding.Vertical;
|
||||
bool rtl = e.RightToLeft;
|
||||
Color textColor = (switchButton.TextColor.IsEmpty || !enabled) ? colorTable.TextColor : switchButton.TextColor;
|
||||
Font textFont = e.Font;
|
||||
eTextFormat tf = eTextFormat.Left | eTextFormat.VerticalCenter;
|
||||
if (switchButton.TextMarkupBody != null)
|
||||
{
|
||||
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, textFont, textColor, rtl);
|
||||
d.HotKeyPrefixVisible = !((tf & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
|
||||
if ((tf & eTextFormat.VerticalCenter) == eTextFormat.VerticalCenter)
|
||||
textRect.Y = switchButton.TopInternal + (switchButton.Bounds.Height - switchButton.TextMarkupBody.Bounds.Height) / 2;
|
||||
else if ((tf & eTextFormat.Bottom) == eTextFormat.Bottom)
|
||||
textRect.Y += (switchButton.TextMarkupBody.Bounds.Height - textRect.Height) + 1;
|
||||
textRect.Height = switchButton.TextMarkupBody.Bounds.Height;
|
||||
switchButton.TextMarkupBody.Bounds = textRect;
|
||||
switchButton.TextMarkupBody.Render(d);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if FRAMEWORK20
|
||||
if (rendersOnGlass)
|
||||
{
|
||||
if (!e.ItemPaintArgs.CachedPaint)
|
||||
Office2007RibbonControlPainter.PaintTextOnGlass(g, switchButton.Text, textFont, textRect, TextDrawing.GetTextFormat(tf));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
TextDrawing.DrawString(g, switchButton.Text, textFont, textColor, textRect, tf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool switchState = switchButton.Value;
|
||||
string offText = switchButton.OffText;
|
||||
string onText = switchButton.OnText;
|
||||
Font font = (switchButton.SwitchFont == null) ? new Font(e.Font, FontStyle.Bold) : switchButton.SwitchFont;
|
||||
Color textOffColor = (switchButton.OffTextColor.IsEmpty || !enabled) ? colorTable.OffTextColor : switchButton.OffTextColor;
|
||||
Color textOnColor = (switchButton.OnTextColor.IsEmpty || !enabled) ? colorTable.OnTextColor : switchButton.OnTextColor;
|
||||
|
||||
int switchWidth = Dpi.Width(switchButton.SwitchWidth);
|
||||
int switchX = Math.Min(bounds.X + switchButton.SwitchOffset, bounds.Right);
|
||||
if (switchState)
|
||||
{
|
||||
switchX = Math.Max(bounds.Right - switchWidth - switchButton.SwitchOffset, bounds.X);
|
||||
}
|
||||
|
||||
Color borderColor = (switchButton.BorderColor.IsEmpty || !enabled) ? colorTable.BorderColor : switchButton.BorderColor;
|
||||
Color offBackgroundColor = (switchButton.OffBackColor.IsEmpty || !enabled) ? colorTable.OffBackColor : switchButton.OffBackColor;
|
||||
Color onBackgroundColor = (switchButton.OnBackColor.IsEmpty || !enabled) ? colorTable.OnBackColor : switchButton.OnBackColor;
|
||||
|
||||
// Main control border
|
||||
DisplayHelp.DrawRectangle(g, borderColor, bounds);
|
||||
|
||||
// Set clip
|
||||
Rectangle innerBoundsClip = bounds;
|
||||
innerBoundsClip.Inflate(-2, -2);
|
||||
GraphicsPath innerClipPath = new GraphicsPath();
|
||||
innerClipPath.AddRectangle(innerBoundsClip);
|
||||
Region oldClip = g.Clip;
|
||||
g.SetClip(innerClipPath, System.Drawing.Drawing2D.CombineMode.Intersect);
|
||||
innerClipPath.Dispose();
|
||||
|
||||
|
||||
// Draw On Background, it is to the left of the switch
|
||||
Rectangle onBounds = new Rectangle(switchX - (bounds.Width - switchWidth), bounds.Y, bounds.Width - switchWidth + 2, bounds.Height);
|
||||
switchButton.OnPartBounds = onBounds;
|
||||
onBounds.Inflate(-2, -2);
|
||||
DisplayHelp.FillRectangle(g, onBounds, onBackgroundColor);
|
||||
if (!string.IsNullOrEmpty(onText))
|
||||
{
|
||||
// Draw On Text
|
||||
if (rendersOnGlass && BarUtilities.UseTextRenderer)
|
||||
TextDrawing.DrawStringLegacy(g, onText, font, textOnColor, onBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
|
||||
else
|
||||
TextDrawing.DrawString(g, onText, font, textOnColor, onBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter | eTextFormat.NoClipping);
|
||||
}
|
||||
|
||||
// Draw Off Background, it is on the right of the switch
|
||||
Rectangle offBounds = new Rectangle(switchX + switchWidth - 2, bounds.Y, bounds.Width - switchWidth + 2, bounds.Height);
|
||||
switchButton.OffPartBounds = offBounds;
|
||||
offBounds.Inflate(-2, -2);
|
||||
DisplayHelp.FillRectangle(g, offBounds, offBackgroundColor);
|
||||
|
||||
if (!string.IsNullOrEmpty(offText))
|
||||
{
|
||||
// Draw Off Text
|
||||
if (rendersOnGlass && BarUtilities.UseTextRenderer)
|
||||
TextDrawing.DrawStringLegacy(g, offText, font, textOffColor, offBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
|
||||
else
|
||||
TextDrawing.DrawString(g, offText, font, textOffColor, offBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter | eTextFormat.NoClipping);
|
||||
}
|
||||
|
||||
// Restore old clip
|
||||
g.Clip = oldClip;
|
||||
oldClip.Dispose();
|
||||
|
||||
// Draw Switch on top
|
||||
Rectangle switchBounds = new Rectangle(switchX, bounds.Y, switchWidth, bounds.Height);
|
||||
switchButton.SwitchBounds = switchBounds;
|
||||
Color switchBorderColor = (switchButton.SwitchBorderColor.IsEmpty || !enabled) ? colorTable.SwitchBorderColor : switchButton.SwitchBorderColor;
|
||||
Color switchFillColor = (switchButton.SwitchBackColor.IsEmpty || !enabled) ? colorTable.SwitchBackColor : switchButton.SwitchBackColor;
|
||||
if (!colorTable.SwitchOnBackColor.IsEmpty && switchButton.Value && switchButton.SwitchBackColor.IsEmpty)
|
||||
switchFillColor = colorTable.SwitchOnBackColor;
|
||||
|
||||
DisplayHelp.FillRectangle(g, switchBounds, switchFillColor);
|
||||
if(!switchBorderColor.IsEmpty)
|
||||
DisplayHelp.DrawRectangle(g, switchBorderColor, switchBounds);
|
||||
|
||||
if (switchButton.IsReadOnly && switchButton.ShowReadOnlyMarker)
|
||||
{
|
||||
Color markerColor = switchButton.ReadOnlyMarkerColor;
|
||||
Rectangle marker = new Rectangle(switchBounds.X + (switchBounds.Width - 7) / 2, switchBounds.Y + (switchBounds.Height - 10) / 2, 7, 10);
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
using (SolidBrush brush = new SolidBrush(markerColor))
|
||||
{
|
||||
g.FillRectangle(brush, new Rectangle(marker.X, marker.Y + 4, marker.Width, marker.Height - 4));
|
||||
g.FillRectangle(Brushes.White, new Rectangle(marker.X + 3, marker.Y + 5, 1, 2));
|
||||
}
|
||||
using (Pen pen = new Pen(markerColor, 1))
|
||||
{
|
||||
g.DrawLine(pen, marker.X + 2, marker.Y + 0, marker.X + 4, marker.Y + 0);
|
||||
g.DrawLine(pen, marker.X + 1, marker.Y + 1, marker.X + 1, marker.Y + 3);
|
||||
g.DrawLine(pen, marker.X + 5, marker.Y + 1, marker.X + 5, marker.Y + 3);
|
||||
}
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DevComponents.DotNetBar.Metro.ColorTables;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroTabItemPainter : MetroRenderer
|
||||
{
|
||||
public override void Render(MetroRendererInfo renderingInfo)
|
||||
{
|
||||
MetroTabItem tab = (MetroTabItem)renderingInfo.Control;
|
||||
Graphics g = renderingInfo.PaintEventArgs.Graphics;
|
||||
MetroTabItemColorTable cti = renderingInfo.ColorTable.MetroTab.MetroTabItem;
|
||||
MetroTabItemStateColorTable color = cti.Default;
|
||||
if (!tab.Enabled)
|
||||
color = cti.Disabled;
|
||||
else if (tab.Checked)
|
||||
color = cti.Selected;
|
||||
else if (tab.IsMouseDown && cti.Pressed != null)
|
||||
color = cti.Pressed;
|
||||
else if (tab.IsMouseOver && cti.MouseOver != null)
|
||||
color = cti.MouseOver;
|
||||
|
||||
Rectangle bounds = tab.Bounds;
|
||||
Rectangle textBounds = tab.TextRenderBounds;
|
||||
Rectangle imageBounds = tab.ImageRenderBounds;
|
||||
CompositeImage image = tab.GetImage();
|
||||
|
||||
if (color.Background != null)
|
||||
{
|
||||
Font font = renderingInfo.DefaultFont;
|
||||
if (!tab.Checked && font.Bold && renderingInfo.DefaultPlainFont != null)
|
||||
font = renderingInfo.DefaultPlainFont;
|
||||
ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(color.Background, g, bounds);
|
||||
ElementStyleDisplay.Paint(di);
|
||||
|
||||
if (image != null && tab.ButtonStyle != eButtonStyle.TextOnlyAlways)
|
||||
{
|
||||
if (imageBounds.IsEmpty)
|
||||
imageBounds = GetImageRectangle(tab, image);
|
||||
if (textBounds.IsEmpty)
|
||||
textBounds = GetTextRectangle(tab, image, imageBounds);
|
||||
|
||||
}
|
||||
else if (textBounds.IsEmpty)
|
||||
textBounds = bounds;
|
||||
|
||||
if (tab.TextMarkupBody == null)
|
||||
{
|
||||
di.Bounds = textBounds;
|
||||
|
||||
ElementStyleDisplay.PaintText(di, tab.Text, font);
|
||||
}
|
||||
else
|
||||
{
|
||||
eTextFormat stringFormat = eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter;
|
||||
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, color.Background.TextColor, renderingInfo.RightToLeft);
|
||||
d.HotKeyPrefixVisible = !((stringFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
|
||||
d.ContextObject = tab;
|
||||
Rectangle mr = new Rectangle(textBounds.X, textBounds.Y + (textBounds.Height - tab.TextMarkupBody.Bounds.Height) / 2 + 1, tab.TextMarkupBody.Bounds.Width, tab.TextMarkupBody.Bounds.Height);
|
||||
if ((stringFormat & eTextFormat.HorizontalCenter) != 0)
|
||||
mr.Offset((textBounds.Width - mr.Width) / 2, 0);
|
||||
if (tab._FixedSizeCenterText) mr.Y--;
|
||||
tab.TextMarkupBody.Bounds = mr;
|
||||
tab.TextMarkupBody.Render(d);
|
||||
}
|
||||
tab.TextRenderBounds = textBounds;
|
||||
tab.ImageRenderBounds = imageBounds;
|
||||
}
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
if (!tab.IsMouseOver && tab.HotTrackingStyle == eHotTrackingStyle.Color)
|
||||
{
|
||||
// Draw gray-scale image for this hover style...
|
||||
float[][] array = new float[5][];
|
||||
array[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0, 0 };
|
||||
array[1] = new float[5] { 0.5f, 0.5f, 0.5f, 0, 0 };
|
||||
array[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0, 0 };
|
||||
array[3] = new float[5] { 0, 0, 0, 1, 0 };
|
||||
array[4] = new float[5] { 0.2f, 0.2f, 0.2f, 0, 1 };
|
||||
ColorMatrix grayMatrix = new ColorMatrix(array);
|
||||
ImageAttributes att = new ImageAttributes();
|
||||
att.SetColorMatrix(grayMatrix);
|
||||
image.DrawImage(g, imageBounds, 0, 0, image.ActualWidth, image.ActualHeight, GraphicsUnit.Pixel, att);
|
||||
}
|
||||
else
|
||||
{
|
||||
image.DrawImage(g, imageBounds);
|
||||
}
|
||||
}
|
||||
|
||||
//g.FillRectangle(Brushes.Red, bounds);
|
||||
}
|
||||
|
||||
private Rectangle GetImageRectangle(MetroTabItem tab, CompositeImage image)
|
||||
{
|
||||
Rectangle imageRect = Rectangle.Empty;
|
||||
// Calculate image position
|
||||
if (image != null)
|
||||
{
|
||||
Size imageSize = tab.ImageSize;
|
||||
|
||||
if (tab.ImagePosition == eImagePosition.Top || tab.ImagePosition == eImagePosition.Bottom)
|
||||
imageRect = new Rectangle(tab.ImageDrawRect.X, tab.ImageDrawRect.Y, tab.DisplayRectangle.Width, tab.ImageDrawRect.Height);
|
||||
else if(tab.ImagePosition == eImagePosition.Left)
|
||||
imageRect = new Rectangle(tab.ImageDrawRect.X+4, tab.ImageDrawRect.Y, tab.ImageDrawRect.Width, tab.ImageDrawRect.Height);
|
||||
else if (tab.ImagePosition == eImagePosition.Right)
|
||||
imageRect = new Rectangle(tab.ImageDrawRect.X + tab.ImagePaddingHorizontal+4, tab.ImageDrawRect.Y, tab.ImageDrawRect.Width, tab.ImageDrawRect.Height);
|
||||
imageRect.Offset(tab.DisplayRectangle.Left, tab.DisplayRectangle.Top);
|
||||
imageRect.Offset((imageRect.Width - imageSize.Width) / 2, (imageRect.Height - imageSize.Height) / 2);
|
||||
|
||||
imageRect.Width = imageSize.Width;
|
||||
imageRect.Height = imageSize.Height;
|
||||
}
|
||||
|
||||
return imageRect;
|
||||
}
|
||||
|
||||
private Rectangle GetTextRectangle(MetroTabItem tab, CompositeImage image, Rectangle imageBounds)
|
||||
{
|
||||
Rectangle itemRect = tab.DisplayRectangle;
|
||||
Rectangle textRect = tab.TextDrawRect;
|
||||
|
||||
if (tab.ImagePosition == eImagePosition.Top || tab.ImagePosition == eImagePosition.Bottom)
|
||||
{
|
||||
textRect = new Rectangle(1, textRect.Y, itemRect.Width - 2, textRect.Height);
|
||||
}
|
||||
textRect.Offset(itemRect.Left, itemRect.Top);
|
||||
|
||||
if (tab.ImagePosition == eImagePosition.Left)
|
||||
textRect.X = imageBounds.Right + tab.ImagePaddingHorizontal;
|
||||
|
||||
if (textRect.Right > itemRect.Right)
|
||||
textRect.Width = itemRect.Right - textRect.Left;
|
||||
|
||||
return textRect;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,365 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DevComponents.DotNetBar.Metro.ColorTables;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroTabStripPainter : MetroRenderer
|
||||
{
|
||||
public override void Render(MetroRendererInfo renderingInfo)
|
||||
{
|
||||
MetroTabStrip strip = (MetroTabStrip)renderingInfo.Control;
|
||||
Graphics g = renderingInfo.PaintEventArgs.Graphics;
|
||||
MetroTabStripColorTable ct = renderingInfo.ColorTable.MetroTab.TabStrip;
|
||||
Rectangle bounds = strip.ClientRectangle;
|
||||
|
||||
if (ct.BackgroundStyle != null)
|
||||
{
|
||||
ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(ct.BackgroundStyle, g, bounds);
|
||||
ElementStyleDisplay.PaintBackground(di);
|
||||
}
|
||||
|
||||
if (strip.CaptionVisible)
|
||||
{
|
||||
if (strip.CaptionBounds.IsEmpty || strip.SystemCaptionItemBounds.IsEmpty || strip.QuickToolbarBounds.IsEmpty)
|
||||
SetQatAndCaptionItemBounds(strip, renderingInfo);
|
||||
Color captionTextColor = renderingInfo.ColorTable.MetroTab.ActiveCaptionText;
|
||||
eTextFormat textFormat = renderingInfo.ColorTable.MetroTab.CaptionTextFormat;
|
||||
System.Windows.Forms.Form form = strip.FindForm();
|
||||
bool isFormActive = true;
|
||||
if (form != null && (form != System.Windows.Forms.Form.ActiveForm && form.MdiParent == null ||
|
||||
form.MdiParent != null && form.MdiParent.ActiveMdiChild != form))
|
||||
{
|
||||
captionTextColor = renderingInfo.ColorTable.MetroTab.InactiveCaptionText;
|
||||
isFormActive = false;
|
||||
}
|
||||
|
||||
Font font = SystemFonts.DefaultFont; // System.Windows.Forms.SystemInformation.MenuFont;
|
||||
bool disposeFont = true;
|
||||
if (strip.CaptionFont != null)
|
||||
{
|
||||
font.Dispose();
|
||||
font = strip.CaptionFont;
|
||||
disposeFont = false;
|
||||
}
|
||||
string text = strip.TitleText;
|
||||
if (string.IsNullOrEmpty(text) && form != null) text = form.Text;
|
||||
bool isTitleTextMarkup = strip.TitleTextMarkupBody != null;
|
||||
Rectangle captionRect = strip.CaptionBounds;
|
||||
const int CAPTION_TEXT_PADDING = 12;
|
||||
captionRect.X += CAPTION_TEXT_PADDING;
|
||||
captionRect.Width -= CAPTION_TEXT_PADDING;
|
||||
|
||||
if(StyleManager.Style == eStyle.OfficeMobile2014)
|
||||
{
|
||||
captionRect.Y -= 2;
|
||||
captionRect.Height -= 2;
|
||||
// Center text in center of window instead of center of available space
|
||||
if (!strip.SystemCaptionItemBounds.IsEmpty && captionRect.Width > strip.SystemCaptionItemBounds.Width)
|
||||
{
|
||||
captionRect.X += strip.SystemCaptionItemBounds.Width / 2 + 18;
|
||||
captionRect.Width -= strip.SystemCaptionItemBounds.Width / 2 +18;
|
||||
}
|
||||
if (!strip.QuickToolbarBounds.IsEmpty && captionRect.Width > strip.QuickToolbarBounds.Width)
|
||||
{
|
||||
captionRect.X -= strip.QuickToolbarBounds.Width / 2;
|
||||
captionRect.Width += strip.QuickToolbarBounds.Width / 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isTitleTextMarkup)
|
||||
TextDrawing.DrawString(g, text, font, captionTextColor, captionRect, textFormat);
|
||||
else
|
||||
{
|
||||
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, captionTextColor, strip.RightToLeft == System.Windows.Forms.RightToLeft.Yes, captionRect, false);
|
||||
d.AllowMultiLine = false;
|
||||
d.IgnoreFormattingColors = !isFormActive;
|
||||
TextMarkup.BodyElement body = strip.TitleTextMarkupBody;
|
||||
if (strip.TitleTextMarkupLastArrangeBounds != captionRect)
|
||||
{
|
||||
body.Measure(captionRect.Size, d);
|
||||
body.Arrange(captionRect, d);
|
||||
strip.TitleTextMarkupLastArrangeBounds = captionRect;
|
||||
Rectangle mr = body.Bounds;
|
||||
if (mr.Width < captionRect.Width)
|
||||
mr.Offset((captionRect.Width - mr.Width) / 2, 0);
|
||||
if (mr.Height < captionRect.Height)
|
||||
mr.Offset(0, (captionRect.Height - mr.Height) / 2);
|
||||
body.Bounds = mr;
|
||||
}
|
||||
Region oldClip = g.Clip;
|
||||
g.SetClip(captionRect, CombineMode.Intersect);
|
||||
body.Render(d);
|
||||
g.Clip = oldClip;
|
||||
if (oldClip != null) oldClip.Dispose();
|
||||
}
|
||||
|
||||
if (disposeFont) font.Dispose();
|
||||
}
|
||||
|
||||
//g.FillRectangle(Brushes.Yellow, strip.QuickToolbarBounds);
|
||||
//g.FillRectangle(Brushes.Green, strip.CaptionBounds);
|
||||
//g.FillRectangle(Brushes.Indigo, strip.SystemCaptionItemBounds);
|
||||
|
||||
}
|
||||
|
||||
private void SetQatAndCaptionItemBounds(MetroTabStrip strip,MetroRendererInfo renderingInfo)
|
||||
{
|
||||
if (!strip.CaptionVisible)
|
||||
return;
|
||||
bool rightToLeft = (strip.RightToLeft == System.Windows.Forms.RightToLeft.Yes);
|
||||
|
||||
System.Windows.Forms.Form form = strip.FindForm();
|
||||
bool isMaximized = false;
|
||||
if (form != null) isMaximized = form.WindowState == System.Windows.Forms.FormWindowState.Maximized;
|
||||
|
||||
// Get right most X position of the Quick Access Toolbar
|
||||
int right = 0, sysLeft = 0;
|
||||
Size qatSize = Size.Empty;
|
||||
for (int i = strip.QuickToolbarItems.Count - 1; i >= 0; i--)
|
||||
{
|
||||
BaseItem item = strip.QuickToolbarItems[i];
|
||||
if (!item.Visible || !item.Displayed)
|
||||
continue;
|
||||
if (item is QatCustomizeItem) qatSize = item.DisplayRectangle.Size;
|
||||
if (item.ItemAlignment == eItemAlignment.Near && item.Visible && i > 0)
|
||||
{
|
||||
if (rightToLeft)
|
||||
right = item.DisplayRectangle.X;
|
||||
else
|
||||
right = item.DisplayRectangle.Right;
|
||||
break;
|
||||
}
|
||||
else if (item.ItemAlignment == eItemAlignment.Far && item.Visible)
|
||||
{
|
||||
if (rightToLeft)
|
||||
sysLeft = item.DisplayRectangle.Right;
|
||||
else
|
||||
sysLeft = item.DisplayRectangle.X;
|
||||
}
|
||||
}
|
||||
|
||||
if (strip.CaptionContainerItem is CaptionItemContainer && ((CaptionItemContainer)strip.CaptionContainerItem).MoreItems != null)
|
||||
{
|
||||
if (rightToLeft)
|
||||
right = ((CaptionItemContainer)strip.CaptionContainerItem).MoreItems.DisplayRectangle.X;
|
||||
else
|
||||
right = ((CaptionItemContainer)strip.CaptionContainerItem).MoreItems.DisplayRectangle.Right;
|
||||
qatSize = ((CaptionItemContainer)strip.CaptionContainerItem).MoreItems.DisplayRectangle.Size;
|
||||
}
|
||||
|
||||
Rectangle r = new Rectangle(right, 2, strip.CaptionContainerItem.WidthInternal - right - (strip.CaptionContainerItem.WidthInternal-sysLeft), strip.GetTotalCaptionHeight());
|
||||
strip.CaptionBounds = r;
|
||||
|
||||
if (sysLeft > 0)
|
||||
{
|
||||
if (rightToLeft)
|
||||
strip.SystemCaptionItemBounds = new Rectangle(r.X, r.Y, sysLeft, r.Height);
|
||||
else
|
||||
strip.SystemCaptionItemBounds = new Rectangle(sysLeft, r.Y, strip.CaptionContainerItem.WidthInternal - sysLeft, r.Height);
|
||||
}
|
||||
|
||||
if (right == 0 || r.Height <= 0 || r.Width <= 0)
|
||||
return;
|
||||
|
||||
BaseItem startButton = strip.GetApplicationButton();
|
||||
if (startButton != null)
|
||||
{
|
||||
int startIndex = strip.QuickToolbarItems.IndexOf(startButton);
|
||||
if (strip.QuickToolbarItems.Count - 1 > startIndex)
|
||||
{
|
||||
BaseItem firstItem = strip.QuickToolbarItems[startIndex + 1];
|
||||
if (rightToLeft)
|
||||
{
|
||||
r.Width -= r.Right - firstItem.DisplayRectangle.Right;
|
||||
}
|
||||
else
|
||||
{
|
||||
r.Width -= firstItem.DisplayRectangle.X - r.X;
|
||||
r.X = firstItem.DisplayRectangle.X;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.Height = ((CaptionItemContainer)strip.CaptionContainerItem).MaxItemHeight + 6;
|
||||
r.X = 0;
|
||||
r.Width = right;
|
||||
strip.QuickToolbarBounds = r;
|
||||
}
|
||||
|
||||
//private void PaintCaptionText(MetroTabStrip rs)
|
||||
//{
|
||||
// if (!rs.CaptionVisible || rs.CaptionBounds.IsEmpty)
|
||||
// return;
|
||||
|
||||
// Graphics g = e.Graphics;
|
||||
// bool isMaximized = false;
|
||||
// bool isFormActive = true;
|
||||
// Rendering.Office2007FormStateColorTable formct = m_ColorTable.Form.Active;
|
||||
// System.Windows.Forms.Form form = rs.FindForm();
|
||||
// if (form != null && (form != System.Windows.Forms.Form.ActiveForm && form.MdiParent == null ||
|
||||
// form.MdiParent != null && form.MdiParent.ActiveMdiChild != form))
|
||||
// {
|
||||
// formct = m_ColorTable.Form.Inactive;
|
||||
// isFormActive = false;
|
||||
// }
|
||||
// string text = e.RibbonControl.TitleText;
|
||||
// string plainText = text;
|
||||
// bool isTitleTextMarkup = e.RibbonControl.RibbonStrip.TitleTextMarkupBody != null;
|
||||
// if (isTitleTextMarkup)
|
||||
// plainText = e.RibbonControl.RibbonStrip.TitleTextMarkupBody.PlainText;
|
||||
// if (form != null)
|
||||
// {
|
||||
// if (text == "")
|
||||
// {
|
||||
// text = form.Text;
|
||||
// plainText = text;
|
||||
// }
|
||||
// isMaximized = form.WindowState == System.Windows.Forms.FormWindowState.Maximized;
|
||||
// }
|
||||
|
||||
// Rectangle captionRect = rs.CaptionBounds;
|
||||
|
||||
// // Exclude quick access toolbar if any
|
||||
// if (!rs.QuickToolbarBounds.IsEmpty)
|
||||
// DisplayHelp.ExcludeEdgeRect(ref captionRect, rs.QuickToolbarBounds);
|
||||
// else
|
||||
// {
|
||||
// BaseItem sb = e.RibbonControl.GetApplicationButton();
|
||||
// if (sb != null && sb.Visible && sb.Displayed)
|
||||
// DisplayHelp.ExcludeEdgeRect(ref captionRect, sb.Bounds);
|
||||
// else
|
||||
// DisplayHelp.ExcludeEdgeRect(ref captionRect, new Rectangle(0, 0, 22, 22)); // The system button in top-left corner
|
||||
// }
|
||||
|
||||
// if (!rs.SystemCaptionItemBounds.IsEmpty)
|
||||
// DisplayHelp.ExcludeEdgeRect(ref captionRect, rs.SystemCaptionItemBounds);
|
||||
|
||||
|
||||
// // Array of the rectangles after they are split
|
||||
// ArrayList rects = new ArrayList(5);
|
||||
// ArrayList tempRemoveList = new ArrayList(5);
|
||||
// // Exclude Context Tabs Captions if any
|
||||
// if (rs.TabGroupsVisible)
|
||||
// {
|
||||
// foreach (RibbonTabItemGroup group in rs.TabGroups)
|
||||
// {
|
||||
// foreach (Rectangle r in group.DisplayPositions)
|
||||
// {
|
||||
// if (rects.Count > 0)
|
||||
// {
|
||||
// tempRemoveList.Clear();
|
||||
// Rectangle[] arrCopy = new Rectangle[rects.Count];
|
||||
// rects.CopyTo(arrCopy);
|
||||
// for (int irc = 0; irc < arrCopy.Length; irc++)
|
||||
// {
|
||||
// if (arrCopy[irc].IntersectsWith(r))
|
||||
// {
|
||||
// tempRemoveList.Add(irc);
|
||||
// Rectangle[] splitRects = DisplayHelp.ExcludeRectangle(arrCopy[irc], r);
|
||||
// rects.AddRange(splitRects);
|
||||
// }
|
||||
// }
|
||||
// foreach (int idx in tempRemoveList)
|
||||
// rects.RemoveAt(idx);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (r.IntersectsWith(captionRect))
|
||||
// {
|
||||
// Rectangle[] splitRects = DisplayHelp.ExcludeRectangle(captionRect, r);
|
||||
// if (splitRects.Length > 0)
|
||||
// {
|
||||
// rects.AddRange(splitRects);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Font font = System.Windows.Forms.SystemInformation.MenuFont;
|
||||
// bool disposeFont = true;
|
||||
// if (rs.CaptionFont != null)
|
||||
// {
|
||||
// font.Dispose();
|
||||
// font = rs.CaptionFont;
|
||||
// disposeFont = false;
|
||||
// }
|
||||
// Size textSize = Size.Empty;
|
||||
// if (isTitleTextMarkup)
|
||||
// {
|
||||
// textSize = e.RibbonControl.RibbonStrip.TitleTextMarkupBody.Bounds.Size;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// textSize = TextDrawing.MeasureString(g, plainText, font);
|
||||
// }
|
||||
|
||||
// if (rects.Count > 0)
|
||||
// {
|
||||
// rs.CaptionTextBounds = (Rectangle[])rects.ToArray(typeof(Rectangle));
|
||||
// if (e.RibbonControl.RightToLeft == System.Windows.Forms.RightToLeft.No)
|
||||
// rects.Reverse();
|
||||
// captionRect = Rectangle.Empty;
|
||||
// foreach (Rectangle r in rects)
|
||||
// {
|
||||
// if (r.Width >= textSize.Width)
|
||||
// {
|
||||
// captionRect = r;
|
||||
// break;
|
||||
// }
|
||||
// else if (r.Width > captionRect.Width)
|
||||
// captionRect = r;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// rs.CaptionTextBounds = new Rectangle[] { captionRect };
|
||||
|
||||
// if (captionRect.Width > 6 && captionRect.Height > 6)
|
||||
// {
|
||||
// if (e.GlassEnabled && e.ItemPaintArgs != null && e.ItemPaintArgs.ThemeWindow != null && !e.RibbonControl.IsDesignMode)
|
||||
// {
|
||||
// if (!e.ItemPaintArgs.CachedPaint || isMaximized)
|
||||
// PaintGlassText(g, plainText, font, captionRect, isMaximized);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (!isTitleTextMarkup)
|
||||
// TextDrawing.DrawString(g, plainText, font, formct.CaptionText, captionRect, eTextFormat.VerticalCenter | eTextFormat.HorizontalCenter | eTextFormat.EndEllipsis | eTextFormat.NoPrefix);
|
||||
// else
|
||||
// {
|
||||
// TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, formct.CaptionText, e.RibbonControl.RightToLeft == System.Windows.Forms.RightToLeft.Yes, captionRect, false);
|
||||
// d.AllowMultiLine = false;
|
||||
// d.IgnoreFormattingColors = !isFormActive;
|
||||
// TextMarkup.BodyElement body = e.RibbonControl.RibbonStrip.TitleTextMarkupBody;
|
||||
// if (e.RibbonControl.RibbonStrip.TitleTextMarkupLastArrangeBounds != captionRect)
|
||||
// {
|
||||
// body.Measure(captionRect.Size, d);
|
||||
// body.Arrange(captionRect, d);
|
||||
// e.RibbonControl.RibbonStrip.TitleTextMarkupLastArrangeBounds = captionRect;
|
||||
// Rectangle mr = body.Bounds;
|
||||
// if (mr.Width < captionRect.Width)
|
||||
// mr.Offset((captionRect.Width - mr.Width) / 2, 0);
|
||||
// if (mr.Height < captionRect.Height)
|
||||
// mr.Offset(0, (captionRect.Height - mr.Height) / 2);
|
||||
// body.Bounds = mr;
|
||||
// }
|
||||
// Region oldClip = g.Clip;
|
||||
// g.SetClip(captionRect, CombineMode.Intersect);
|
||||
// body.Render(d);
|
||||
// g.Clip = oldClip;
|
||||
// if (oldClip != null) oldClip.Dispose();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (disposeFont) font.Dispose();
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,345 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing.Drawing2D;
|
||||
using DevComponents.DotNetBar.Metro.ColorTables;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroTileItemPainter : MetroRenderer
|
||||
{
|
||||
private static readonly int InflatePixels = 1;
|
||||
private static readonly int InflatePixelsMouseDown = 2;
|
||||
private static readonly int DragEffectInflatePixels = -4;
|
||||
private static readonly int DragInsertOffsetPixels = 10;
|
||||
|
||||
//private static readonly Point ImageIndent = new Point(2, 2);
|
||||
public override void Render(MetroRendererInfo renderingInfo)
|
||||
{
|
||||
MetroTileItem item = (MetroTileItem)renderingInfo.Control;
|
||||
if (item.Frames.Count == 0)
|
||||
{
|
||||
using (HatchBrush brush = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Red))
|
||||
renderingInfo.PaintEventArgs.Graphics.FillRectangle(brush, item.Bounds);
|
||||
return;
|
||||
}
|
||||
|
||||
Matrix currentTransform = null;
|
||||
float zoom = 0.95f;
|
||||
System.Drawing.Drawing2D.Matrix mx = null;
|
||||
|
||||
if (renderingInfo.ItemPaintArgs.DragInProgress)
|
||||
{
|
||||
currentTransform = renderingInfo.PaintEventArgs.Graphics.Transform;
|
||||
|
||||
mx = new System.Drawing.Drawing2D.Matrix(zoom, 0, 0, zoom, 0, 0);
|
||||
float offsetX = (item.WidthInternal * (1.0f / zoom) - item.WidthInternal) / 2;
|
||||
float offsetY = (item.HeightInternal * (1.0f / zoom) - item.HeightInternal) / 2;
|
||||
mx.Translate(offsetX, offsetY);
|
||||
renderingInfo.PaintEventArgs.Graphics.Transform = mx;
|
||||
}
|
||||
|
||||
if (item.CurrentFrameOffset != 0 && item.LastFrame != item.CurrentFrame)
|
||||
{
|
||||
Graphics g = renderingInfo.PaintEventArgs.Graphics;
|
||||
if (currentTransform == null)
|
||||
currentTransform = g.Transform;
|
||||
g.TranslateTransform(0, -(item.HeightInternal - item.CurrentFrameOffset - InflatePixels * 2), MatrixOrder.Append);
|
||||
// Draw last frame first then offset the current frame
|
||||
RenderFrame(renderingInfo, item.LastFrame);
|
||||
if (mx != null)
|
||||
g.Transform = mx;
|
||||
else
|
||||
g.Transform = currentTransform;
|
||||
g.TranslateTransform(0, item.CurrentFrameOffset, MatrixOrder.Append);
|
||||
|
||||
RenderFrame(renderingInfo, item.CurrentFrame);
|
||||
}
|
||||
else
|
||||
RenderFrame(renderingInfo, item.CurrentFrame);
|
||||
|
||||
if (currentTransform != null)
|
||||
{
|
||||
renderingInfo.PaintEventArgs.Graphics.Transform = currentTransform;
|
||||
currentTransform.Dispose();
|
||||
}
|
||||
}
|
||||
private void RenderFrame(MetroRendererInfo renderingInfo, int frameIndex)
|
||||
{
|
||||
MetroTileItem item = (MetroTileItem)renderingInfo.Control;
|
||||
MetroTileFrame frame = item.Frames[frameIndex];
|
||||
MetroTileColorTable colorTable = renderingInfo.ColorTable.MetroTile;
|
||||
Graphics g = renderingInfo.PaintEventArgs.Graphics;
|
||||
Rectangle bounds = item.Bounds;
|
||||
Region clip = null;
|
||||
if (!item.DragStartPoint.IsEmpty) // When dragging tile moves with the mouse
|
||||
{
|
||||
bounds.Location = renderingInfo.ItemPaintArgs.ContainerControl.PointToClient(Control.MousePosition);
|
||||
bounds.Location.Offset(-item.DragStartPoint.X, -item.DragStartPoint.Y);
|
||||
clip = g.Clip;
|
||||
g.SetClip(bounds, CombineMode.Replace);
|
||||
}
|
||||
Control control = item.ContainerControl as Control;
|
||||
bounds.Inflate(-InflatePixels, -InflatePixels);
|
||||
if (item.IsLeftMouseButtonDown)
|
||||
bounds.Inflate(-InflatePixelsMouseDown, -InflatePixelsMouseDown);
|
||||
else if (item.IsMouseOver)
|
||||
bounds.Inflate(InflatePixels, InflatePixels);
|
||||
|
||||
//if (renderingInfo.ItemPaintArgs.DragInProgress)
|
||||
// bounds.Inflate(DragEffectInflatePixels, DragEffectInflatePixels);
|
||||
|
||||
eDesignInsertPosition insertMarker = item.DesignInsertMarker;
|
||||
if (insertMarker == eDesignInsertPosition.After)
|
||||
{
|
||||
if (item.IsDesignMarkHorizontal)
|
||||
bounds.Offset(-DragInsertOffsetPixels, 0);
|
||||
else
|
||||
bounds.Offset(0, -DragInsertOffsetPixels);
|
||||
g.ResetClip();
|
||||
}
|
||||
else if (insertMarker == eDesignInsertPosition.Before)
|
||||
{
|
||||
if (item.IsDesignMarkHorizontal)
|
||||
bounds.Offset(DragInsertOffsetPixels, 0);
|
||||
else
|
||||
bounds.Offset(0, DragInsertOffsetPixels);
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
bool dispose = false;
|
||||
bool enabled = item.GetEnabled(renderingInfo.ItemPaintArgs.ContainerControl);
|
||||
ElementStyle style = ElementStyleDisplay.GetElementStyle(frame.EffectiveStyle, out dispose);
|
||||
|
||||
if (bounds.Width > 2048) bounds.Width = 2048;
|
||||
if (bounds.Height > 1600) bounds.Height = 1600;
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(style, g, bounds);
|
||||
ElementStyleDisplay.Paint(di);
|
||||
}
|
||||
else
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(item.DisabledBackColor.IsEmpty ? renderingInfo.ColorTable.MetroPartColors.CanvasColorLighterShade : item.DisabledBackColor))
|
||||
g.FillRectangle(brush, bounds);
|
||||
}
|
||||
|
||||
Rectangle textRect = bounds;
|
||||
textRect.X += style.PaddingLeft;
|
||||
textRect.Y += style.PaddingTop;
|
||||
textRect.Width -= style.PaddingHorizontal;
|
||||
textRect.Height -= style.PaddingVertical;
|
||||
if (item.IsLeftMouseButtonDown)
|
||||
{
|
||||
textRect.Width += InflatePixelsMouseDown*2;
|
||||
textRect.Height += InflatePixelsMouseDown*2;
|
||||
}
|
||||
else if(item.IsMouseOver)
|
||||
textRect.Inflate(-InflatePixels, -InflatePixels);
|
||||
Size tileSize = Dpi.Size(item.TileSize);
|
||||
if (item.SubItems.Count > 0 && frameIndex < item.SubItems.Count)
|
||||
{
|
||||
BaseItem child = item.SubItems[frameIndex];
|
||||
if (child.Displayed)
|
||||
{
|
||||
child.TopInternal = bounds.Y + style.PaddingTop + ((bounds.Height - style.PaddingTop - frame.TitleTextBounds.Height) - child.HeightInternal) / 2;
|
||||
child.LeftInternal = bounds.X + style.PaddingLeft;
|
||||
child.WidthInternal = tileSize.Width - style.PaddingHorizontal;
|
||||
child.Paint(renderingInfo.ItemPaintArgs);
|
||||
}
|
||||
}
|
||||
|
||||
Image image = frame.Image;
|
||||
ContentAlignment imageTextAlign = frame.ImageTextAlignment;
|
||||
Color textColor = enabled ? style.TextColor : renderingInfo.ColorTable.MetroPartColors.CanvasColorLightShade;
|
||||
Color symbolColor = textColor;
|
||||
if (!frame.SymbolColor.IsEmpty) symbolColor = frame.SymbolColor;
|
||||
if (image != null || !string.IsNullOrEmpty(frame.SymbolRealized))
|
||||
{
|
||||
Font symFont = null;
|
||||
Rectangle imageRect = Rectangle.Empty;
|
||||
if (string.IsNullOrEmpty(frame.SymbolRealized))
|
||||
imageRect = new Rectangle(0, 0, Dpi.ImageWidth(image.Width), Dpi.ImageHeight(image.Height));
|
||||
else
|
||||
{
|
||||
symFont = Symbols.GetFont(frame.SymbolSize, frame.SymbolSet);
|
||||
Size imageSize = TextDrawing.MeasureString(g, frame.SymbolRealized, symFont);
|
||||
int descent = (int)Math.Ceiling((symFont.FontFamily.GetCellDescent(symFont.Style) *
|
||||
symFont.Size / symFont.FontFamily.GetEmHeight(symFont.Style)));
|
||||
imageSize.Height -= descent;
|
||||
imageRect = new Rectangle(0, 0, imageSize.Width, imageSize.Height);
|
||||
}
|
||||
|
||||
imageRect.Offset(bounds.Location);
|
||||
|
||||
if (imageTextAlign == ContentAlignment.TopLeft)
|
||||
{
|
||||
textRect.X += (imageRect.Width + frame.ImageIndent.X);
|
||||
textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
|
||||
imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
|
||||
}
|
||||
else if (imageTextAlign == ContentAlignment.TopCenter)
|
||||
{
|
||||
imageRect.X += (tileSize.Width - imageRect.Width) / 2;
|
||||
imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
|
||||
textRect.Y += (imageRect.Height + frame.ImageIndent.Y);
|
||||
textRect.Height -= (imageRect.Height);
|
||||
}
|
||||
else if (imageTextAlign == ContentAlignment.TopRight)
|
||||
{
|
||||
imageRect.X += (tileSize.Width - imageRect.Width - frame.ImageIndent.X);
|
||||
imageRect.Offset(0, frame.ImageIndent.Y);
|
||||
textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
|
||||
}
|
||||
else if (imageTextAlign == ContentAlignment.BottomCenter)
|
||||
{
|
||||
imageRect.Offset((tileSize.Width - imageRect.Width) / 2, tileSize.Height - imageRect.Height);
|
||||
imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
|
||||
textRect.Height -= (imageRect.Height);
|
||||
}
|
||||
else if (imageTextAlign == ContentAlignment.BottomLeft)
|
||||
{
|
||||
imageRect.Offset(0, tileSize.Height - imageRect.Height);
|
||||
imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
|
||||
textRect.X += (imageRect.Width + frame.ImageIndent.X);
|
||||
textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
|
||||
}
|
||||
else if (imageTextAlign == ContentAlignment.BottomRight)
|
||||
{
|
||||
imageRect.Offset((tileSize.Width - imageRect.Width - frame.ImageIndent.X), tileSize.Height - imageRect.Height);
|
||||
imageRect.Offset(0, frame.ImageIndent.Y);
|
||||
textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
|
||||
}
|
||||
else if (imageTextAlign == ContentAlignment.MiddleCenter)
|
||||
{
|
||||
imageRect.Offset((tileSize.Width - imageRect.Width) / 2, (tileSize.Height - imageRect.Height) / 2);
|
||||
imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
|
||||
textRect.Height = Math.Max(0, textRect.Bottom - imageRect.Bottom);
|
||||
textRect.Y = imageRect.Bottom + 1;
|
||||
}
|
||||
else if (imageTextAlign == ContentAlignment.MiddleLeft)
|
||||
{
|
||||
imageRect.Offset(0, (tileSize.Height - imageRect.Height) / 2);
|
||||
imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
|
||||
textRect.X += (imageRect.Width + frame.ImageIndent.X);
|
||||
textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
|
||||
}
|
||||
else if (imageTextAlign == ContentAlignment.MiddleRight)
|
||||
{
|
||||
imageRect.Offset((tileSize.Width - imageRect.Width - frame.ImageIndent.X), (tileSize.Height - imageRect.Height) / 2);
|
||||
imageRect.Offset(0, frame.ImageIndent.Y);
|
||||
textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
|
||||
}
|
||||
else
|
||||
imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
|
||||
|
||||
if (string.IsNullOrEmpty(frame.SymbolRealized))
|
||||
g.DrawImage(image, imageRect);
|
||||
else
|
||||
TextDrawing.DrawStringLegacy(g, frame.SymbolRealized, symFont, symbolColor, new Rectangle(imageRect.X, imageRect.Y, 0, 0), eTextFormat.Default);
|
||||
}
|
||||
|
||||
if (textRect.Width > 0 && textRect.Height > 0 && frame.Text != null)
|
||||
{
|
||||
Font font = renderingInfo.DefaultFont;
|
||||
if (style.Font != null)
|
||||
font = style.Font;
|
||||
bool rightToLeft = renderingInfo.RightToLeft;
|
||||
if (frame.TextMarkupBody == null)
|
||||
{
|
||||
eTextFormat textFormat = eTextFormat.Default | eTextFormat.WordBreak | eTextFormat.NoClipping;
|
||||
if (style.TextLineAlignment == eStyleTextAlignment.Center)
|
||||
textFormat |= eTextFormat.VerticalCenter;
|
||||
else if (style.TextLineAlignment == eStyleTextAlignment.Far)
|
||||
textFormat |= eTextFormat.Bottom;
|
||||
if (style.TextAlignment == eStyleTextAlignment.Center)
|
||||
textFormat |= eTextFormat.HorizontalCenter;
|
||||
else if (style.TextAlignment == eStyleTextAlignment.Far)
|
||||
textFormat |= eTextFormat.Right;
|
||||
//if (frame.Text.Contains("Explorer")) Console.WriteLine("{0} {1}", textRect, DateTime.Now);
|
||||
TextDrawing.DrawString(g, frame.Text, font, textColor, textRect, textFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rightToLeft);
|
||||
d.HotKeyPrefixVisible = false;
|
||||
d.ContextObject = item;
|
||||
Rectangle markupBounds = textRect;
|
||||
// Can't do this because it will break all apps default for TextLineAlignment is eStyleTextAlignment.Center
|
||||
//if (style.TextLineAlignment == eStyleTextAlignment.Center)
|
||||
// markupBounds = new Rectangle(new Point(textRect.X, textRect.Y + (textRect.Height - frame.TextMarkupBody.Bounds.Height) / 2), frame.TextMarkupBody.Bounds.Size);
|
||||
//else if (style.TextLineAlignment == eStyleTextAlignment.Far)
|
||||
// markupBounds = new Rectangle(new Point(textRect.X, textRect.Bottom - frame.TextMarkupBody.Bounds.Height), frame.TextMarkupBody.Bounds.Size);
|
||||
|
||||
frame.TextMarkupBody.Bounds = markupBounds;
|
||||
frame.TextMarkupBody.Render(d);
|
||||
}
|
||||
}
|
||||
|
||||
if (frame.TitleText != null)
|
||||
{
|
||||
Color titleTextColor = enabled ? frame.TitleTextColor : renderingInfo.ColorTable.MetroPartColors.CanvasColorLightShade;
|
||||
if (titleTextColor.IsEmpty)
|
||||
titleTextColor = style.TextColor;
|
||||
Font font = item.GetTitleTextFont(frame, style, control);
|
||||
Rectangle titleTextRect = frame.TitleTextBounds;
|
||||
titleTextRect.Offset(bounds.Location);
|
||||
if (item.IsLeftMouseButtonDown)
|
||||
titleTextRect.Offset(1, 1);
|
||||
else if (item.IsMouseOver)
|
||||
titleTextRect.Offset(InflatePixels, InflatePixels);
|
||||
if (frame.TitleTextMarkupBody == null)
|
||||
TextDrawing.DrawString(g, frame.TitleText, font, titleTextColor, titleTextRect, eTextFormat.Default | eTextFormat.SingleLine);
|
||||
else
|
||||
{
|
||||
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, titleTextColor, renderingInfo.RightToLeft);
|
||||
d.HotKeyPrefixVisible = false;
|
||||
d.ContextObject = item;
|
||||
Rectangle markupBounds = titleTextRect;
|
||||
frame.TitleTextMarkupBody.Bounds = markupBounds;
|
||||
frame.TitleTextMarkupBody.Render(d);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.Checked)
|
||||
{
|
||||
Size checkMarkSize = Dpi.Size(CheckMarkSize);
|
||||
Rectangle markBounds = new Rectangle(bounds.Right - checkMarkSize.Width, bounds.Y, checkMarkSize.Width, checkMarkSize.Height);
|
||||
using (GraphicsPath markPath = new GraphicsPath())
|
||||
{
|
||||
markPath.AddLine(markBounds.X, markBounds.Y, markBounds.Right - 1, markBounds.Y);
|
||||
markPath.AddLine(markBounds.Right - 1, markBounds.Y, markBounds.Right - 1, markBounds.Bottom - 1);
|
||||
markPath.CloseFigure();
|
||||
using (SolidBrush brush = new SolidBrush(colorTable.CheckBackground))
|
||||
g.FillPath(brush, markPath);
|
||||
}
|
||||
using (SolidBrush brush = new SolidBrush(colorTable.CheckForeground))
|
||||
{
|
||||
Rectangle checkCircleBounds = new Rectangle();
|
||||
checkCircleBounds.Size = new Size(Dpi.Width11, Dpi.Height11);
|
||||
checkCircleBounds.X = markBounds.Right - checkCircleBounds.Size.Width - Dpi.Width3;
|
||||
checkCircleBounds.Y = markBounds.Y + Dpi.Height2;
|
||||
using (Pen pen = new Pen(colorTable.CheckForeground, Dpi.Width2))
|
||||
{
|
||||
g.DrawEllipse(pen, checkCircleBounds);
|
||||
g.DrawLine(pen, checkCircleBounds.X + Dpi.Width3, checkCircleBounds.Y + Dpi.Height5, checkCircleBounds.X + Dpi.Width6, checkCircleBounds.Y + Dpi.Height8);
|
||||
g.DrawLine(pen, checkCircleBounds.X + Dpi.Width6, checkCircleBounds.Y + Dpi.Height8, checkCircleBounds.X + Dpi.Width9, checkCircleBounds.Y + Dpi.Height3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dispose) style.Dispose();
|
||||
|
||||
if (clip != null)
|
||||
{
|
||||
g.Clip = clip;
|
||||
clip.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Size CheckMarkSize = new Size(27, 27);
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using DevComponents.DotNetBar.Metro.ColorTables;
|
||||
|
||||
namespace DevComponents.DotNetBar.Metro.Rendering
|
||||
{
|
||||
internal class MetroToolbarPainter : MetroRenderer
|
||||
{
|
||||
public override void Render(MetroRendererInfo renderingInfo)
|
||||
{
|
||||
MetroToolbar bar = (MetroToolbar)renderingInfo.Control;
|
||||
Graphics g = renderingInfo.PaintEventArgs.Graphics;
|
||||
MetroToolbarColorTable ct = renderingInfo.ColorTable.MetroToolbar;
|
||||
Rectangle bounds = bar.ClientRectangle;
|
||||
|
||||
if (ct.BackgroundStyle != null)
|
||||
{
|
||||
ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(ct.BackgroundStyle, g, bounds);
|
||||
ElementStyleDisplay.PaintBackground(di);
|
||||
}
|
||||
|
||||
#if TRIAL
|
||||
if (bar.Expanded)
|
||||
{
|
||||
Rectangle tr = bounds;
|
||||
tr.Inflate(-2, -2);
|
||||
using (Font font = new Font(bar.Font.FontFamily, 8f, FontStyle.Regular))
|
||||
TextDrawing.DrawString(g, "DotNetBar Trial", font, Color.FromArgb(32, Color.Black), tr, eTextFormat.Bottom | eTextFormat.Right);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user