Exemple #1
0
 internal 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)
 {
     checked
     {
         if (drawBorder)
         {
             rect.Width--;
             rect.Height--;
         }
     }
     using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
     {
         Color[] colors = new Color[]
         {
             RenderHelper.GetColor(baseColor, 0, 35, 24, 9),
             RenderHelper.GetColor(baseColor, 0, 13, 8, 3),
             baseColor,
             RenderHelper.GetColor(baseColor, 0, 35, 24, 9)
         };
         linearGradientBrush.InterpolationColors = new ColorBlend
         {
             Positions = new float[]
             {
                 0f,
                 basePosition,
                 basePosition + 0.05f,
                 1f
             },
             Colors = colors
         };
         if (style != RoundStyle.None)
         {
             using (GraphicsPath graphicsPath = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
             {
                 g.FillPath(linearGradientBrush, graphicsPath);
             }
             checked
             {
                 if (baseColor.A > 80)
                 {
                     Rectangle rect2 = rect;
                     if (mode == LinearGradientMode.Vertical)
                     {
                         rect2.Height = (int)unchecked ((float)rect2.Height * basePosition);
                     }
                     else
                     {
                         rect2.Width = (int)unchecked ((float)rect.Width * basePosition);
                     }
                     using (GraphicsPath graphicsPath2 = GraphicsPathHelper.CreatePath(rect2, roundWidth, RoundStyle.Top, false))
                     {
                         using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(128, 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;
                 }
                 ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
             }
             if (drawBorder)
             {
                 using (GraphicsPath graphicsPath = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                 {
                     using (Pen pen = new Pen(borderColor))
                     {
                         g.DrawPath(pen, graphicsPath);
                     }
                 }
                 rect.Inflate(-1, -1);
                 using (GraphicsPath graphicsPath = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                 {
                     using (Pen pen = new Pen(innerBorderColor))
                     {
                         g.DrawPath(pen, graphicsPath);
                     }
                 }
             }
         }
         else
         {
             g.FillRectangle(linearGradientBrush, rect);
             checked
             {
                 if (baseColor.A > 80)
                 {
                     Rectangle rect2 = rect;
                     if (mode == LinearGradientMode.Vertical)
                     {
                         rect2.Height = (int)unchecked ((float)rect2.Height * basePosition);
                     }
                     else
                     {
                         rect2.Width = (int)unchecked ((float)rect.Width * basePosition);
                     }
                     using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(128, 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;
                 }
                 ControlPaintEx.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);
                 }
             }
         }
     }
 }
Exemple #2
0
 public static void DrawGlass(Graphics g, RectangleF glassRect, int alphaCenter, int alphaSurround)
 {
     ControlPaintEx.DrawGlass(g, glassRect, Color.White, alphaCenter, alphaSurround);
 }
Exemple #3
0
 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 (var brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
     {
         Color[] colorArray =
         {
             GetColor(baseColor, 0, 0x23, 0x18, 9), GetColor(baseColor, 0, 13, 8, 3), baseColor,
             GetColor(baseColor, 0, 0x23, 0x18, 9)
         };
         var blend    = new ColorBlend();
         var numArray = new float[4];
         numArray[1]               = basePosition;
         numArray[2]               = basePosition + 0.05f;
         numArray[3]               = 1f;
         blend.Positions           = numArray;
         blend.Colors              = colorArray;
         brush.InterpolationColors = blend;
         if (style != RoundStyle.None)
         {
             //using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
             using (var path = DrawHelper.CreateRoundPath(rect, roundWidth, style, false))
             {
                 g.FillPath(brush, path);
             }
             if (drawGlass)
             {
                 if (baseColor.A > 80)
                 {
                     var rectangle = rect;
                     if (mode == LinearGradientMode.Vertical)
                     {
                         rectangle.Height = (int)(rectangle.Height * basePosition);
                     }
                     else
                     {
                         rectangle.Width = (int)(rect.Width * basePosition);
                     }
                     using (var path2 = DrawHelper.CreateRoundPath(rectangle, roundWidth, RoundStyle.Top, false))
                     //
                     {
                         using (var brush2 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff)))
                         {
                             g.FillPath(brush2, path2);
                         }
                     }
                 }
                 RectangleF glassRect = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     glassRect.Y      = rect.Y + (rect.Height * basePosition);
                     glassRect.Height = (rect.Height - (rect.Height * basePosition)) * 2f;
                 }
                 else
                 {
                     glassRect.X     = rect.X + (rect.Width * basePosition);
                     glassRect.Width = (rect.Width - (rect.Width * basePosition)) * 2f;
                 }
                 ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
             }
             if (!drawBorder)
             {
                 return;
             }
             using (var path3 = DrawHelper.CreateRoundPath(rect, roundWidth, style, false)) //
             {
                 using (var pen = new Pen(borderColor))
                 {
                     g.DrawPath(pen, path3);
                 }
             }
             rect.Inflate(-1, -1);
             using (var path4 = DrawHelper.CreateRoundPath(rect, roundWidth, style, false)) //
             {
                 using (var pen2 = new Pen(innerBorderColor))
                 {
                     g.DrawPath(pen2, path4);
                 }
                 return;
             }
         }
         g.FillRectangle(brush, rect);
         if (drawGlass)
         {
             if (baseColor.A > 80)
             {
                 var rectangle2 = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     rectangle2.Height = (int)(rectangle2.Height * basePosition);
                 }
                 else
                 {
                     rectangle2.Width = (int)(rect.Width * basePosition);
                 }
                 using (var brush3 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff)))
                 {
                     g.FillRectangle(brush3, rectangle2);
                 }
             }
             RectangleF ef2 = rect;
             if (mode == LinearGradientMode.Vertical)
             {
                 ef2.Y      = rect.Y + (rect.Height * basePosition);
                 ef2.Height = (rect.Height - (rect.Height * basePosition)) * 2f;
             }
             else
             {
                 ef2.X     = rect.X + (rect.Width * basePosition);
                 ef2.Width = (rect.Width - (rect.Width * basePosition)) * 2f;
             }
             ControlPaintEx.DrawGlass(g, ef2, 200, 0);
         }
         if (drawBorder)
         {
             using (var pen3 = new Pen(borderColor))
             {
                 g.DrawRectangle(pen3, rect);
             }
             rect.Inflate(-1, -1);
             using (var pen4 = new Pen(innerBorderColor))
             {
                 g.DrawRectangle(pen4, rect);
             }
         }
     }
 }