Ejemplo n.º 1
0
        /// <summary>
        /// Paints text for given style.
        /// </summary>
        /// <param name="e">Display information.</param>
        /// <param name="text"><Text to paint./param>
        /// <param name="defaultFont">Default font if no font by style is specified.</param>
        /// <param name="useDefaultFont">Specifies whether to use default font for painting regardless of style settings.</param>
        public static void PaintText(ElementStyleDisplayInfo e, string text, Font defaultFont, bool useDefaultFont, eTextFormat textFormat)
        {
            Rectangle textBounds = e.Bounds;
            ElementStyle style = GetElementStyle(e.Style);

            if (text == "" || textBounds.IsEmpty || style.TextColor.IsEmpty)
                return;

            Font font = style.Font;
            if (font == null || useDefaultFont)
                font = defaultFont;

            textBounds.X += style.MarginLeft;
            textBounds.Width -= (style.MarginLeft + style.MarginRight);
            textBounds.Y += style.MarginTop;
            textBounds.Height -= (style.MarginTop + style.MarginBottom);

            if (!style.TextShadowColor.IsEmpty && Math.Abs(style.TextShadowColor.GetBrightness() - style.TextColor.GetBrightness()) > .2)
            {
                using (SolidBrush brush = new SolidBrush(style.TextShadowColor))
                {
                    Rectangle r = textBounds;
                    r.Offset(style.TextShadowOffset);
                    TextDrawing.DrawString(e.Graphics, text, font, style.TextShadowColor, r, textFormat);
                    //e.Graphics.DrawString(text,font,brush,r,style.StringFormat);
                }
            }

            if (!style.TextColor.IsEmpty)
                TextDrawing.DrawString(e.Graphics, text, font, style.TextColor, textBounds, textFormat);
        }
Ejemplo n.º 2
0
        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
        }
Ejemplo n.º 3
0
        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

        }
Ejemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            Rectangle clientRect = this.ClientRectangle;
            bool enabled = this.Enabled;

            if (!this.Enabled)
                e.Graphics.FillRectangle(SystemBrushes.Control, clientRect);
            else
            {
                using(SolidBrush brush=new SolidBrush(this.BackColor))
                    e.Graphics.FillRectangle(brush, clientRect);
            }

            bool disposeStyle = false;
            ElementStyle style = GetBackgroundStyle(out disposeStyle);

            if (style.Custom)
            {
                SmoothingMode sm = g.SmoothingMode;
                if(this.AntiAlias)
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                ElementStyleDisplayInfo displayInfo = new ElementStyleDisplayInfo(style, g, clientRect);
                if (!enabled)
                {
                    ElementStyleDisplay.PaintBorder(displayInfo);
                }
                else
                    ElementStyleDisplay.Paint(displayInfo);
                if (this.AntiAlias)
                    g.SmoothingMode = sm;
            }

            PaintButtons(g);

            if(disposeStyle) style.Dispose();
        }
