Example #1
0
 internal void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor,
                                        Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, LinearGradientMode mode)
 {
     if (drawBorder)
     {
         rect.Width--;
         rect.Height--;
     }
     using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
     {
         Color[] colors = new Color[]
         {
             this.GetColor(baseColor, 0, 35, 24, 9),
             this.GetColor(baseColor, 0, 13, 8, 3),
             baseColor,
             this.GetColor(baseColor, 0, 68, 69, 54)
         };
         linearGradientBrush.InterpolationColors = new ColorBlend
         {
             Positions = new float[]
             {
                 0f,
                 basePosition,
                 basePosition + 0.05f,
                 1f
             },
             Colors = colors
         };
         if (style != RoundStyle.None)
         {
             using (GraphicsPath graphicsPath = GraphicsPathHelper.CreateFilletRectangle(rect, roundWidth, style, false))
             {
                 g.FillPath(linearGradientBrush, graphicsPath);
             }
             if (baseColor.A > 80)
             {
                 Rectangle rect2 = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     rect2.Height = (int)((float)rect2.Height * basePosition);
                 }
                 else
                 {
                     rect2.Width = (int)((float)rect.Width * basePosition);
                 }
                 using (GraphicsPath graphicsPath2 = GraphicsPathHelper.CreateFilletRectangle(rect2, roundWidth, RoundStyle.Top, false))
                 {
                     using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
                     {
                         g.FillPath(solidBrush, graphicsPath2);
                     }
                 }
             }
             if (drawGlass)
             {
                 RectangleF glassRect = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     glassRect.Y      = (float)rect.Y + (float)rect.Height * basePosition;
                     glassRect.Height = ((float)rect.Height - (float)rect.Height * basePosition) * 2f;
                 }
                 else
                 {
                     glassRect.X     = (float)rect.X + (float)rect.Width * basePosition;
                     glassRect.Width = ((float)rect.Width - (float)rect.Width * basePosition) * 2f;
                 }
                 this.DrawGlass(g, glassRect, 170, 0);
             }
             if (drawBorder)
             {
                 using (GraphicsPath graphicsPath = GraphicsPathHelper.CreateFilletRectangle(rect, roundWidth, style, false))
                 {
                     using (Pen pen = new Pen(borderColor))
                     {
                         g.DrawPath(pen, graphicsPath);
                     }
                 }
                 rect.Inflate(-1, -1);
                 using (GraphicsPath graphicsPath = GraphicsPathHelper.CreateFilletRectangle(rect, roundWidth, style, false))
                 {
                     using (Pen pen = new Pen(innerBorderColor))
                     {
                         g.DrawPath(pen, graphicsPath);
                     }
                 }
             }
         }
         else
         {
             g.FillRectangle(linearGradientBrush, rect);
             if (baseColor.A > 80)
             {
                 Rectangle rect2 = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     rect2.Height = (int)((float)rect2.Height * basePosition);
                 }
                 else
                 {
                     rect2.Width = (int)((float)rect.Width * basePosition);
                 }
                 using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
                 {
                     g.FillRectangle(solidBrush, rect2);
                 }
             }
             if (drawGlass)
             {
                 RectangleF glassRect = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     glassRect.Y      = (float)rect.Y + (float)rect.Height * basePosition;
                     glassRect.Height = ((float)rect.Height - (float)rect.Height * basePosition) * 2f;
                 }
                 else
                 {
                     glassRect.X     = (float)rect.X + (float)rect.Width * basePosition;
                     glassRect.Width = ((float)rect.Width - (float)rect.Width * basePosition) * 2f;
                 }
                 this.DrawGlass(g, glassRect, 200, 0);
             }
             if (drawBorder)
             {
                 using (Pen pen = new Pen(borderColor))
                 {
                     g.DrawRectangle(pen, rect);
                 }
                 rect.Inflate(-1, -1);
                 using (Pen pen = new Pen(innerBorderColor))
                 {
                     g.DrawRectangle(pen, rect);
                 }
             }
         }
     }
 }
Example #2
0
        /// <summary>
        /// 渲染内部背景.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rect">渲染的区域.</param>
        /// <param name="baseColor">基色</param>
        /// <param name="borderColor">边框颜色</param>
        /// <param name="innerBorderColor">内边框颜色.</param>
        /// <param name="style">指定圆角的风格.</param>
        /// <param name="roundWidth">指定圆角的半径</param>
        /// <param name="drawBorder"></param>
        /// <param name="drawGlass"></param>
        /// <param name="mode">指定线性渐变的方向.</param>
        /// <param name="basePosition"></param>
        public static void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor,
                                                    Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, LinearGradientMode mode)
        {
            if (drawBorder)
            {
                rect.Width--;
                rect.Height--;
            }

            if (rect.Width == 0 || rect.Height == 0)
            {
                return;
            }

            using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
            {
                DecoratorBrush(brush, baseColor, basePosition);
                if (style != RoundStyle.None)
                {
                    using (GraphicsPath path = GraphicsPathHelper.CreateFilletRectangle(rect, roundWidth, style, false))
                    {
                        g.FillPath(brush, path);//填充区域.
                    }

                    if (baseColor.A > 80)
                    {
                        Rectangle rectTop = GetGradientModeRectangle(rect, basePosition, mode);
                        DrawTranslucence(g, rectTop, roundWidth);
                    }

                    if (drawGlass)
                    {
                        RectangleF glassRect = GetGlassRectangle(rect, basePosition, mode);
                        ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
                    }

                    if (drawBorder)
                    {
                        DrawRoundBorder(g, rect, borderColor, innerBorderColor, style, roundWidth);
                    }
                }
                else
                {
                    g.FillRectangle(brush, rect);
                    if (baseColor.A > 80)
                    {
                        Rectangle rectTop = GetGradientModeRectangle(rect, basePosition, mode);

                        using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
                        {
                            g.FillRectangle(brushAlpha, rectTop);
                        }
                    }

                    if (drawGlass)
                    {
                        RectangleF glassRect = GetGlassRectangle(rect, basePosition, mode);
                        ControlPaintEx.DrawGlass(g, glassRect, 200, 0);
                    }

                    if (drawBorder)
                    {
                        DrawNormalBorder(g, rect, borderColor, innerBorderColor);
                    }
                }
            }
        }