private static Rectangle CalcGlassRect(Rectangle ownerRect, RectangleGlassPosition pos, float factor) { Point location = ownerRect.Location; int width = ownerRect.Width; int height = ownerRect.Height; switch (pos) { case RectangleGlassPosition.Fill: break; case RectangleGlassPosition.Top: height = (int)(ownerRect.Height * factor); break; case RectangleGlassPosition.Bottom: height = (int)(ownerRect.Height * factor); location.Offset(0, ownerRect.Height - height); break; case RectangleGlassPosition.Left: width = (int)(ownerRect.Width * factor); break; case RectangleGlassPosition.Right: width = (int)(ownerRect.Width * factor); location.Offset(ownerRect.Width - width, 0); break; } return(new Rectangle(location, new Size(width, height))); }
private static RoundStyle CalcRoundStyle(RectangleGlassPosition pos, int radius, RoundStyle ownerStyle) { if (radius < 2 || ownerStyle == RoundStyle.None) { return(RoundStyle.None); } switch (pos) { case RectangleGlassPosition.Fill: return(ownerStyle); case RectangleGlassPosition.Top: if (ownerStyle == RoundStyle.All || ownerStyle == RoundStyle.Top) { return(RoundStyle.Top); } else { return(RoundStyle.None); } case RectangleGlassPosition.Bottom: if (ownerStyle == RoundStyle.All || ownerStyle == RoundStyle.Bottom) { return(RoundStyle.Bottom); } else { return(RoundStyle.None); } case RectangleGlassPosition.Left: if (ownerStyle == RoundStyle.All || ownerStyle == RoundStyle.Left) { return(RoundStyle.Left); } else { return(RoundStyle.None); } case RectangleGlassPosition.Right: if (ownerStyle == RoundStyle.All || ownerStyle == RoundStyle.Right) { return(RoundStyle.Right); } else { return(RoundStyle.None); } default: return(RoundStyle.None); } }
public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect, int ownerRadius, RoundStyle ownerRoundTye, RectangleGlassPosition position, float angle, float glassLengthFactor, Color glassColor, int alpha1, int alpha2) { if (!(glassLengthFactor > 0 && glassLengthFactor < 1)) { throw new ArgumentException("glassLengthFactor must be between 0 and 1, but not include 0 and 1. ", "glassLengthFactor"); } Rectangle rect = CalcGlassRect(ownerRect, position, glassLengthFactor); RoundStyle round = CalcRoundStyle(position, ownerRadius, ownerRoundTye); //if (angle == 0 || angle == 90 || angle == 180 || angle == 270) // angle++; bool simpleRect = (round == RoundStyle.None); SmoothingMode newMode; if (simpleRect) { newMode = SmoothingMode.HighSpeed; } else { newMode = SmoothingMode.AntiAlias; rect.Width--; rect.Height--; } if (rect.Width < 1 || rect.Height < 1) { return; } using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode)) { using (LinearGradientBrush lb = new LinearGradientBrush(rect, Color.FromArgb(alpha1, glassColor), Color.FromArgb(alpha2, glassColor), angle)) { if (simpleRect) { g.FillRectangle(lb, rect); } else { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, ownerRadius, round, false)) { g.FillPath(lb, path); } } } } }
public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect, int ownerRadius, RoundStyle ownerRoundTye, RectangleGlassPosition position, float angle, float glassLengthFactor) { RenderRectangleGlass(g, ownerRect, ownerRadius, ownerRoundTye, position, angle, glassLengthFactor, Color.White, 220, 60); }
public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect, int ownerRadius, RoundStyle ownerRoundTye, RectangleGlassPosition position, float angle) { RenderRectangleGlass(g, ownerRect, ownerRadius, ownerRoundTye, position, angle, 0.5f); }