Ejemplo n.º 5
0
		/// <summary>Returns new Region object for given ElementStyle.</summary>
		/// <returns>New instance of Region object.</returns>
		/// <param name="e">Information to describe ElementStyle.</param>
		public static Region GetStyleRegion(ElementStyleDisplayInfo e)
		{
            Rectangle rectPath = e.Bounds;
            if (e.Style.PaintBorder && e.Style.CornerType!=eCornerType.Square)
            {
                rectPath.Width--;
                rectPath.Height--;
            }

            GraphicsPath path = ElementStyleDisplay.GetBackgroundPath(e.Style, rectPath);
            Region r = new Region();
            r.MakeEmpty();
            r.Union(path);
            // Widen path for the border...
            if (e.Style.PaintBorder && (e.Style.CornerType == eCornerType.Rounded || e.Style.CornerType == eCornerType.Diagonal || 
                e.Style.CornerTypeTopLeft == eCornerType.Rounded || e.Style.CornerTypeTopLeft == eCornerType.Diagonal ||
                e.Style.CornerTypeTopRight==eCornerType.Rounded || e.Style.CornerTypeTopRight==eCornerType.Diagonal ||
                e.Style.CornerTypeBottomLeft==eCornerType.Rounded || e.Style.CornerTypeBottomLeft==eCornerType.Diagonal ||
                e.Style.CornerTypeBottomRight==eCornerType.Rounded || e.Style.CornerTypeBottomRight==eCornerType.Diagonal))
            {
                using (Pen pen = new Pen(Color.Black, (e.Style.BorderTopWidth>0?e.Style.BorderTopWidth:1)))
                {
                    path.Widen(pen);
                }
                //Region r2 = new Region(path);
                r.Union(path);
            }

            return r;
            //GraphicsPath path=ElementStyleDisplay.GetBackgroundPath(e.Style,e.Bounds,false);
            //return new Region(path);
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Paints style background.
		/// </summary>
		/// <param name="e">Style display information.</param>
		public static void PaintBackground(ElementStyleDisplayInfo e)
		{
            Region oldClip = e.Graphics.Clip;
            if (oldClip != null)
                e.Graphics.SetClip(e.Bounds, CombineMode.Intersect);
            else
                e.Graphics.SetClip(e.Bounds, CombineMode.Replace);

            ElementStyle style = GetElementStyle(e.Style);

            SmoothingMode sm = e.Graphics.SmoothingMode;
            e.Graphics.SmoothingMode = SmoothingMode.Default;

			// Paint Background
			Rectangle bounds=DisplayHelp.GetDrawRectangle(ElementStyleDisplay.GetBackgroundRectangle(style,e.Bounds));
			GraphicsPath path;
            path = ElementStyleDisplay.GetBackgroundPath(style, e.Bounds);

            eBackgroundColorBlendType blendType = style.BackColorBlend.GetBlendType();
            if (blendType!=eBackgroundColorBlendType.Invalid)
            {
                if (blendType == eBackgroundColorBlendType.Relative)
                {
                    try
                    {
                        if (style.BackColorGradientType == eGradientType.Linear)
                        {
                            Rectangle rb = bounds;
                            rb.Inflate(1, 1);
                            using (LinearGradientBrush brush = DisplayHelp.CreateLinearGradientBrush(rb, style.BackColor, style.BackColor2, style.BackColorGradientAngle))
                            {
                                brush.InterpolationColors = style.BackColorBlend.GetColorBlend();
                                e.Graphics.FillPath(brush, path);
                            }
                        }
                        else if (style.BackColorGradientType == eGradientType.Radial)
                        {
                            int d = (int)Math.Sqrt(bounds.Width * bounds.Width + bounds.Height * bounds.Height) + 4;
                            GraphicsPath fillPath = new GraphicsPath();
                            fillPath.AddEllipse(bounds.X - (d - bounds.Width) / 2, bounds.Y - (d - bounds.Height) / 2, d, d);
                            using (PathGradientBrush brush = new PathGradientBrush(fillPath))
                            {
                                brush.CenterColor = style.BackColor;
                                brush.SurroundColors = new Color[] { style.BackColor2 };
                                brush.InterpolationColors = style.BackColorBlend.GetColorBlend();
                                e.Graphics.FillPath(brush, path);
                            }
                            fillPath.Dispose();
                        }
                    }
                    catch
                    {
                        blendType = eBackgroundColorBlendType.Invalid;
                    }
                }
                else
                {
                    Graphics g = e.Graphics;
                    bounds = e.Bounds;
                    if (oldClip != null)
                    {
                        e.Graphics.SetClip(oldClip, CombineMode.Replace);
                        e.Graphics.SetClip(path, CombineMode.Intersect);
                    }
                    else
                        e.Graphics.SetClip(path, CombineMode.Replace);
                    BackgroundColorBlendCollection bc = style.BackColorBlend;
                    for (int i = 0; i < bc.Count; i+=2)
                    {
                        BackgroundColorBlend b1 = bc[i];
                        BackgroundColorBlend b2 = null;
                        if (i < bc.Count)
                            b2 = bc[i + 1];
                        if (b1 != null && b2 != null)
                        {
                            Rectangle rb = new Rectangle(bounds.X, bounds.Y + (int)b1.Position, bounds.Width,
                                (b2.Position == 1f ? bounds.Height : (int)b2.Position) - (int)b1.Position);
                            using (LinearGradientBrush brush = DisplayHelp.CreateLinearGradientBrush(rb, b1.Color, b2.Color, style.BackColorGradientAngle))
                                g.FillRectangle(brush, rb);
                        }
                    }
                }
            }
            
            if(blendType==eBackgroundColorBlendType.Invalid)
            {
                if (style.BackColor2.IsEmpty)
                {
                    if (!style.BackColor.IsEmpty)
                    {
                        using (SolidBrush brush = new SolidBrush(style.BackColor))
                            e.Graphics.FillPath(brush, path);
                        //if(e.Style.BackColor.A==255)
                        //{
                        //    // Correct problems with FillPath where path was not filled properly...
                        //    using(Pen pen=new Pen(e.Style.BackColor,1))
                        //        e.Graphics.DrawPath(pen,path);
                        //}
                    }
                }
                else if (!style.BackColor.IsEmpty)
                {
                    if (style.BackColorGradientType == eGradientType.Linear)
                    {
                        Rectangle rb = bounds;
                        rb.X--;
                        rb.Height++;
                        rb.Width += 2;
                        using (LinearGradientBrush brush = DisplayHelp.CreateLinearGradientBrush(rb, style.BackColor, style.BackColor2, style.BackColorGradientAngle))
                        {
                            e.Graphics.FillPath(brush, path);
                        }
                    }
                    else if (style.BackColorGradientType == eGradientType.Radial)
                    {
                        int d = (int)Math.Sqrt(bounds.Width * bounds.Width + bounds.Height * bounds.Height) + 4;
                        GraphicsPath fillPath = new GraphicsPath();
                        fillPath.AddEllipse(bounds.X - (d - bounds.Width) / 2, bounds.Y - (d - bounds.Height) / 2, d, d);
                        using (PathGradientBrush brush = new PathGradientBrush(fillPath))
                        {
                            brush.CenterColor = style.BackColor;
                            brush.SurroundColors = new Color[] { style.BackColor2 };
                            e.Graphics.FillPath(brush, path);
                        }
                        fillPath.Dispose();
                    }
                }
            }

            e.Graphics.SmoothingMode = sm;

            if (oldClip != null)
                e.Graphics.Clip = oldClip;
            else
                e.Graphics.ResetClip();

			
		}
Ejemplo n.º 7
0
		/// <summary>
        /// Paints text for given style.
		/// </summary>
        /// <param name="e">Display information.</param>
        /// <param name="text"><Text to paint./param>
        /// <param name="defaultFont">Default font if no font by style is specified.</param>
		/// <param name="useDefaultFont">Specifies whether to use default font for painting regardless of style settings.</param>
		public static void PaintText(ElementStyleDisplayInfo e, string text, Font defaultFont, bool useDefaultFont)
		{
            PaintText(e, text, defaultFont, useDefaultFont, e.Style.TextFormat);
		}
Ejemplo n.º 8
0
		/// <summary>
		/// Paint style border.
		/// </summary>
		/// <param name="e">Style display information.</param>
		public static void PaintBorder(ElementStyleDisplayInfo e)
		{
            ElementStyle style = GetElementStyle(e.Style);
			Rectangle bounds=ElementStyleDisplay.GetBorderRectangle(style,e.Bounds);
            if (bounds.Width < 2 || bounds.Height < 2)
                return;

            eCornerType cornerTopLeft = GetCornerType(style.CornerType, style.CornerTypeTopLeft);
            eCornerType cornerTopRight = GetCornerType(style.CornerType, style.CornerTypeTopRight);
            eCornerType cornerBottomLeft = GetCornerType(style.CornerType, style.CornerTypeBottomLeft);
            eCornerType cornerBottomRight = GetCornerType(style.CornerType, style.CornerTypeBottomRight);

            if (!style.BorderColor2.IsEmpty || !style.BorderColorLight.IsEmpty)
            {
                if (style.Border == eStyleBorderType.Solid)
                {
                    using (GraphicsPath path = DisplayHelp.GetRoundedRectanglePath(bounds, style.CornerDiameter, eStyleBackgroundPathPart.Complete,
                        cornerTopLeft, cornerTopRight, cornerBottomLeft, cornerBottomRight))
                    {
                        DisplayHelp.DrawGradientPathBorder(e.Graphics, path, style.BorderColor, style.BorderColor2, style.BorderGradientAngle, style.BorderWidth);
                    }
                    return;
                }
                else if (style.Border == eStyleBorderType.Etched)
                {
                    Rectangle r = bounds;
                    
                    r.Width -= style.BorderWidth;
                    r.Height -= style.BorderWidth;
                    r.Offset(style.BorderWidth, style.BorderWidth);
                    if (r.Width > 2 && r.Height > 2)
                    {
                        using (GraphicsPath path = DisplayHelp.GetRoundedRectanglePath(r, style.CornerDiameter, eStyleBackgroundPathPart.Complete,
                            cornerTopLeft, cornerTopRight, cornerBottomLeft, cornerBottomRight))
                        {
                            DisplayHelp.DrawGradientPathBorder(e.Graphics, path, style.BorderColorLight, style.BorderColorLight2, style.BorderLightGradientAngle, style.BorderWidth);
                        }
                        r.Offset(-style.BorderWidth, -style.BorderWidth);
                        using (GraphicsPath path = DisplayHelp.GetRoundedRectanglePath(r, style.CornerDiameter, eStyleBackgroundPathPart.Complete,
                            cornerTopLeft, cornerTopRight, cornerBottomLeft, cornerBottomRight))
                        {
                            DisplayHelp.DrawGradientPathBorder(e.Graphics, path, style.BorderColor, style.BorderColor2, style.BorderGradientAngle, style.BorderWidth);
                        }
                    }
                    return;
                }
                else if ((style.BorderTop == eStyleBorderType.Double && style.BorderLeft == eStyleBorderType.Double &&
                    style.BorderRight == eStyleBorderType.Double && style.BorderBottom == eStyleBorderType.Double) ||
                   (style.BorderTop == eStyleBorderType.None && style.BorderLeft == eStyleBorderType.Double &&
                   style.BorderRight == eStyleBorderType.Double && style.BorderBottom == eStyleBorderType.Double))
                    {
                    Rectangle r = bounds;
                    Region oldClip = null;
                    bool clipSet = false;
                    if (style.BorderTop == eStyleBorderType.None)
                    {
                        Rectangle clipRect = r;
                        clipRect.Width++;
                        clipRect.Height++;
                        e.Graphics.SetClip(clipRect);
                        r.Y -= 3;
                        r.Height += 3;
                    }
                    using(GraphicsPath path = DisplayHelp.GetBorderPath(r, style.CornerDiameter, eStyleBackgroundPathPart.Complete,
                        cornerTopLeft, cornerTopRight, cornerBottomLeft, cornerBottomRight, style.PaintLeftBorder, style.PaintRightBorder, 
                        style.PaintTopBorder, style.PaintBottomBorder))
                    {
                        using (Pen pen = new Pen(style.BorderColor, style.BorderWidth))
                            path.Widen(pen);
                        DisplayHelp.FillPath(e.Graphics, path, style.BorderColor, style.BorderColor2);
                    }
                    r.Inflate(-style.BorderWidth, -style.BorderWidth);
                    using (GraphicsPath path = DisplayHelp.GetBorderPath(r, style.CornerDiameter, eStyleBackgroundPathPart.Complete,
                        cornerTopLeft, cornerTopRight, cornerBottomLeft, cornerBottomRight, style.PaintLeftBorder, style.PaintRightBorder,
                        style.PaintTopBorder, style.PaintBottomBorder))
                    {
                        using (Pen pen = new Pen(style.BorderColor, style.BorderWidth))
                            path.Widen(pen);
                        DisplayHelp.FillPath(e.Graphics, path, style.BorderColorLight, style.BorderColorLight2);
                    }

                    if (clipSet)
                        e.Graphics.Clip = oldClip;

                    return;
                }
            }

            Color colorStart = style.BorderColor;
            Color colorEnd = style.BorderColor2;
            Color colorLightStart = style.BorderColorLight;
            Color colorLightEnd = style.BorderColorLight2;

			if(style.PaintLeftBorder)
			{
				Color color=style.BorderColor;
				if(!style.BorderLeftColor.IsEmpty)
					color=style.BorderLeftColor;
				Point[] p=new Point[2];

				// Corner type square is default setting
				p[0]=bounds.Location;
				p[1].X=bounds.X;
				p[1].Y=bounds.Bottom;

				if(cornerTopLeft!=eCornerType.Square)
				{
					p[0].Y+=style.CornerDiameter;
				}
				if(cornerBottomLeft!=eCornerType.Square)
				{
					p[1].Y-=style.CornerDiameter;
				}

                ElementStyleDisplay.DrawBorderLine(e.Graphics, p, style.BorderLeft, style.BorderLeftWidth, color, colorEnd, colorLightStart, colorLightEnd, eBorderSide.Left);

				if(style.PaintTopBorder && cornerTopLeft!=eCornerType.Square)
				{
					if(cornerTopLeft==eCornerType.Diagonal)
					{
						p[0].X=bounds.X;
						p[0].Y=bounds.Y+style.CornerDiameter;
						p[1].X=bounds.X+style.CornerDiameter;
						p[1].Y=bounds.Y;
                        ElementStyleDisplay.DrawBorderLine(e.Graphics, p, style.BorderLeft, style.BorderLeftWidth, color, colorEnd, colorLightStart, colorLightEnd, eBorderSide.TopLeft);
					}
					else if(cornerTopLeft==eCornerType.Rounded)
					{
						ArcData a=GetCornerArc(bounds,style.CornerDiameter,eCornerArc.TopLeft);// new ArcData(bounds.X,bounds.Y,style.CornerDiameter*2,style.CornerDiameter*2,180,90);
						ElementStyleDisplay.DrawCornerArc(e.Graphics,a,style.BorderLeft,style.BorderLeftWidth,color);
					}
				}

				if(style.PaintBottomBorder && cornerBottomLeft!=eCornerType.Square)
				{
					if(cornerBottomLeft==eCornerType.Diagonal)
					{
						p[0].X=bounds.X;
						p[0].Y=bounds.Bottom-style.CornerDiameter;
						p[1].X=bounds.X+style.CornerDiameter;
						p[1].Y=bounds.Bottom;
                        ElementStyleDisplay.DrawBorderLine(e.Graphics, p, style.BorderLeft, style.BorderLeftWidth, color, colorEnd, colorLightStart, colorLightEnd, eBorderSide.BottomLeft);
					}
					else if(cornerBottomLeft==eCornerType.Rounded)
					{
						ArcData a=GetCornerArc(bounds,style.CornerDiameter,eCornerArc.BottomLeft);// new ArcData(bounds.X,bounds.Y,style.CornerDiameter*2,style.CornerDiameter*2,180,90);
						ElementStyleDisplay.DrawCornerArc(e.Graphics,a,style.BorderLeft,style.BorderLeftWidth,color);
					}
				}
			}

			if(style.PaintTopBorder)
			{
				Color color=style.BorderColor;
				if(!style.BorderTopColor.IsEmpty)
					color=style.BorderTopColor;
				Point[] p=new Point[2];
				// Default setting for Square corner type on both sides
				p[0]=bounds.Location;
				p[1].X=bounds.Right;
				p[1].Y=bounds.Y;

				if(cornerTopLeft!=eCornerType.Square)
				{
					p[0].X+=style.CornerDiameter;
				}
				if(cornerTopRight!=eCornerType.Square)
				{
					p[1].X-=style.CornerDiameter;
				}
                ElementStyleDisplay.DrawBorderLine(e.Graphics, p, style.BorderTop, style.BorderTopWidth, color, colorEnd, colorLightStart, colorLightEnd, eBorderSide.Top);
			}

			if(style.PaintBottomBorder)
			{
				Color color=style.BorderColor;
				if(!style.BorderBottomColor.IsEmpty)
					color=style.BorderBottomColor;
				Point[] p=new Point[2];
				// Default for Square corner type on both sides
				p[0].X=bounds.X;
				p[0].Y=bounds.Bottom;
				p[1].X=bounds.Right;
				p[1].Y=bounds.Bottom;

				if(cornerBottomLeft!=eCornerType.Square)
				{
					p[0].X+=style.CornerDiameter;
				}
				if(cornerBottomRight!=eCornerType.Square)
				{
					p[1].X-=style.CornerDiameter;
				}

                ElementStyleDisplay.DrawBorderLine(e.Graphics, p, style.BorderBottom, style.BorderBottomWidth, color, colorEnd, colorLightStart, colorLightEnd, eBorderSide.Bottom);
			}

			if(style.PaintRightBorder)
			{
				Color color=style.BorderColor;
				if(!style.BorderRightColor.IsEmpty)
					color=style.BorderRightColor;
				Point[] p=new Point[2];
				// Default for Square corner type on both sides
				p[0].X=bounds.Right;
				p[0].Y=bounds.Y;
				p[1].X=bounds.Right;
				p[1].Y=bounds.Bottom;

				if(cornerTopRight!=eCornerType.Square)
				{
					p[0].Y+=style.CornerDiameter;
				}
				if(cornerBottomRight!=eCornerType.Square)
				{
					p[1].Y-=style.CornerDiameter;
				}

                ElementStyleDisplay.DrawBorderLine(e.Graphics, p, style.BorderRight, style.BorderRightWidth, color, colorEnd, colorLightStart, colorLightEnd, eBorderSide.Right);

				if(style.PaintTopBorder && cornerTopRight!=eCornerType.Square)
				{
					if(cornerTopRight==eCornerType.Diagonal)
					{
						p[0].X=bounds.Right-style.CornerDiameter;
						p[0].Y=bounds.Y;
						p[1].X=bounds.Right;
						p[1].Y=bounds.Y+style.CornerDiameter;
                        ElementStyleDisplay.DrawBorderLine(e.Graphics, p, style.BorderLeft, style.BorderRightWidth, color, colorEnd, colorLightStart, colorLightEnd, eBorderSide.TopRight);
					}
					else if(cornerTopRight==eCornerType.Rounded)
					{
						ArcData a=GetCornerArc(bounds,style.CornerDiameter,eCornerArc.TopRight);// new ArcData(bounds.X,bounds.Y,style.CornerDiameter*2,style.CornerDiameter*2,180,90);
						ElementStyleDisplay.DrawCornerArc(e.Graphics,a,style.BorderLeft,style.BorderLeftWidth,color);
					}
				}

				if(style.PaintBottomBorder && cornerBottomRight!=eCornerType.Square)
				{
					if(cornerBottomRight==eCornerType.Diagonal)
					{
						p[0].X=bounds.Right;
						p[0].Y=bounds.Bottom-style.CornerDiameter;
						p[1].X=bounds.Right-style.CornerDiameter;
						p[1].Y=bounds.Bottom;
						ElementStyleDisplay.DrawBorderLine(e.Graphics,p,style.BorderLeft,style.BorderRightWidth,color, colorEnd, colorLightStart, colorLightEnd,eBorderSide.BottomRight);
					}
					else if(cornerBottomRight==eCornerType.Rounded)
					{
						ArcData a=GetCornerArc(bounds,style.CornerDiameter,eCornerArc.BottomRight);// new ArcData(bounds.X,bounds.Y,style.CornerDiameter*2,style.CornerDiameter*2,180,90);
						ElementStyleDisplay.DrawCornerArc(e.Graphics,a,style.BorderLeft,style.BorderLeftWidth,color);
					}
				}
			}

		}
Ejemplo n.º 9
0
        /// <summary>
        /// Returns the clipping for the content of the element style.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static GraphicsPath GetInsideClip(ElementStyleDisplayInfo e)
        {
            Rectangle rectPath = e.Bounds;
            // GDI bug
            if (e.Style.PaintBorder)
            {
                if (e.Style.PaintTopBorder)
                {
                    rectPath.Y += e.Style.BorderTopWidth;
                    rectPath.Height -= e.Style.BorderTopWidth;

                    if (e.Style.BorderTop == eStyleBorderType.Etched || e.Style.BorderTop == eStyleBorderType.Double)
                    {
                        rectPath.Y += e.Style.BorderTopWidth;
                        rectPath.Height -= e.Style.BorderTopWidth;
                    }
                }

                if (e.Style.PaintBottomBorder)
                {
                    rectPath.Height -= e.Style.BorderBottomWidth;
                    if (e.Style.BorderBottom == eStyleBorderType.Etched || e.Style.BorderBottom == eStyleBorderType.Double)
                        rectPath.Height -= e.Style.BorderBottomWidth;
                }

                if (e.Style.PaintLeftBorder)
                {
                    rectPath.X += e.Style.BorderLeftWidth;
                    rectPath.Width -= e.Style.BorderLeftWidth;
                    if (e.Style.BorderLeft == eStyleBorderType.Etched || e.Style.BorderLeft == eStyleBorderType.Double)
                    {
                        rectPath.X += e.Style.BorderLeftWidth;
                        rectPath.Width -= e.Style.BorderLeftWidth;
                    }
                }

                if (e.Style.PaintRightBorder)
                {
                    rectPath.Width -= e.Style.BorderRightWidth;
                    if (e.Style.BorderRight == eStyleBorderType.Etched || e.Style.BorderRight == eStyleBorderType.Double)
                        rectPath.Width -= e.Style.BorderRightWidth;
                }
            }

            GraphicsPath path = ElementStyleDisplay.GetBackgroundPath(e.Style, rectPath);

            return path;
        }
Ejemplo n.º 10
0
		private void PaintSingleNode(Node node, NodeDisplayContext context)
		{
			Rectangle r=NodeDisplay.GetNodeRectangle(eNodeRectanglePart.NodeContentBounds,node,context.Offset);
			NodeRenderer renderer=context.NodeRenderer;
			if(node.NodeRenderer!=null && node.RenderMode==eNodeRenderMode.Custom)
				renderer = node.NodeRenderer;
			
			// Paint node background
			ElementStyle style=context.DefaultNodeStyle.Copy();
			if(node.Style!=null)
				style=node.Style.Copy();

			bool bApllyStyles=true;

			if(node.MouseOverNodePart==eMouseOverNodePart.Node && style!=null)
			{
				ElementStyle mouseOverStyle=context.MouseOverNodeStyle;
				if(node.StyleMouseOver!=null)
					mouseOverStyle=node.StyleMouseOver;
                if (mouseOverStyle != null)
                {
                    style.ApplyStyle(mouseOverStyle);
                    bApllyStyles = false;
                }
			}

			// On default style apply expanded style
			if(bApllyStyles && node.Expanded && style!=null)
			{
				ElementStyle expandedStyle=context.ExpandedNodeStyle;
				if(node.StyleExpanded!=null)
					expandedStyle=node.StyleExpanded;
				if(expandedStyle!=null)
					style.ApplyStyle(expandedStyle);
			}

			// Apply selected style if needed too
			if(bApllyStyles && node.IsSelected && style!=null)
			{
				ElementStyle selectedStyle=context.SelectedNodeStyle;
				if(node.StyleSelected!=null)
					selectedStyle=node.StyleSelected;
				if(selectedStyle!=null)
					style.ApplyStyle(selectedStyle);
			}

			Region backRegion=null;
			if(style!=null)
			{
				if(style.Font==null)
					style.Font=context.DefaultFont;
				context.NodeRendererEventArgs.Graphics=context.Graphics;
				context.NodeRendererEventArgs.Node = node;
				context.NodeRendererEventArgs.NodeBounds = r;
				context.NodeRendererEventArgs.Style = style;
				renderer.DrawNodeBackground(context.NodeRendererEventArgs);
				ElementStyleDisplayInfo di=new ElementStyleDisplayInfo(style,context.Graphics,DisplayHelp.GetDrawRectangle(r));
				//ElementStyleDisplay.Paint(di);
				backRegion=ElementStyleDisplay.GetStyleRegion(di);
			}
						
			if(NodeDisplay.DrawExpandPart(node))
			{
				r=NodeDisplay.GetNodeRectangle(eNodeRectanglePart.ExpandBounds,node,context.Offset);
				context.ExpandDisplayInfo.Node=node;
				context.ExpandDisplayInfo.ExpandPartBounds=r;
				//context.ExpandDisplayInfo.MouseOver=(node.MouseOverNodePart==eMouseOverNodePart.Expand);
				//context.ExpandDisplay.DrawExpandButton(context.ExpandDisplayInfo);
				
				renderer.DrawNodeExpandPart(context.ExpandDisplayInfo);
			}

			// TODO: Support for display of columns should go here
//			if(node.NodesColumnHeaderVisible)
//			{
//				foreach(ColumnHeader col in node.NodesColumns)
//				{
//					r=col.Bounds;
//					r.Offset(context.Offset);
//					r.Offset(node.Bounds.Location);
//					using(Pen pen=new Pen(Color.Yellow))
//						context.Graphics.DrawRectangle(pen,Display.GetDrawRectangle(r));
//				}
//			}

			Region oldRegion=null;
			if(backRegion!=null)
			{
				oldRegion=context.Graphics.Clip;
				context.Graphics.SetClip(backRegion,CombineMode.Replace);
			}

			if(!node.CommandBoundsRelative.IsEmpty)
			{
				r=NodeDisplay.GetNodeRectangle(eNodeRectanglePart.CommandBounds,node,context.Offset);
                context.CommandDisplayInfo.Node=node;
				context.CommandDisplayInfo.CommandPartBounds=r;
				context.CommandDisplayInfo.Graphics = context.Graphics;
				//context.CommandDisplay.DrawCommandButton(context.CommandDisplayInfo);
				renderer.DrawNodeCommandPart(context.CommandDisplayInfo);
				context.CommandDisplayInfo.Graphics = null;
			}
			
			ElementStyle cellStyle = null;
			if(context.CellStyleDefault==null)
			{
				cellStyle=new ElementStyle();
				cellStyle.TextColor = style.TextColor;
				cellStyle.TextShadowColor = style.TextShadowColor;
				cellStyle.TextShadowOffset = style.TextShadowOffset;
				cellStyle.TextAlignment = style.TextAlignment;
				cellStyle.TextLineAlignment = style.TextLineAlignment;
				cellStyle.WordWrap = style.WordWrap;
				cellStyle.Font = style.Font;
			}

			foreach(Cell cell in node.Cells)
			{
				if(cell.StyleNormal!=null)
					style=cell.StyleNormal;
				else if(context.CellStyleDefault!=null)
					style=context.CellStyleDefault.Copy();
				else
					style = cellStyle;

				if(!cell.Enabled && cell.StyleDisabled!=null)
					style.ApplyStyle(cell.StyleDisabled);
				else if(!cell.Enabled && context.CellStyleDisabled!=null)
					style.ApplyStyle(context.CellStyleDisabled);
				else if(cell.IsMouseDown && cell.StyleMouseDown!=null)
					style.ApplyStyle(cell.StyleMouseDown);
				else if(cell.IsMouseDown && context.CellStyleMouseDown!=null)
					style.ApplyStyle(context.CellStyleMouseDown);
				else 
				{
					if(cell.IsSelected && cell.StyleSelected!=null)
						style.ApplyStyle(cell.StyleSelected);
					else if(cell.IsSelected && context.CellStyleSelected!=null)
						style.ApplyStyle(context.CellStyleSelected);

					if(cell.IsMouseOver && cell.StyleMouseOver!=null)
						style.ApplyStyle(cell.StyleMouseOver);
					else if(cell.IsMouseOver && context.CellStyleMouseOver!=null)
						style.ApplyStyle(context.CellStyleMouseOver);
				}

				r=NodeDisplay.GetNodeRectangle(eNodeRectanglePart.NodeBounds,node,context.Offset);
				
				if(style!=null)
				{
					if(style.Font==null)
						style.Font=context.DefaultFont;
					Rectangle rCell=cell.BoundsRelative;
					Rectangle rText=cell.TextContentBounds;
					rCell.Offset(r.Location);
					rText.Offset(r.Location);
					ElementStyleDisplayInfo di=GetElementStyleDisplayInfo(style,context.Graphics,DisplayHelp.GetDrawRectangle(rCell));
					ElementStyleDisplay.Paint(di);
					NodeCellRendererEventArgs ci=GetCellDisplayInfo(style,context.Graphics,cell,r.Location, rCell, rText);
					
					if(ci.Cell.CheckBoxVisible)
						renderer.DrawCellCheckBox(ci); //CellDisplay.PaintCellCheckBox(ci);
					if(!ci.Cell.Images.LargestImageSize.IsEmpty)
						renderer.DrawCellImage(ci); //CellDisplay.PaintCellImage(ci);
					renderer.DrawCellText(ci) ; //CellDisplay.PaintText(ci);
					
					//CellDisplay.PaintCell(ci);
				}
			}

			if(backRegion!=null)
				context.Graphics.SetClip(oldRegion,CombineMode.Replace);
		}
Ejemplo n.º 11
0
        /// <summary>
        /// Paints style background image.
        /// </summary>
        /// <param name="e">Style display information.</param>
        public static void PaintBackgroundImage(ElementStyleDisplayInfo e)
        {
            bool disposeStyle = false;
            ElementStyle style = GetElementStyle(e.Style, out disposeStyle);
            GraphicsPath path = null;
            try
            {
                if (style.BackgroundImage == null)
                    return;

                Rectangle bounds = ElementStyleDisplay.GetBackgroundRectangle(style, e.Bounds);
                if (e.Graphics.SmoothingMode == SmoothingMode.AntiAlias)
                {
                    Rectangle r = e.Bounds;
                    //r.Width--;
                    //r.Height--;
                    path = ElementStyleDisplay.GetBackgroundPath(style, r);
                }
                else
                    path = ElementStyleDisplay.GetBackgroundPath(style, e.Bounds);

                ImageAttributes imageAtt = null;

                if (style.BackgroundImageAlpha != 255)
                {
                    //ColorMatrix colorMatrix = new ColorMatrix();
                    //colorMatrix.Matrix33 = 255 - style.BackgroundImageAlpha;
                    float[][] matrixItems ={ 
                       new float[] {1, 0, 0, 0, 0},
                       new float[] {0, 1, 0, 0, 0},
                       new float[] {0, 0, 1, 0, 0},
                       new float[] {0, 0, 0, (float)style.BackgroundImageAlpha/255, 0}, 
                       new float[] {0, 0, 0, 0, 1}};
                        System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(matrixItems);
                    imageAtt = new ImageAttributes();
                    imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                }

                Region clip = e.Graphics.Clip;
                e.Graphics.SetClip(path, CombineMode.Intersect);

                eStyleBackgroundImage imagePosition = style.BackgroundImagePosition;
                bool transform = false;
                Image backgroundImage = style.BackgroundImage;

                if (e.RightToLeft)
                {
                    if (imagePosition == eStyleBackgroundImage.TopLeft)
                    {
                        imagePosition = eStyleBackgroundImage.TopRight;
                        transform = true;
                    }
                    else if (imagePosition == eStyleBackgroundImage.TopRight)
                        imagePosition = eStyleBackgroundImage.TopLeft;
                    else if (imagePosition == eStyleBackgroundImage.BottomLeft)
                        imagePosition = eStyleBackgroundImage.BottomRight;
                    else if (imagePosition == eStyleBackgroundImage.BottomRight)
                        imagePosition = eStyleBackgroundImage.BottomLeft;
                }

                if (transform)
                {
                    backgroundImage = backgroundImage.Clone() as Image;
                    backgroundImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
                }

                switch (imagePosition)
                {
                    case eStyleBackgroundImage.Stretch:
                        {
                            if (imageAtt != null)
                                e.Graphics.DrawImage(backgroundImage, bounds, 0, 0, backgroundImage.Width,
                                                     backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
                            else
                                e.Graphics.DrawImage(backgroundImage, bounds, 0, 0, backgroundImage.Width,
                                                     backgroundImage.Height, GraphicsUnit.Pixel);
                            break;
                        }
                    case eStyleBackgroundImage.Zoom:
                        {
                            Size backImageSize = backgroundImage.Size;
                            Rectangle newImageBounds = Rectangle.Empty;
                            float horizontalRatio = ((float) bounds.Width) / ((float) backImageSize.Width);
                            float verticalRatio = ((float) bounds.Height) / ((float) backImageSize.Height);
                            if (horizontalRatio >= verticalRatio)
                            {
                                newImageBounds.Height = bounds.Height;
                                newImageBounds.Width = (int)((backImageSize.Width * verticalRatio) + 0.5);
                                if (bounds.X >= 0)
                                {
                                    newImageBounds.X = (bounds.Width - newImageBounds.Width) / 2;
                                }
                            }
                            else
                            {
                                newImageBounds.Width = bounds.Width;
                                newImageBounds.Height = (int)((backImageSize.Height * horizontalRatio) + 0.5);
                                if (bounds.Y >= 0)
                                {
                                    newImageBounds.Y = (bounds.Height - newImageBounds.Height) / 2;
                                }
                            }
                            bounds = newImageBounds;
            
                            if (imageAtt != null)
                            {
    
                                e.Graphics.DrawImage(backgroundImage, bounds, 0, 0, backgroundImage.Width,
                                                     backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
                            }
                            else
                                e.Graphics.DrawImage(backgroundImage, bounds, 0, 0, backgroundImage.Width,
                                                     backgroundImage.Height, GraphicsUnit.Pixel);
                            break;
                        }
                    case eStyleBackgroundImage.Center:
                        {
                            Rectangle destRect = new Rectangle(bounds.X, bounds.Y, backgroundImage.Width,
                                                               backgroundImage.Height);
                            if (bounds.Width > backgroundImage.Width)
                                destRect.X += (bounds.Width - backgroundImage.Width)/2;
                            if (bounds.Height > backgroundImage.Height)
                                destRect.Y += (bounds.Height - backgroundImage.Height)/2;
                            if (imageAtt != null)
                                e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width,
                                                     backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
                            else
                                e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width,
                                                     backgroundImage.Height, GraphicsUnit.Pixel);

                            break;
                        }
                    case eStyleBackgroundImage.TopLeft:
                    case eStyleBackgroundImage.TopRight:
                    case eStyleBackgroundImage.BottomLeft:
                    case eStyleBackgroundImage.BottomRight:
                        {
                            Rectangle destRect = new Rectangle(bounds.X, bounds.Y, backgroundImage.Width,
                                                               backgroundImage.Height);
                            if (imagePosition == eStyleBackgroundImage.TopRight)
                                destRect.X = bounds.Right - backgroundImage.Width;
                            else if (imagePosition == eStyleBackgroundImage.BottomLeft)
                                destRect.Y = bounds.Bottom - backgroundImage.Height;
                            else if (imagePosition == eStyleBackgroundImage.BottomRight)
                            {
                                destRect.Y = bounds.Bottom - backgroundImage.Height;
                                destRect.X = bounds.Right - backgroundImage.Width;
                            }

                            if (imageAtt != null)
                                e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width,
                                                     backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
                            else
                                e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width,
                                                     backgroundImage.Height, GraphicsUnit.Pixel);
                            break;
                        }
                    case eStyleBackgroundImage.Tile:
                        {
                            if (imageAtt != null)
                            {
                                if (bounds.Width > backgroundImage.Width || bounds.Height > backgroundImage.Height)
                                {
                                    int x = bounds.X, y = bounds.Y;
                                    while (y < bounds.Bottom)
                                    {
                                        while (x < bounds.Right)
                                        {
                                            Rectangle destRect = new Rectangle(x, y, backgroundImage.Width,
                                                                               backgroundImage.Height);
                                            if (destRect.Right > bounds.Right)
                                                destRect.Width = destRect.Width - (destRect.Right - bounds.Right);
                                            if (destRect.Bottom > bounds.Bottom)
                                                destRect.Height = destRect.Height - (destRect.Bottom - bounds.Bottom);
                                            e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, destRect.Width,
                                                                 destRect.Height, GraphicsUnit.Pixel, imageAtt);
                                            x += backgroundImage.Width;
                                        }
                                        x = bounds.X;
                                        y += backgroundImage.Height;
                                    }
                                }
                                else
                                {
                                    e.Graphics.DrawImage(backgroundImage,
                                                         new Rectangle(0, 0, backgroundImage.Width,
                                                                       backgroundImage.Height), 0, 0,
                                                         backgroundImage.Width, backgroundImage.Height,
                                                         GraphicsUnit.Pixel, imageAtt);
                                }
                            }
                            else
                            {
                                TextureBrush brush = new TextureBrush(backgroundImage);
                                brush.WrapMode = WrapMode.Tile;
                                e.Graphics.FillPath(brush, path);
                                brush.Dispose();
                            }
                            break;
                        }
                }
                if (transform)
                {
                    backgroundImage.Dispose();
                }

                if (clip != null)
                {
                    e.Graphics.Clip = clip;
                    clip.Dispose();
                }
                else
                    e.Graphics.ResetClip();
            }
            finally
            {
                if (path != null) path.Dispose();
                if(disposeStyle) style.Dispose();
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Paints style background.
 /// </summary>
 /// <param name="e">Style display information.</param>
 public static void PaintBackground(ElementStyleDisplayInfo e)
 {
     PaintBackground(e, true);
 }
Ejemplo n.º 13
0
        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;
                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.Width, image.Height, GraphicsUnit.Pixel, att);
                }
                else
                {
                    image.DrawImage(g, imageBounds);
                }
            }

            //g.FillRectangle(Brushes.Red, bounds);
        }
