Example #1
0
        /// <summary>
        /// 创建画刷,渲染背景和边框使用
        /// </summary>
        /// <param name="rect">画刷区域</param>
        /// <param name="baseColor">基色</param>
        /// <param name="pos1">基色位置1</param>
        /// <param name="pos2">基色位置2</param>
        /// <param name="reverse">是否反转</param>
        /// <param name="mode">渐变模式</param>
        /// <param name="style">样式</param>
        /// <returns>画刷</returns>
        public static Brush CreateBrush(Rectangle rect, Color baseColor, float pos1, float pos2, bool reverse, LinearGradientMode mode, BlendStyle style)
        {
            Brush brush = null;

            RectangleEx.MakeNotEmpty(ref rect);
            switch (style)
            {
            case BlendStyle.Solid:
            {
                SolidBrush brushTmp = new SolidBrush(baseColor);
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.Gradient:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosGradient(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeIn:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeIn(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeOut(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeInFadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeInFadeOut(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            default:
                break;
            }
            return(brush);
        }
Example #2
0
        /// <summary>
        /// 创建画刷,渲染线段使用
        /// </summary>
        /// <param name="pt1">起点</param>
        /// <param name="pt2">终点</param>
        /// <param name="baseColor">基色</param>
        /// <param name="style">样式</param>
        /// <returns>画刷</returns>
        public static Brush CreateBrush(Point pt1, Point pt2, Color baseColor, BlendStyle style)
        {
            Brush brush = null;

            switch (style)
            {
            case BlendStyle.Solid:
            {
                SolidBrush brushTmp = new SolidBrush(baseColor);
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.Gradient:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(GetLineRect(pt1, pt2), Color.Empty, Color.Empty, GetLineDegrees(pt1, pt2));
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosGradient(baseColor, float.NaN, float.NaN, false, true, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeIn:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(GetLineRect(pt1, pt2), Color.Empty, Color.Empty, GetLineDegrees(pt1, pt2));
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeIn(baseColor, float.NaN, float.NaN, false, true, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(GetLineRect(pt1, pt2), Color.Empty, Color.Empty, GetLineDegrees(pt1, pt2));
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeOut(baseColor, float.NaN, float.NaN, false, true, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeInFadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(GetLineRect(pt1, pt2), Color.Empty, Color.Empty, GetLineDegrees(pt1, pt2));
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeInFadeOut(baseColor, float.NaN, float.NaN, false, true, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            default:
                break;
            }
            return(brush);
        }
        /// <summary>
        /// 绘制Metrol选中边框
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderMetroCheck(Rectangle rect)
        {
            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
            {
                return;
            }

            //左侧
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Left) != 0)
            {
                rect.X     += 2;
                rect.Width -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Left) != 0)
            {
                rect.X     += 1;
                rect.Width -= 1;
            }

            //上边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Top) != 0)
            {
                rect.Y      += 2;
                rect.Height -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Top) != 0)
            {
                rect.Y      += 1;
                rect.Height -= 1;
            }

            //右边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Right) != 0)
            {
                rect.Width -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Right) != 0)
            {
                rect.Width -= 1;
            }

            //下边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
            {
                rect.Height -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
            {
                rect.Height -= 1;
            }

            //设置剪切区
            this.m_Graphics.SetClip(rect);

            //绘制宽边框
            using (GraphicsPath pathBorder = RenderEngine.CreateGraphicsPath(rect),
                   pathBorderIn = RenderEngine.CreateGraphicsPath(Rectangle.Inflate(rect, -3, -3)),
                   pathTriangle = new GraphicsPath())
            {
                //边框区域
                pathBorder.AddPath(pathBorderIn, true);

                //右上角三角区域
                Point[] points = new Point[] {
                    new Point(rect.X + rect.Width - 40, rect.Y),
                    new Point(rect.X + rect.Width, rect.Y),
                    new Point(rect.X + rect.Width, rect.Y + 40)
                };
                pathTriangle.AddPolygon(points);

                //绘制
                using (Brush brush = new SolidBrush(this.CurrentBackColor))
                {
                    this.m_Graphics.FillPath(brush, pathBorder);
                    this.m_Graphics.FillPath(brush, pathTriangle);
                }
            }

            //绘制对号
            RenderEngine.DrawCheck(this.m_Graphics, new Rectangle(rect.Right - 22, rect.Y + 2, 20, 20), this.CurrentForeColor);
        }
        /// <summary>
        /// 渲染Metrol按下边框
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderMetroPress(Rectangle rect)
        {
            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
            {
                return;
            }

            //左侧
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Left) != 0)
            {
                rect.X     += 2;
                rect.Width -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Left) != 0)
            {
                rect.X     += 1;
                rect.Width -= 1;
            }

            //上边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Top) != 0)
            {
                rect.Y      += 2;
                rect.Height -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Top) != 0)
            {
                rect.Y      += 1;
                rect.Height -= 1;
            }

            //右边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Right) != 0)
            {
                rect.Width -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Right) != 0)
            {
                rect.Width -= 1;
            }

            //下边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
            {
                rect.Height -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
            {
                rect.Height -= 1;
            }

            //设置剪切区
            this.m_Graphics.SetClip(rect);

            //绘制宽边框
            using (GraphicsPath pathBorder = RenderEngine.CreateGraphicsPath(rect),
                   pathBorderIn = RenderEngine.CreateGraphicsPath(Rectangle.Inflate(rect, -3, -3)))
            {
                //边框区域
                pathBorder.AddPath(pathBorderIn, true);

                //绘制
                using (Brush brush = new SolidBrush(this.CurrentBorderColor))
                {
                    this.m_Graphics.FillPath(brush, pathBorder);
                }
            }
        }
        /// <summary>
        /// 渲染背景色特效
        /// </summary>
        public void RenderBackColorAero()
        {
            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackColorRect))
            {
                return;
            }

            //绘制模糊效果
            if ((this.m_BackColorAeroStyle & AeroStyle.Blur) != 0)
            {
                Rectangle blurRect   = this.CurrentBackColorPathRect;
                int       blurWidth  = 0;
                int       blurHeight = 0;
                switch (this.m_BackColorAlign)
                {
                case TabAlignment.Top:
                    blurHeight      = (int)(this.CurrentBackColorPathRect.Height * this.m_BackColorAeroPos);
                    blurRect.Height = blurHeight;
                    break;

                case TabAlignment.Bottom:
                    blurHeight      = (int)(this.CurrentBackColorPathRect.Height * this.m_BackColorAeroPos);
                    blurRect.Y      = blurRect.Bottom - blurHeight;
                    blurRect.Height = blurHeight;
                    break;

                case TabAlignment.Left:
                    blurWidth      = (int)(this.CurrentBackColorPathRect.Width * this.m_BackColorAeroPos);
                    blurRect.Width = blurWidth;
                    break;

                case TabAlignment.Right:
                    blurWidth      = (int)(this.CurrentBackColorPathRect.Width * this.m_BackColorAeroPos);
                    blurRect.X     = blurRect.Right - blurWidth;
                    blurRect.Width = blurWidth;
                    break;

                default:    //同Top
                    blurHeight      = (int)(this.CurrentBackColorPathRect.Height * this.m_BackColorAeroPos);
                    blurRect.Height = blurHeight;
                    break;
                }

                //绘制
                RenderEngine.DrawAeroBlur(this.m_Graphics, blurRect, this.m_BackColorAeroBlurColor);
            }

            //绘制玻璃效果
            if ((this.m_BackColorAeroStyle & AeroStyle.Glass) != 0)
            {
                Rectangle glassRect  = this.CurrentBackColorPathRect;
                int       blurWidth  = 0;
                int       blurHeight = 0;
                switch (this.m_BackColorAlign)
                {
                case TabAlignment.Top:
                    blurHeight       = (int)(glassRect.Height * this.BackColorAeroPos);
                    glassRect.Y     += blurHeight;                          //底部
                    glassRect.Height = (glassRect.Height - blurHeight) * 2; //圆的一半
                    break;

                case TabAlignment.Bottom:
                    blurHeight       = (int)(glassRect.Height * this.BackColorAeroPos);
                    glassRect.Y     -= (glassRect.Height - blurHeight);                         //顶部
                    glassRect.Height = (this.CurrentBackColorPathRect.Height - blurHeight) * 2; //圆的一半
                    break;


                case TabAlignment.Left:
                    blurWidth       = (int)(glassRect.Width * this.BackColorAeroPos);
                    glassRect.X    += blurWidth;                         //右侧
                    glassRect.Width = (glassRect.Width - blurWidth) * 2; //圆的一半
                    break;


                case TabAlignment.Right:
                    blurWidth       = (int)(glassRect.Width * this.BackColorAeroPos);
                    glassRect.X    -= (glassRect.Width - blurWidth);     //左侧
                    glassRect.Width = (glassRect.Width - blurWidth) * 2; //圆的一般
                    break;

                default:                                                    //同Top
                    blurHeight       = (int)(glassRect.Height * this.BackColorAeroPos);
                    glassRect.Y     += blurHeight;                          //底部
                    glassRect.Height = (glassRect.Height - blurHeight) * 2; //圆的一半
                    break;
                }

                //绘制
                RenderEngine.DrawAeroGlass(this.m_Graphics, glassRect, this.BackColorAeroGlassCenterColor, this.BackColorAeroGlassSurroundColor);
            }
        }
        //渲染文本核心方法
        private void RenderTextCore(LayoutData layout)
        {
            layout.DoLayout();                                                                                                                                                          //执行布局
            this.CurrentTextPreferredRect = layout.OutTextBounds;                                                                                                                       //保存文本区域矩形
            bool      needRotate = !(Single.IsNaN(this.m_TextRotateAngle) || this.m_TextRotateAngle % 360f == 0f);                                                                      //是否需要旋转
            Rectangle textRect   = needRotate ? RenderEngine.RotateRect(this.m_Graphics, this.CurrentTextPreferredRect, this.m_TextRotateAngle, false) : this.CurrentTextPreferredRect; //新绘图区域(如果旋转则为旋转后的区域)

            //绘制阴影或描边
            if (this.m_TextShadowShapeStyle != 0)
            {
                using (new SmoothingModeGraphics(this.m_Graphics, SmoothingMode.AntiAlias))
                {
                    using (GraphicsPath textPath = new GraphicsPath())
                    {
                        //添加文本
                        textPath.AddString(this.m_Text, this.m_Font.FontFamily, (int)this.m_Font.Style, this.m_Graphics.DpiY * this.m_Font.SizeInPoints / 72f, textRect, layout.CurrentStringFormat);

                        //绘制阴影和阴影描边
                        if (((this.m_TextShadowShapeStyle & ShadowShapeStyle.Shadow) != 0) || ((this.m_TextShadowShapeStyle & ShadowShapeStyle.ShapeOfShadow) != 0 && this.m_TextShapeOfShadowWidth > 0f))
                        {
                            using (GraphicsPath shadowPath = textPath.Clone() as GraphicsPath)
                            {
                                using (Matrix shadowMatrix = new Matrix(1, 0, 0, 1, this.m_TextShadowMatrixOffset.X, this.m_TextShadowMatrixOffset.Y))
                                {
                                    shadowPath.Transform(shadowMatrix);
                                }

                                //绘制阴影
                                if ((this.m_TextShadowShapeStyle & ShadowShapeStyle.Shadow) != 0)
                                {
                                    using (Brush shadowBrush = new SolidBrush(this.m_TextShadowColor))
                                    {
                                        this.m_Graphics.FillPath(shadowBrush, shadowPath);
                                    }
                                }
                                //阴影描边
                                if ((this.m_TextShadowShapeStyle & ShadowShapeStyle.ShapeOfShadow) != 0 && this.m_TextShapeOfShadowWidth > 0f)
                                {
                                    using (Pen shapeOfShadowPen = new Pen(this.m_TextShapeOfShadowColor, this.m_TextShapeOfShadowWidth))
                                    {
                                        this.m_Graphics.DrawPath(shapeOfShadowPen, shadowPath);
                                    }
                                }
                            }
                        }

                        //绘制文本
                        using (Brush textBrush = new SolidBrush(this.CurrentForeColor))
                        {
                            this.m_Graphics.FillPath(textBrush, textPath);
                        }

                        //文本描边
                        if ((this.m_TextShadowShapeStyle & ShadowShapeStyle.ShapeOfText) != 0 && this.m_TextShapeOfTextWidth > 0f)
                        {
                            using (Pen shapeOfTextPen = new Pen(this.m_TextShapeOfTextColor, this.m_TextShapeOfTextWidth))
                            {
                                this.m_Graphics.DrawPath(shapeOfTextPen, textPath);
                            }
                        }
                    }
                }
            }
            else
            {
                using (new TextRenderingHintGraphics(this.m_Graphics, this.m_TextRenderingHint))
                {
                    using (Brush textBrush = new SolidBrush(this.CurrentForeColor))
                    {
                        this.m_Graphics.DrawString(this.m_Text, this.m_Font, textBrush, textRect, layout.CurrentStringFormat);
                    }
                }
            }

            //恢复旋转
            if (needRotate)
            {
                this.m_Graphics.ResetTransform();
            }
        }