Ejemplo n.º 14
0
		/// <summary>
		/// Draws the tree background. If you need to provide custom rendering this is the method that you should override in your custom rendered. If you
		/// do not want default rendering to occur do not call the base implementation. You can call OnRenderTreeBackground method so events can occur.
		/// </summary>
		/// <param name="e">Information provided for rendering.</param>
		public override void DrawTreeBackground(TreeBackgroundRendererEventArgs e)
		{
			TreeGX tree = e.TreeGX;
			Graphics g = e.Graphics;
			
			if(!tree.BackColor.IsEmpty)
			{
				using(SolidBrush brush=new SolidBrush(tree.BackColor))
					g.FillRectangle(brush,tree.DisplayRectangle);
			}

			ElementStyleDisplayInfo info=new ElementStyleDisplayInfo();
			info.Bounds=tree.DisplayRectangle;
			info.Graphics=g;
			info.Style=tree.BackgroundStyle;
			ElementStyleDisplay.Paint(info);
			
			base.DrawTreeBackground (e);
		}
        protected virtual void PaintBackground(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Rectangle r = this.ClientRectangle;
            bool disposeStyle = false;
            ElementStyle style = this.GetBackgroundStyle(out disposeStyle);

            if (!this.BackColor.IsEmpty)
            {
                DisplayHelp.FillRectangle(g, r, this.BackColor);
            }

            if (style.Custom)
            {
                SmoothingMode sm = g.SmoothingMode;
                if (this.AntiAlias)
                    g.SmoothingMode = SmoothingMode.HighQuality;
                ElementStyleDisplayInfo displayInfo = new ElementStyleDisplayInfo(style, e.Graphics, r);
                ElementStyleDisplay.Paint(displayInfo);
                if (this.AntiAlias)
                    g.SmoothingMode = sm;
            }

            if (disposeStyle) style.Dispose();
        }
Ejemplo n.º 16
0
		private void PaintStyleBackground(Graphics g)
		{
			Display.NodeRenderer renderer = this.NodeRenderer;
			if(renderer!=null)
			{
				this.NodeRenderer.DrawTreeBackground(new TreeBackgroundRendererEventArgs(g, this));
				return;
			}
			
			if(!this.BackColor.IsEmpty)
			{
				using(SolidBrush brush=new SolidBrush(this.BackColor))
					g.FillRectangle(brush,this.DisplayRectangle);
			}

			ElementStyleDisplayInfo info=new ElementStyleDisplayInfo();
			info.Bounds=this.DisplayRectangle;
			info.Graphics=g;
			info.Style=m_BackgroundStyle;
			ElementStyleDisplay.Paint(info);
		}
Ejemplo n.º 17
0
        protected override void OnPaint(PaintEventArgs e)
        {
            ElementStyle style = GetBackgroundStyle();
            if (style.BackColor.A < 255 && !style.BackColor.IsEmpty ||
                this.BackColor == Color.Transparent || this.BackgroundImage != null)
            {
                base.OnPaintBackground(e);
            }
            else
            {
                using (SolidBrush brush = new SolidBrush(this.BackColor))
                    e.Graphics.FillRectangle(brush, this.ClientRectangle);
            }

            ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, e.Graphics, this.ClientRectangle);
            ElementStyleDisplay.PaintBackground(info);
        }
Ejemplo n.º 18
0
		/// <summary>
		/// Paints the element style on the canvas.
		/// </summary>
		/// <param name="e">Holds information neccessary to paint style on canvas.</param>
		public static void Paint(ElementStyleDisplayInfo e)
		{
			ElementStyleDisplay.PaintBackground(e);
			ElementStyleDisplay.PaintBackgroundImage(e);
			ElementStyleDisplay.PaintBorder(e);
		}
Ejemplo n.º 19
0
        /// <summary>
        /// Paints insides of the control.
        /// </summary>
        /// <param name="e">Paint event arguments.</param>
        protected override void PaintInnerContent(PaintEventArgs e, ElementStyle style, bool paintText)
        {
            Graphics g = e.Graphics;
            if (this.TextMarkupElement == null)
                RefreshTextClientRectangle();
            Rectangle r = this.DisplayRectangle;
#if FRAMEWORK20
            r.X -= this.Padding.Left;
            r.Y -= this.Padding.Top;
            r.Width += this.Padding.Horizontal;
            r.Height += this.Padding.Vertical;
#else
            r.X -= this.DockPadding.Left;
            r.Y -= this.DockPadding.Top;
            r.Width += this.DockPadding.Left + this.DockPadding.Right;
            r.Height += this.DockPadding.Top + this.DockPadding.Bottom;
#endif
            r.Inflate(2, 2);
            ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, g, r);
            info.RightToLeft = (this.RightToLeft == RightToLeft.Yes);
            ElementStyleDisplay.PaintBackground(info, false);
            if (style.BackgroundImage != null) ElementStyleDisplay.PaintBackgroundImage(info);
            if (!m_IsShadowEnabled) return;
            ShadowPaintInfo pi = new ShadowPaintInfo();
            pi.Graphics = g;
            pi.Size = 6;
            foreach (Control c in this.Controls)
            {
                if (!c.Visible || c.BackColor == Color.Transparent && !(c is GroupPanel)) continue;
                if (c is GroupPanel)
                {
                    GroupPanel p = c as GroupPanel;
                    pi.Rectangle = new Rectangle(c.Bounds.X, c.Bounds.Y + p.GetInternalClientRectangle().Y / 2, c.Bounds.Width, c.Bounds.Height - p.GetInternalClientRectangle().Y / 2);
                }
                else
                    pi.Rectangle = c.Bounds;
                ShadowPainter.Paint2(pi);
            }
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Paints text for given style.
 /// </summary>
 /// <param name="e">Display information.</param>
 /// <param name="text">Text to paint.</param>
 /// <param name="defaultFont">Default font if no font by style is specified.</param>
 public static void PaintText(ElementStyleDisplayInfo e, string text, Font defaultFont)
 {
     PaintText(e, text, defaultFont, false);
 }
Ejemplo n.º 21
0
        private void NCAfterBorderPaint(object sender, CustomNCPaintEventArgs e)
        {
            Graphics g = e.Graphics;

            TextRenderingHint th = g.TextRenderingHint;
            SmoothingMode sm = g.SmoothingMode;
            if (this.AntiAlias)
            {
                g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }
            g.ResetClip();
            ElementStyle style = this.Style;

            if (!this.Enabled)
            {
                style = style.Copy();
                style.TextColor = GetColorScheme().ItemDisabledText;
            }

            if (m_DrawTitleBox && !m_TitleArea.IsEmpty)
            {
                DisplayHelp.FillRoundedRectangle(g, m_TitleArea, 2, style.BackColor, style.BackColor2, -90);
                DisplayHelp.DrawRoundedRectangle(g, this.Style.BorderColor, m_TitleArea, 2);
            }

            Rectangle rText = new Rectangle(m_NCPainter.ClientRectangle.X + 4, 1, this.ClientRectangle.Width - 8, m_NCPainter.ClientRectangle.Y - 1);
            if (m_TitleImage != null)
            {
                Size textSize = GetAutoSize(rText.Width);
                if (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.No || m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.Yes)
                {
                    g.DrawImage(m_TitleImage, rText.X - 1, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
                    rText.X += m_TitleImage.Width;
                    rText.Width -= m_TitleImage.Width;
                }
                else if (m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.No || m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.Yes)
                {
                    g.DrawImage(m_TitleImage, rText.Right - m_TitleImage.Width, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
                    rText.Width -= m_TitleImage.Width;
                }
                else if (m_TitleImagePosition == eTitleImagePosition.Center)
                {
                    g.DrawImage(m_TitleImage, rText.X + (rText.Width - m_TitleImage.Width) / 2, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
                }
                rText.Y = rText.Bottom - textSize.Height - 2;
            }

            // Paint text
            if (this.TextMarkupElement == null)
            {
                ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, g, rText);
                info.RightToLeft = (this.RightToLeft == RightToLeft.Yes);
                ElementStyleDisplay.PaintText(info, this.Text, this.Font);
            }
            else
            {
                TextRenderingHint tr = g.TextRenderingHint;
                if (this.AntiAlias)
                    g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, style.TextColor, (this.RightToLeft == RightToLeft.Yes), Rectangle.Empty, true);
                Rectangle r = this.TextMarkupElement.Bounds;
                if (style.TextAlignment == eStyleTextAlignment.Center)
                    this.TextMarkupElement.Bounds = new Rectangle(this.TextMarkupElement.Bounds.X + (rText.Width - this.TextMarkupElement.Bounds.Width) / 2, this.TextMarkupElement.Bounds.Y,
                        this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Height);
                else if(style.TextAlignment == eStyleTextAlignment.Far && this.RightToLeft == RightToLeft.No || this.RightToLeft == RightToLeft.Yes && style.TextAlignment== eStyleTextAlignment.Near)
                    this.TextMarkupElement.Bounds = new Rectangle(rText.Right - this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Y,
                        this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Height);
                this.TextMarkupElement.Render(d);
                g.TextRenderingHint = tr;
                this.TextMarkupElement.Bounds = r;
            }

            g.TextRenderingHint = th;
            g.SmoothingMode = sm;
        }
Ejemplo n.º 22
0
 protected override void OnPaint(PaintEventArgs e)
 {
     Graphics g = e.Graphics;
     if (_Style != null)
     {
         ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(_Style, g, this.ClientRectangle);
         ElementStyleDisplay.Paint(di);
     }
     base.OnPaint(e);
 }
Ejemplo n.º 23
0
        private void PaintBorder(Graphics g)
        {
            ElementStyle style = ((INonClientControl)m_Control).BorderStyle;
            Rectangle r = GetControlRectangle();
            if (style == null || r.Width <= 0 || r.Height <= 0) return;
            
            ElementStyleDisplayInfo displayInfo = new ElementStyleDisplayInfo(style, g, r);

            if (style.BackColor == Color.Transparent && (style.BackColor2.IsEmpty || style.BackColor2 == Color.Transparent))
            {
                ((INonClientControl)m_Control).PaintBackground(new PaintEventArgs(g, r));
            }
            else
            {
                if (style.BackColor.IsEmpty && m_Control.BackColor != Color.Transparent)
                {
                    using (SolidBrush brush = new SolidBrush((m_Control.Enabled ? m_Control.BackColor : SystemColors.Control)))
                        g.FillRectangle(brush, r);
                }
                else
                {
                    if (m_Control.BackColor == Color.Transparent || style.PaintBorder && (style.CornerType == eCornerType.Rounded || style.CornerType == eCornerType.Diagonal ||
                        style.CornerTypeBottomLeft == eCornerType.Rounded || style.CornerTypeBottomLeft == eCornerType.Diagonal ||
                        style.CornerTypeBottomRight == eCornerType.Rounded || style.CornerTypeBottomRight == eCornerType.Diagonal ||
                        style.CornerTypeTopLeft == eCornerType.Rounded || style.CornerTypeTopLeft == eCornerType.Diagonal ||
                        style.CornerTypeTopRight == eCornerType.Rounded || style.CornerTypeTopRight == eCornerType.Diagonal))
                    {
                        if (m_Control is TextBox || m_Control.BackColor == Color.Transparent)
                            ((INonClientControl)m_Control).PaintBackground(new PaintEventArgs(g, r));
                        else
                            using (SolidBrush brush = new SolidBrush(m_Control.BackColor))
                                g.FillRectangle(brush, r);
                    }
                    else
                    {
                        using (SolidBrush brush = new SolidBrush(m_Control.BackColor))
                            g.FillRectangle(brush, r);
                    }
                }

                Rectangle rback = r;
                if (style.PaintBorder)
                {
                    if (style.PaintRightBorder && style.BorderRightWidth > 1)
                        rback.Width--;
                    if (style.PaintBottomBorder && style.BorderBottomWidth > 1)
                        rback.Height--;
                }
                m_Control.AdjustBorderRectangle(ref rback);
                displayInfo.Bounds = rback;
                ElementStyleDisplay.PaintBackground(displayInfo);
                m_Control.RenderNonClient(g);
            }

            SmoothingMode sm = g.SmoothingMode;
            if (style.PaintBorder && (style.CornerType == eCornerType.Rounded || style.CornerType == eCornerType.Diagonal))
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            m_Control.AdjustBorderRectangle(ref r);
            displayInfo.Bounds = r;
            this.BeforePaintBorder(g, r);
            ElementStyleDisplay.PaintBorder(displayInfo);
            g.SmoothingMode = sm;
            this.AfterPaintBorder(g, r);
        }
Ejemplo n.º 24
0
		/// <summary>
		/// Paints style background image.
		/// </summary>
		/// <param name="e">Style display information.</param>
		public static void PaintBackgroundImage(ElementStyleDisplayInfo e)
		{
            ElementStyle style = GetElementStyle(e.Style);
			if(style.BackgroundImage==null)
				return;

            Rectangle bounds = DisplayHelp.GetDrawRectangle(ElementStyleDisplay.GetBackgroundRectangle(style, e.Bounds));
			GraphicsPath path;
			if (e.Graphics.SmoothingMode == SmoothingMode.AntiAlias)
			{
				Rectangle r = e.Bounds;
				r.Width--;
				//r.Height--;
                path = ElementStyleDisplay.GetBackgroundPath(style, r);
			}
			else
                path = ElementStyleDisplay.GetBackgroundPath(style, e.Bounds);
			
			ImageAttributes imageAtt=null;

            if (style.BackgroundImageAlpha != 255)
			{
				ColorMatrix colorMatrix=new ColorMatrix();
                colorMatrix.Matrix33 = 255 - style.BackgroundImageAlpha;
				imageAtt=new ImageAttributes();
				imageAtt.SetColorMatrix(colorMatrix,ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
			}

			Region clip=e.Graphics.Clip;
			e.Graphics.SetClip(path);

            eStyleBackgroundImage imagePosition = style.BackgroundImagePosition;
            bool transform = false;
            Image backgroundImage = style.BackgroundImage;

            if (e.RightToLeft)
            {
                if (imagePosition == eStyleBackgroundImage.TopLeft)
                {
                    imagePosition = eStyleBackgroundImage.TopRight;
                    transform = true;
                }
                else if (imagePosition == eStyleBackgroundImage.TopRight)
                    imagePosition = eStyleBackgroundImage.TopLeft;
                else if (imagePosition == eStyleBackgroundImage.BottomLeft)
                    imagePosition = eStyleBackgroundImage.BottomRight;
                else if (imagePosition == eStyleBackgroundImage.BottomRight)
                    imagePosition = eStyleBackgroundImage.BottomLeft;
            }

            if (transform)
            {
                backgroundImage = backgroundImage.Clone() as Image;
                backgroundImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
            }

            switch (imagePosition)
			{
				case eStyleBackgroundImage.Stretch:
				{
					if(imageAtt!=null)
                        e.Graphics.DrawImage(backgroundImage, bounds, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
					else
                        e.Graphics.DrawImage(backgroundImage, bounds, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);
					break;
				}
				case eStyleBackgroundImage.Center:
				{
                    Rectangle destRect = new Rectangle(bounds.X, bounds.Y, backgroundImage.Width, backgroundImage.Height);
                    if (bounds.Width > backgroundImage.Width)
                        destRect.X += (bounds.Width - backgroundImage.Width) / 2;
                    if (bounds.Height > backgroundImage.Height)
                        destRect.Y += (bounds.Height - backgroundImage.Height) / 2;
					if(imageAtt!=null)
                        e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
					else
                        e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);
					
					break;
				}
				case eStyleBackgroundImage.TopLeft:
				case eStyleBackgroundImage.TopRight:
				case eStyleBackgroundImage.BottomLeft:
				case eStyleBackgroundImage.BottomRight:
				{
                    Rectangle destRect = new Rectangle(bounds.X, bounds.Y, backgroundImage.Width, backgroundImage.Height);
                    if (imagePosition == eStyleBackgroundImage.TopRight)
                        destRect.X = bounds.Right - backgroundImage.Width;
                    else if (imagePosition == eStyleBackgroundImage.BottomLeft)
                        destRect.Y = bounds.Bottom - backgroundImage.Height;
                    else if (imagePosition == eStyleBackgroundImage.BottomRight)
					{
                        destRect.Y = bounds.Bottom - backgroundImage.Height;
                        destRect.X = bounds.Right - backgroundImage.Width;
					}

					if(imageAtt!=null)
                        e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
					else
                        e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);
					break;
				}
				case eStyleBackgroundImage.Tile:
				{
					if(imageAtt!=null)
					{
                        if (bounds.Width > backgroundImage.Width || bounds.Height > backgroundImage.Height)
						{
							int x=bounds.X,y=bounds.Y;
							while(y<bounds.Bottom)
							{
								while(x<bounds.Right)
								{
                                    Rectangle destRect = new Rectangle(x, y, backgroundImage.Width, backgroundImage.Height);
									if(destRect.Right>bounds.Right)
										destRect.Width=destRect.Width-(destRect.Right-bounds.Right);
									if(destRect.Bottom>bounds.Bottom)
										destRect.Height=destRect.Height-(destRect.Bottom-bounds.Bottom);
                                    e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, destRect.Width, destRect.Height, GraphicsUnit.Pixel, imageAtt);
                                    x += backgroundImage.Width;
								}
								x=bounds.X;
                                y += backgroundImage.Height;
							}
						}
						else
						{
                            e.Graphics.DrawImage(backgroundImage, new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height), 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
						}
					}
					else
					{
                        TextureBrush brush = new TextureBrush(backgroundImage);
						brush.WrapMode=WrapMode.Tile;
						e.Graphics.FillPath(brush,path);
						brush.Dispose();
					}
					break;
				}
			}
            if (transform)
            {
                backgroundImage.Dispose();
            }

			if (clip != null)
				e.Graphics.Clip = clip;
			else
				e.Graphics.ResetClip();
		}
Ejemplo n.º 25
0
        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.IsMouseOver)
                textRect.Inflate(-InflatePixels, -InflatePixels);
            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 = item.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.Symbol))
            {
                Font symFont = null;
                Rectangle imageRect = Rectangle.Empty;
                if (string.IsNullOrEmpty(frame.Symbol))
                    imageRect = new Rectangle(0, 0, image.Width, image.Height);
                else
                {
                    symFont = Symbols.GetFontAwesome(frame.SymbolSize);
                    Size imageSize = TextDrawing.MeasureString(g, frame.Symbol, 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 += (item.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 += (item.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((item.TileSize.Width - imageRect.Width) / 2, item.TileSize.Height - imageRect.Height);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.Height -= (imageRect.Height);
                }
                else if (imageTextAlign == ContentAlignment.BottomLeft)
                {
                    imageRect.Offset(0, item.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((item.TileSize.Width - imageRect.Width - frame.ImageIndent.X), item.TileSize.Height - imageRect.Height);
                    imageRect.Offset(0, frame.ImageIndent.Y);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else if (imageTextAlign == ContentAlignment.MiddleCenter)
                {
                    imageRect.Offset((item.TileSize.Width - imageRect.Width) / 2, (item.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, (item.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((item.TileSize.Width - imageRect.Width - frame.ImageIndent.X), (item.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.Symbol))
                    g.DrawImage(image, imageRect);
                else
                    TextDrawing.DrawStringLegacy(g, frame.Symbol, 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;
                    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;
                    frame.TextMarkupBody.Bounds = textRect;
                    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.IsMouseOver)
                    titleTextRect.Offset(InflatePixels, InflatePixels);
                TextDrawing.DrawString(g, frame.TitleText, font, titleTextColor, titleTextRect, eTextFormat.Default | eTextFormat.SingleLine);
            }

            if (item.Checked)
            {
                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(11, 11);
                    checkCircleBounds.X = markBounds.Right - checkCircleBounds.Size.Width - 3;
                    checkCircleBounds.Y = markBounds.Y + 2;
                    using (Pen pen = new Pen(colorTable.CheckForeground, 2))
                    {
                        g.DrawEllipse(pen, checkCircleBounds);
                        g.DrawLine(pen, checkCircleBounds.X + 3, checkCircleBounds.Y + 5, checkCircleBounds.X + 6, checkCircleBounds.Y + 8);
                        g.DrawLine(pen, checkCircleBounds.X + 6, checkCircleBounds.Y + 8, checkCircleBounds.X + 9, checkCircleBounds.Y + 3);
                    }
                }
            }

            if (dispose) style.Dispose();

            if (clip != null) 
            {
                g.Clip = clip;
                clip.Dispose();
            }
        }
Ejemplo n.º 26
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            Rectangle clientRect = this.ClientRectangle;
            bool enabled = this.Enabled;

            if (!this.Enabled)
            {
                if (!_DisabledBackColor.IsEmpty)
                {
                    using(SolidBrush brush=new SolidBrush(_DisabledBackColor))
                        e.Graphics.FillRectangle(brush, clientRect);
                }
                else
                    e.Graphics.FillRectangle(SystemBrushes.Control, clientRect);
            }
            else
            {
                using (SolidBrush brush = new SolidBrush(this.BackColor))
                    e.Graphics.FillRectangle(brush, clientRect);
            }

            bool disposeStyle = false;
            ElementStyle style = GetBackgroundStyle(out disposeStyle);

            if (style.Custom)
            {
                SmoothingMode sm = g.SmoothingMode;
                if (this.AntiAlias)
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                ElementStyleDisplayInfo displayInfo = new ElementStyleDisplayInfo(style, g, clientRect);
                if (!enabled)
                {
                    ElementStyleDisplay.PaintBorder(displayInfo);
                }
                else
                    ElementStyleDisplay.Paint(displayInfo);
                if (this.AntiAlias)
                    g.SmoothingMode = sm;
            }

            Rectangle buttonBounds = PaintButtons(g);
            // Paint selected content
            Rectangle selectionRect = GetSelectionRectangle(style, clientRect);
            if (!buttonBounds.IsEmpty)
            {
                Rectangle[] split = DisplayHelp.ExcludeRectangle(selectionRect, buttonBounds);
                if (split.Length >= 1)
                    selectionRect = split[0];
                selectionRect.Width--;
            }

            if (this.WatermarkEnabled && this.WatermarkText.Length > 0 && this.IsWatermarkRendered)
            {
                Rectangle watermarkBounds = selectionRect;
                watermarkBounds.Inflate(-1, -1);
                DrawWatermark(g, watermarkBounds);
            }

            PaintSelection(g, selectionRect);

            if(disposeStyle) style.Dispose();
        }
Ejemplo n.º 27
0
        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 (!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);
            
        }