public static void RenderBorder(Graphics g, Rectangle rect, Color borderColor, ButtonBorderType borderType, int radius, RoundStyle roundType) { rect.Width--; rect.Height--; bool simpleRect = (borderType == ButtonBorderType.Rectangle && (roundType == RoundStyle.None || radius < 2)); SmoothingMode newMode = simpleRect ? SmoothingMode.HighSpeed : SmoothingMode.AntiAlias; using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode)) { using (Pen p = new Pen(borderColor)) { if (simpleRect) { g.DrawRectangle(p, rect); } else if (borderType == ButtonBorderType.Ellipse) { g.DrawEllipse(p, rect); } else { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, radius, roundType, false)) { g.DrawPath(p, path); } } } } }
internal static void RenderBackgroundInternal( Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, bool drawBorder, bool drawGlass, LinearGradientMode mode) { RenderBackgroundInternal( g, rect, baseColor, borderColor, innerBorderColor, style, 8, 0.45f, drawBorder, drawGlass, mode); }
public static GraphicsPath CreatePath(Rectangle rect, int radius, RoundStyle style, bool correction) { GraphicsPath path = new GraphicsPath(); int radiusCorrection = correction ? 1 : 0; switch (style) { case RoundStyle.None: path.AddRectangle(rect); break; case RoundStyle.All: path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f); path.AddArc((rect.Right - radius) - radiusCorrection, rect.Y, radius, radius, 270f, 90f); path.AddArc((rect.Right - radius) - radiusCorrection, (rect.Bottom - radius) - radiusCorrection, radius, radius, 0f, 90f); path.AddArc(rect.X, (rect.Bottom - radius) - radiusCorrection, radius, radius, 90f, 90f); break; case RoundStyle.Left: path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f); path.AddLine(rect.Right - radiusCorrection, rect.Y, rect.Right - radiusCorrection, rect.Bottom - radiusCorrection); path.AddArc(rect.X, (rect.Bottom - radius) - radiusCorrection, radius, radius, 90f, 90f); break; case RoundStyle.Right: path.AddArc((rect.Right - radius) - radiusCorrection, rect.Y, radius, radius, 270f, 90f); path.AddArc((rect.Right - radius) - radiusCorrection, (rect.Bottom - radius) - radiusCorrection, radius, radius, 0f, 90f); path.AddLine(rect.X, rect.Bottom - radiusCorrection, rect.X, rect.Y); break; case RoundStyle.Top: path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f); path.AddArc((rect.Right - radius) - radiusCorrection, rect.Y, radius, radius, 270f, 90f); path.AddLine(rect.Right - radiusCorrection, rect.Bottom - radiusCorrection, rect.X, rect.Bottom - radiusCorrection); break; case RoundStyle.Bottom: path.AddArc((rect.Right - radius) - radiusCorrection, (rect.Bottom - radius) - radiusCorrection, radius, radius, 0f, 90f); path.AddArc(rect.X, (rect.Bottom - radius) - radiusCorrection, radius, radius, 90f, 90f); path.AddLine(rect.X, rect.Y, rect.Right - radiusCorrection, rect.Y); break; case RoundStyle.BottomLeft: path.AddArc(rect.X, (rect.Bottom - radius) - radiusCorrection, radius, radius, 90f, 90f); path.AddLine(rect.X, rect.Y, rect.Right - radiusCorrection, rect.Y); path.AddLine(rect.Right - radiusCorrection, rect.Y, rect.Right - radiusCorrection, rect.Bottom - radiusCorrection); break; case RoundStyle.BottomRight: path.AddArc((rect.Right - radius) - radiusCorrection, (rect.Bottom - radius) - radiusCorrection, radius, radius, 0f, 90f); path.AddLine(rect.X, rect.Bottom - radiusCorrection, rect.X, rect.Y); path.AddLine(rect.X, rect.Y, rect.Right - radiusCorrection, rect.Y); break; } path.CloseFigure(); return path; }
public static void CreateRegion(Control control, Rectangle bounds, int radius, RoundStyle roundStyle) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(bounds, radius, roundStyle, true)) { Region region = new Region(path); path.Widen(Pens.White); region.Union(path); if (control.Region != null) { control.Region.Dispose(); } control.Region = region; } }
/// <summary> /// /// </summary> void Awake() { //When you start from room scene, return to lobby for connect to server first. if (!PhotonNetwork.connected || PhotonNetwork.room == null) { Application.LoadLevel(0); return; } isFinish = false; if ((string)PhotonNetwork.room.customProperties[PropiertiesKeys.RoomRoundKey] == "1") { m_RoundStyle = RoundStyle.Rounds; } else { m_RoundStyle = RoundStyle.OneMacht; } GetTime(); }
public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect, int ownerRadius, RoundStyle ownerRoundTye, GlassPosition 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 (rect.Width < 1 || rect.Height < 1) return; BasicBlockPainter.RenderLinearGradientBackground( g, rect, Color.FromArgb(alpha1, glassColor), Color.FromArgb(alpha2, glassColor), angle, ownerRadius, round); }
internal static void RenderBackgroundInternal( Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, bool drawBorder, bool drawGlass, System.Drawing.Drawing2D.LinearGradientMode mode) { RenderBackgroundInternal( g, rect, baseColor, borderColor, innerBorderColor, style, 8, drawBorder, drawGlass, mode); }
public static void RenderFlatBackground(Graphics g, Rectangle rect, Color backColor, ButtonBorderType borderType, int radius, RoundStyle roundType) { SmoothingMode newMode; bool simpleRect = (borderType == ButtonBorderType.Rectangle && (roundType == RoundStyle.None || radius < 2)); if (simpleRect) { newMode = SmoothingMode.HighSpeed; } else { newMode = SmoothingMode.AntiAlias; rect.Width--; rect.Height--; } using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode)) { using (SolidBrush sb = new SolidBrush(backColor)) { if (simpleRect) { g.FillRectangle(sb, rect); } else if (borderType == ButtonBorderType.Ellipse) { g.FillEllipse(sb, rect); } else { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, radius, roundType, false)) { g.FillPath(sb, path); } } } } }
internal void RenderScrollBarArrowInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, Color arrowColor, RoundStyle roundStyle, bool drawBorder, bool drawGlass, ArrowDirection arrowDirection, LinearGradientMode mode) { RenderHelper.RenderBackgroundInternal(g, rect, baseColor, borderColor, innerBorderColor, roundStyle, 0, .45F, drawBorder, drawGlass, mode); using (var brush = new SolidBrush(arrowColor)) { RenderArrowInternal(g, rect, arrowDirection, brush); } }
public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect, int ownerRadius, RoundStyle ownerRoundTye, GlassPosition position, float angle, float glassLengthFactor) { RenderRectangleGlass(g, ownerRect, ownerRadius, ownerRoundTye, position, angle, glassLengthFactor, Color.White, 220, 60); }
/// <summary> /// 建立带有圆角样式的路径。取横向一半顶部(用于按钮玻璃效果) /// </summary> /// <param name="rect">用来建立路径的矩形。</param> /// <param name="_radius">圆角的大小。</param> /// <param name="style">圆角的样式。</param> /// <param name="correction">是否把矩形长宽减 1,以便画出边框。</param> /// <returns>建立的路径。</returns> public static GraphicsPath CreatePathHalf( Rectangle rect, int radius, RoundStyle style, bool correction) { GraphicsPath path = new GraphicsPath(); int radiusCorrection = correction ? 1 : 0; switch (style) { case RoundStyle.None: path.AddRectangle(new Rectangle(rect.X, rect.Y, rect.Width - radiusCorrection, rect.Height/2 - radiusCorrection)); break; case RoundStyle.All: //顺时针 path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddLine(rect.Right - radiusCorrection, rect.Y + rect.Height / 2 - radiusCorrection, rect.X, rect.Y + rect.Height / 2 - radiusCorrection); break; case RoundStyle.Left: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddLine( rect.Right - radiusCorrection, rect.Y, rect.Right - radiusCorrection, rect.Y + rect.Height / 2 - radiusCorrection); path.AddLine( rect.Right - radiusCorrection, rect.Y + rect.Height / 2 - radiusCorrection, rect.X, rect.Y + rect.Height / 2 - radiusCorrection); break; case RoundStyle.Right: path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddLine(rect.Right - radiusCorrection, rect.Y + rect.Height / 2 - radiusCorrection, rect.X, rect.Y + rect.Height / 2 - radiusCorrection); path.AddLine(rect.X, rect.Y + rect.Height / 2 - radiusCorrection, rect.X, rect.Y); break; case RoundStyle.Top: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddLine( rect.Right - radiusCorrection, rect.Y + rect.Height / 2 - radiusCorrection, rect.X, rect.Y + rect.Height / 2 - radiusCorrection); break; case RoundStyle.Bottom: path.AddRectangle(new Rectangle(rect.X, rect.Y, rect.Width - radiusCorrection, rect.Height / 2 - radiusCorrection)); break; } path.CloseFigure(); return path; }
public static GraphicsPath CreateRoundedRect(Rectangle rect, int radius, RoundStyle type, bool shorten) { GraphicsPath path = new GraphicsPath(); if (shorten) { rect.Width--; rect.Height--; } if (radius < 2) type = RoundStyle.None; Rectangle rectTopLeft = new Rectangle(rect.X, rect.Y, radius, radius); Rectangle rectTopRight = new Rectangle(rect.Right - radius, rect.Y, radius, radius); Rectangle rectBottomLeft = new Rectangle(rect.X, rect.Bottom - radius, radius, radius); Rectangle rectBottomRight = new Rectangle(rect.Right - radius, rect.Bottom - radius, radius, radius); Point p1 = new Point(rect.X, rect.Y); Point p2 = new Point(rect.Right, rect.Y); Point p3 = new Point(rect.Right, rect.Bottom); Point p4 = new Point(rect.X, rect.Bottom); switch (type) { case RoundStyle.None: path.AddRectangle(rect); break; case RoundStyle.All: path.AddArc(rectTopLeft, 180, 90); path.AddArc(rectTopRight, 270, 90); path.AddArc(rectBottomRight, 0, 90); path.AddArc(rectBottomLeft, 90, 90); break; case RoundStyle.Top: path.AddArc(rectTopLeft, 180, 90); path.AddArc(rectTopRight, 270, 90); path.AddLine(p3, p4); break; case RoundStyle.Bottom: path.AddArc(rectBottomRight, 0, 90); path.AddArc(rectBottomLeft, 90, 90); path.AddLine(p1, p2); break; case RoundStyle.Left: path.AddArc(rectBottomLeft, 90, 90); path.AddArc(rectTopLeft, 180, 90); path.AddLine(p2, p3); break; case RoundStyle.Right: path.AddArc(rectTopRight, 270, 90); path.AddArc(rectBottomRight, 0, 90); path.AddLine(p4, p1); break; default: break; } path.CloseFigure(); return path; }
public static GraphicsPath CreateRoundedRect(Rectangle rect, int radius, RoundStyle type, bool shorten) { GraphicsPath path = new GraphicsPath(); if (shorten) { rect.Width--; rect.Height--; } if (radius < 2) { type = RoundStyle.None; } Rectangle rectTopLeft = new Rectangle(rect.X, rect.Y, radius, radius); Rectangle rectTopRight = new Rectangle(rect.Right - radius, rect.Y, radius, radius); Rectangle rectBottomLeft = new Rectangle(rect.X, rect.Bottom - radius, radius, radius); Rectangle rectBottomRight = new Rectangle(rect.Right - radius, rect.Bottom - radius, radius, radius); Point p1 = new Point(rect.X, rect.Y); Point p2 = new Point(rect.Right, rect.Y); Point p3 = new Point(rect.Right, rect.Bottom); Point p4 = new Point(rect.X, rect.Bottom); switch (type) { case RoundStyle.None: path.AddRectangle(rect); break; case RoundStyle.All: path.AddArc(rectTopLeft, 180, 90); path.AddArc(rectTopRight, 270, 90); path.AddArc(rectBottomRight, 0, 90); path.AddArc(rectBottomLeft, 90, 90); break; case RoundStyle.Top: path.AddArc(rectTopLeft, 180, 90); path.AddArc(rectTopRight, 270, 90); path.AddLine(p3, p4); break; case RoundStyle.Bottom: path.AddArc(rectBottomRight, 0, 90); path.AddArc(rectBottomLeft, 90, 90); path.AddLine(p1, p2); break; case RoundStyle.Left: path.AddArc(rectBottomLeft, 90, 90); path.AddArc(rectTopLeft, 180, 90); path.AddLine(p2, p3); break; case RoundStyle.Right: path.AddArc(rectTopRight, 270, 90); path.AddArc(rectBottomRight, 0, 90); path.AddLine(p4, p1); break; default: break; } path.CloseFigure(); return(path); }
public static void RenderFlatBackground(Graphics g, Rectangle rect, Color backColor, ButtonBorderType borderType, int radius, RoundStyle roundType) { SmoothingMode newMode; bool simpleRect = (borderType == ButtonBorderType.Rectangle && (roundType == RoundStyle.None || radius < 2)); if (simpleRect) { newMode = SmoothingMode.HighSpeed; } else { newMode = SmoothingMode.AntiAlias; rect.Width--; rect.Height--; } using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode)) { using (SolidBrush sb = new SolidBrush(backColor)) { if (simpleRect) { g.FillRectangle(sb, rect); } else if (borderType == ButtonBorderType.Ellipse) { g.FillEllipse(sb, rect); } else { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, radius, roundType, false)) { g.FillPath(sb, path); } } } } }
public static void CreateRegion(Control control, Rectangle bounds, int radius, RoundStyle roundStyle) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(bounds, radius, roundStyle, true)) { Region region = new Region(path); path.Widen(Pens.White); region.Union(path); if (control.Region != null) { control.Region.Dispose(); } control.Region = region; } }
private void DrawBorder(Graphics g, Rectangle rect, RoundStyle roundStyle, int radius, CCSkinMain frm) { g.SmoothingMode = SmoothingMode.HighQuality; rect.Width--; rect.Height--; using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radius, roundStyle, false)) { using (Pen pen = new Pen(this.ColorTable.Border)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radius, roundStyle, false)) { using (Pen pen = new Pen(this.ColorTable.InnerBorder)) { g.DrawPath(pen, path); } } }
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) { if (drawBorder) { --rect.Width; --rect.Height; } using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode)) { Color[] colorArray = new Color[4] { RenderHelperStrip.GetColor(baseColor, 0, 35, 24, 9), RenderHelperStrip.GetColor(baseColor, 0, 13, 8, 3), baseColor, RenderHelperStrip.GetColor(baseColor, 0, 35, 24, 9) }; linearGradientBrush.InterpolationColors = new ColorBlend() { Positions = new float[4] { 0.0f, basePosition, basePosition + 0.05f, 1f }, Colors = colorArray }; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) g.FillPath((Brush)linearGradientBrush, path); if (drawGlass) { RectangleF glassRect = (RectangleF)rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = (float)rect.Y + (float)rect.Height * basePosition; glassRect.Height = (float)(((double)rect.Height - (double)rect.Height * (double)basePosition) * 2.0); } else { glassRect.X = (float)rect.X + (float)rect.Width * basePosition; glassRect.Width = (float)(((double)rect.Width - (double)rect.Width * (double)basePosition) * 2.0); } ControlPaintEx.DrawGlass(g, glassRect, 170, 0); if ((int)baseColor.A > 0) { Rectangle rect1 = rect; if (mode == LinearGradientMode.Vertical) { rect1.Height = (int)((double)rect1.Height * (double)basePosition); } else { rect1.Width = (int)((double)rect.Width * (double)basePosition); } using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect1, roundWidth, RoundStyle.Top, false)) { using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(128, (int)byte.MaxValue, (int)byte.MaxValue, (int)byte.MaxValue))) g.FillPath((Brush)solidBrush, path); } } } if (!drawBorder) { return; } using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) g.DrawPath(pen, path); } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) g.DrawPath(pen, path); } } else { g.FillRectangle((Brush)linearGradientBrush, rect); if (drawGlass) { RectangleF glassRect = (RectangleF)rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = (float)rect.Y + (float)rect.Height * basePosition; glassRect.Height = (float)(((double)rect.Height - (double)rect.Height * (double)basePosition) * 2.0); } else { glassRect.X = (float)rect.X + (float)rect.Width * basePosition; glassRect.Width = (float)(((double)rect.Width - (double)rect.Width * (double)basePosition) * 2.0); } ControlPaintEx.DrawGlass(g, glassRect, 200, 0); if ((int)baseColor.A > 80) { Rectangle rect1 = rect; if (mode == LinearGradientMode.Vertical) { rect1.Height = (int)((double)rect1.Height * (double)basePosition); } else { rect1.Width = (int)((double)rect.Width * (double)basePosition); } using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(128, (int)byte.MaxValue, (int)byte.MaxValue, (int)byte.MaxValue))) g.FillRectangle((Brush)solidBrush, rect1); } } if (!drawBorder) { return; } using (Pen pen = new Pen(borderColor)) g.DrawRectangle(pen, rect); rect.Inflate(-1, -1); using (Pen pen = new Pen(innerBorderColor)) g.DrawRectangle(pen, rect); } } }
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 brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[4]; colors[0] = GetColor(baseColor, 0, 35, 24, 9); colors[1] = GetColor(baseColor, 0, 0, 0, 0); colors[2] = baseColor; colors[3] = GetColor(baseColor, 0, 0, 0, 0); ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, basePosition, basePosition, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { // rectTop.Height = (int)(rectTop.Height * basePosition); } else { // rectTop.Width = (int)(rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } } } }
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--; } if (rect.Width > 0 && rect.Height > 0) { using (LinearGradientBrush brush = 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) }; brush.InterpolationColors = new ColorBlend { Positions = new float[] { 0f, basePosition, basePosition + 0.05f, 1f }, Colors = colors }; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)((float)rectTop.Height * basePosition); } else { rectTop.Width = (int)((float)rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath(rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } 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 path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)((float)rectTop.Height * basePosition); } else { rectTop.Width = (int)((float)rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } 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); } } } } } }
internal static void DrawGradientRoundRect(Graphics g, Rectangle rect, Color begin, Color end, Color border, Color innerBorder, Blend blend, LinearGradientMode mode, int radios, RoundStyle roundStyle, bool drawBorder, bool drawInnderBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radios, roundStyle, true)) { using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, begin, end, mode)) { linearGradientBrush.Blend = blend; g.FillPath((Brush)linearGradientBrush, path); } if (drawBorder) { using (Pen pen = new Pen(border)) g.DrawPath(pen, path); } } if (!drawInnderBorder) { return; } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radios, roundStyle, true)) { using (Pen pen = new Pen(innerBorder)) g.DrawPath(pen, path); } }
public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect, int ownerRadius, RoundStyle ownerRoundTye) { RenderRectangleGlass(g, ownerRect, ownerRadius, ownerRoundTye, GlassPosition.Top, 90f); }
internal static void RenderBackgroundInternal3( 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 < 1 || rect.Height < 1) { return; } using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Transparent, Color.Transparent, mode)) { FillBrush(brush, baseColor, borderColor, basePosition, drawGlass); if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (drawGlass) { RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 170, 0); if (baseColor.A > 0) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } } if (drawBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (drawGlass) { RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 200, 0); if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } } 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); } } } } }
internal void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, bool drawBorder, bool drawGlass, LinearGradientMode mode) { RenderBackgroundInternal(g, rect, baseColor, borderColor, innerBorderColor, style, 8, 0.45f, drawBorder, drawGlass, mode); }
private static RoundStyle CalcRoundStyle(GlassPosition pos, int radius, RoundStyle ownerStyle) { if (radius < 2 || ownerStyle == RoundStyle.None) return RoundStyle.None; switch (pos) { case GlassPosition.Fill: return ownerStyle; case GlassPosition.Top: if (ownerStyle == RoundStyle.All || ownerStyle == RoundStyle.Top) return RoundStyle.Top; else return RoundStyle.None; case GlassPosition.Bottom: if (ownerStyle == RoundStyle.All || ownerStyle == RoundStyle.Bottom) return RoundStyle.Bottom; else return RoundStyle.None; case GlassPosition.Left: if (ownerStyle == RoundStyle.All || ownerStyle == RoundStyle.Left) return RoundStyle.Left; else return RoundStyle.None; case GlassPosition.Right: if (ownerStyle == RoundStyle.All || ownerStyle == RoundStyle.Right) return RoundStyle.Right; else return RoundStyle.None; default: return RoundStyle.None; } }
/// <summary> /// 画边框与背景 /// </summary> internal void RenderBackGroundInternal( Graphics g, Rectangle rect, RoundStyle style, int roundWidth ) { if (ControlStates != ControlState.Normal || AlwaysShowBorder) { rect.Width--; rect.Height--; if (style != RoundStyle.None) { using (var path = DrawHelper.CreateRoundPath(rect, roundWidth, style, false)) { if (ControlStates != ControlState.Normal) { using ( var brush = (ControlStates == ControlState.Pressed) ? new LinearGradientBrush(rect, BaseColorEnd, BaseColor, LinearGradientMode.ForwardDiagonal) : new LinearGradientBrush(rect, BaseColor, BaseColorEnd, LinearGradientMode.Vertical) ) { if (!ShowSpliteButton) { g.FillPath(brush, path); } else { if (CurrentMousePosition == ButtonMousePosition.Button) { using ( var buttonpath = DrawHelper.CreateRoundPath(ButtonRect, roundWidth, RoundStyle.Left, true)) { g.FillPath(brush, buttonpath); } } else { using ( var splitepath = DrawHelper.CreateRoundPath(SpliteButtonRect, roundWidth, RoundStyle.Right, true)) { g.FillPath(brush, splitepath); } } } } } using (var pen = new Pen(_borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (var path = DrawHelper.CreateRoundPath(rect, roundWidth, style, false)) { using (var pen = new Pen(InnerBorderColor)) { g.DrawPath(pen, path); } } } else { if (ControlStates != ControlState.Normal) { using ( var brush = (ControlStates == ControlState.Pressed) ? new LinearGradientBrush(rect, BaseColorEnd, BaseColor, LinearGradientMode.ForwardDiagonal) : new LinearGradientBrush(rect, BaseColor, BaseColorEnd, LinearGradientMode.Vertical)) { if (!ShowSpliteButton) { g.FillRectangle(brush, rect); } else { if (CurrentMousePosition == ButtonMousePosition.Button) { g.FillRectangle(brush, ButtonRect); } else { g.FillRectangle(brush, SpliteButtonRect); } } } } using (var pen = new Pen(_borderColor)) { g.DrawRectangle(pen, rect); } rect.Inflate(-1, -1); using (var pen = new Pen(InnerBorderColor)) { g.DrawRectangle(pen, rect); } } } }
internal void RenderScrollBarArrowInternal( Graphics g, Rectangle rect, //Color baseColor, //Color borderColor, //Color innerBorderColor, Color arrowColor, RoundStyle roundStyle, bool drawBorder, bool drawGlass, ArrowDirection arrowDirection, LinearGradientMode mode) { //RenderHelper.RenderBackgroundInternal( // g, // rect, // baseColor, // borderColor, // innerBorderColor, // roundStyle, // 0, // .45F, // drawBorder, // drawGlass, // mode); using (SolidBrush brush = new SolidBrush(arrowColor)) { RenderArrowInternal( g, rect, arrowDirection, brush); } }
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); }
public static void CreateRegion(IntPtr hWnd, int radius, RoundStyle roundStyle, bool redraw) { Win32.Struct.RECT lpRect = new Win32.Struct.RECT(); Win32.NativeMethods.GetWindowRect(hWnd, ref lpRect); Rectangle rect = new Rectangle(System.Drawing.Point.Empty, lpRect.Size); if (roundStyle != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radius, roundStyle, true)) { using (Region region = new Region(path)) { path.Widen(Pens.White); region.Union(path); IntPtr windowDC = Win32.NativeMethods.GetWindowDC(hWnd); try { using (Graphics graphics = Graphics.FromHdc(windowDC)) { Win32.NativeMethods.SetWindowRgn(hWnd, region.GetHrgn(graphics), redraw); } } finally { Win32.NativeMethods.ReleaseDC(hWnd, windowDC); } } return; } } IntPtr hRgn = Win32.NativeMethods.CreateRectRgn(0, 0, rect.Width, rect.Height); Win32.NativeMethods.SetWindowRgn(hWnd, hRgn, redraw); }
/// <summary> /// 样式绘制圆角 /// </summary> /// <param name="hWnd">控件句柄</param> /// <param name="radius">圆角</param> /// <param name="roundStyle">圆角样式</param> /// <param name="redraw">是否重画</param> public static void CreateRegion( IntPtr hWnd, int radius, RoundStyle roundStyle, bool redraw) { RECT bounds = new RECT(); NativeMethods.GetWindowRect(hWnd, ref bounds); Rectangle rect = new Rectangle( Point.Empty, bounds.Size); if (roundStyle != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radius, roundStyle, true)) { using (Region region = new Region(path)) { path.Widen(Pens.White); region.Union(path); IntPtr hDc = NativeMethods.GetWindowDC(hWnd); try { using (Graphics g = Graphics.FromHdc(hDc)) { NativeMethods.SetWindowRgn(hWnd, region.GetHrgn(g), redraw); } } finally { NativeMethods.ReleaseDC(hWnd, hDc); } } } } else { IntPtr hRgn = NativeMethods.CreateRectRgn(0, 0, rect.Width, rect.Height); NativeMethods.SetWindowRgn(hWnd, hRgn, redraw); } }
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--; } if ((rect.Width > 0) && (rect.Height > 0)) { using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode)) { Rectangle rectangle; SolidBrush brush2; RectangleF ef; Pen pen; Color[] colorArray = new Color[] { this.GetColor(baseColor, 0, 0x23, 0x18, 9), this.GetColor(baseColor, 0, 13, 8, 3), baseColor, this.GetColor(baseColor, 0, 0x44, 0x45, 0x36) }; ColorBlend blend = new ColorBlend(); float[] 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) { GraphicsPath path; using (path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (baseColor.A > 80) { rectangle = rect; if (mode == LinearGradientMode.Vertical) { rectangle.Height = (int) (rectangle.Height * basePosition); } else { rectangle.Width = (int) (rect.Width * basePosition); } using (GraphicsPath path2 = GraphicsPathHelper.CreatePath(rectangle, roundWidth, RoundStyle.Top, false)) { using (brush2 = new SolidBrush(Color.FromArgb(80, 0xff, 0xff, 0xff))) { g.FillPath(brush2, path2); } } } if (drawGlass) { ef = rect; if (mode == LinearGradientMode.Vertical) { ef.Y = rect.Y + (rect.Height * basePosition); ef.Height = (rect.Height - (rect.Height * basePosition)) * 2f; } else { ef.X = rect.X + (rect.Width * basePosition); ef.Width = (rect.Width - (rect.Width * basePosition)) * 2f; } this.DrawGlass(g, ef, 170, 0); } if (drawBorder) { using (path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (baseColor.A > 80) { rectangle = rect; if (mode == LinearGradientMode.Vertical) { rectangle.Height = (int) (rectangle.Height * basePosition); } else { rectangle.Width = (int) (rect.Width * basePosition); } using (brush2 = new SolidBrush(Color.FromArgb(80, 0xff, 0xff, 0xff))) { g.FillRectangle(brush2, rectangle); } } if (drawGlass) { ef = rect; if (mode == LinearGradientMode.Vertical) { ef.Y = rect.Y + (rect.Height * basePosition); ef.Height = (rect.Height - (rect.Height * basePosition)) * 2f; } else { ef.X = rect.X + (rect.Width * basePosition); ef.Width = (rect.Width - (rect.Width * basePosition)) * 2f; } this.DrawGlass(g, ef, 200, 0); } if (drawBorder) { using (pen = new Pen(borderColor)) { g.DrawRectangle(pen, rect); } rect.Inflate(-1, -1); using (pen = new Pen(innerBorderColor)) { g.DrawRectangle(pen, rect); } } } } } }
/// <summary> /// /// </summary> public void SetFinalText(RoundStyle style, string winner) { FinalUI.SetActive(true); FinalUIText.text = (style == RoundStyle.OneMacht) ? bl_GameTexts.FinalOneMatch : bl_GameTexts.FinalRounds; FinalWinnerText.text = string.Format("{0} {1}", winner, bl_GameTexts.FinalWinner); }
public static void CreateRegion(Control control, Rectangle bounds, int radius, RoundStyle roundStyle) { using (GraphicsPath path = CreatePath(bounds, radius, roundStyle, true)) { Region region = new Region(path); path.Widen(Pens.White); region.Union(path); control.Region = region; } }
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) { if (drawBorder) { rect.Width--; rect.Height--; } if ((rect.Width != 0) && (rect.Height != 0)) { using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode)) { Color[] colorArray = new Color[] { GetColor(baseColor, 0, 0x23, 0x18, 9), GetColor(baseColor, 0, 13, 8, 3), baseColor, GetColor(baseColor, 0, 0x23, 0x18, 9) }; ColorBlend blend = new ColorBlend(); float[] 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)) { g.FillPath(brush, path); } if (drawGlass) { if (baseColor.A > 80) { Rectangle rectangle = rect; if (mode == LinearGradientMode.Vertical) { rectangle.Height = (int)(rectangle.Height * basePosition); } else { rectangle.Width = (int)(rect.Width * basePosition); } using (GraphicsPath path2 = GraphicsPathHelper.CreatePath(rectangle, roundWidth, RoundStyle.Top, false)) { using (SolidBrush 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 (GraphicsPath path3 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path3); } } rect.Inflate(-1, -1); using (GraphicsPath path4 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen2 = new Pen(innerBorderColor)) { g.DrawPath(pen2, path4); } return; } } g.FillRectangle(brush, rect); if (drawGlass) { if (baseColor.A > 80) { Rectangle rectangle2 = rect; if (mode == LinearGradientMode.Vertical) { rectangle2.Height = (int)(rectangle2.Height * basePosition); } else { rectangle2.Width = (int)(rect.Width * basePosition); } using (SolidBrush 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 (Pen pen3 = new Pen(borderColor)) { g.DrawRectangle(pen3, rect); } rect.Inflate(-1, -1); using (Pen pen4 = new Pen(innerBorderColor)) { g.DrawRectangle(pen4, rect); } } } } }
public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect, int ownerRadius, RoundStyle ownerRoundTye, GlassPosition position, float angle) { RenderRectangleGlass(g, ownerRect, ownerRadius, ownerRoundTye, position, angle, 0.5f); }
//画关闭按钮 private void RenderSkinFormCloseBoxInternal( Graphics g, Rectangle rect, ControlBoxState state, bool active, bool minimizeBox, bool maximizeBox, CCSkinMain form) { Bitmap btm = null; Color baseColor = ColorTable.ControlBoxActive; if (state == ControlBoxState.Pressed) { btm = (Bitmap)form.CloseDownBack; baseColor = ColorTable.ControlCloseBoxPressed; } else if (state == ControlBoxState.Hover) { btm = (Bitmap)form.CloseMouseBack; baseColor = ColorTable.ControlCloseBoxHover; } else { btm = (Bitmap)form.CloseNormlBack; baseColor = active ? ColorTable.ControlBoxActive : ColorTable.ControlBoxDeactive; } //绘制图片样式 if (btm != null) { g.DrawImage(btm, rect); } else //绘制默认样式 { RoundStyle roundStyle = minimizeBox || maximizeBox ? RoundStyle.BottomRight : RoundStyle.Bottom; using (AntiAliasGraphics antiGraphics = new AntiAliasGraphics(g)) { RenderHelper.RenderBackgroundInternal( g, rect, baseColor, baseColor, ColorTable.ControlBoxInnerBorder, roundStyle, 6, .38F, true, false, LinearGradientMode.Vertical); using (Pen pen = new Pen(ColorTable.Border)) { g.DrawLine(pen, rect.X, rect.Y, rect.Right, rect.Y); } using (GraphicsPath path = CreateCloseFlagPath(rect)) { g.FillPath(Brushes.White, path); using (Pen pen = new Pen(baseColor)) { g.DrawPath(pen, path); } } } } }
/// <summary> /// 建立带有圆角样式和标题的路径。 /// </summary> /// <param name="rect">用来简历路径的矩形。</param> /// <param name="style">圆角样式。</param> /// <param name="radius">圆角大小。</param> /// <param name="tabSize">标题大小。</param> /// <param name="tabRound">标题是否圆角。</param> /// <param name="tabRadius">标题圆角大小。</param> /// <param name="correct">是否把矩形长宽减 1,以便画出边框。</param> /// <returns>简历的路径。</returns> public static GraphicsPath CreateGroupBoxTabGraphicsPath(Rectangle rect, RoundStyle style, float radius, Size tabSize, bool tabRound, float tabRadius, bool correct) { //校正 if (correct) { rect.Width--; rect.Height--; } style = (float.IsNaN(radius) || radius <= 0f) ? RoundStyle.None : style; tabRound = (float.IsNaN(tabRadius) || tabRadius <= 0f) ? false : tabRound; //定义 GraphicsPath path = new GraphicsPath(); Rectangle tabRect = new Rectangle(rect.Location, tabSize); float diameter = radius * 2; float tabDiameter = tabRadius * 2; Point pt; //左上 if ((style & RoundStyle.TopLeft) == 0) { pt = new Point(rect.X, rect.Y); path.AddLine(pt, pt); } else { path.AddArc(rect.X, rect.Y, diameter, diameter, 180, 90); } //Tab右上 if (tabRound) { if (tabRadius > tabRect.Height)//不到90度 { double radians = Math.Acos((tabRadius - tabRect.Height) / tabRadius); path.AddArc((float)(tabRect.Right - tabRadius * Math.Sin(radians) - tabRadius), tabRect.Y, tabDiameter, tabDiameter, 270, (float)MathEx.ToDegrees(radians)); } else//到90度 { path.AddArc(tabRect.Right - tabDiameter, tabRect.Y, tabDiameter, tabDiameter, 270, 90); //Tab右下 pt = new Point(tabRect.Right, tabRect.Bottom); path.AddLine(pt, pt); } } else { pt = new Point(tabRect.Right, tabRect.Y); path.AddLine(pt, pt); //Tab右下 pt = new Point(tabRect.Right, tabRect.Bottom); path.AddLine(pt, pt); } //右上 if ((style & RoundStyle.TopRight) == 0) { pt = new Point(rect.Right, tabRect.Bottom); path.AddLine(pt, pt); } else { path.AddArc(rect.Right - diameter, tabRect.Bottom, diameter, diameter, 270, 90); } //右下 if ((style & RoundStyle.BottomRight) == 0) { pt = new Point(rect.Right, rect.Bottom); path.AddLine(pt, pt); } else { path.AddArc(rect.Right - diameter, rect.Bottom - diameter, diameter, diameter, 0, 90); } //左下 if ((style & RoundStyle.BottomLeft) == 0) { pt = new Point(rect.X, rect.Bottom); path.AddLine(pt, pt); } else { path.AddArc(rect.X, rect.Bottom - diameter, diameter, diameter, 90, 90); } //闭合返回 path.CloseFigure(); return(path); }
public static void RenderLinearGradientBackground(Graphics g, Rectangle rect, Color color1, Color color2, float angle, int radius, RoundStyle roundType) { SmoothingMode newMode; bool simpleRect = (roundType == RoundStyle.None || radius < 2); 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, color1, color2, angle)) { if (simpleRect) { g.FillRectangle(lb, rect); } else { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, radius, roundType, false)) { g.FillPath(lb, path); } } } } }
/// <summary> /// 创建路径。 /// </summary> /// <param name="rect">用来创建路径的矩形。</param> /// <param name="cornerStyle">圆角弯曲样式。</param> /// <param name="roundStyle">圆角的样式。</param> /// <param name="radius">圆角半径。</param> /// <param name="correct">是否把矩形长宽减 1,以便画出边框。</param> /// <returns>创建的路径。</returns> public static GraphicsPath CreateGraphicsPath(Rectangle rect, CornerStyle cornerStyle, RoundStyle roundStyle, float radius, bool correct) { //-----------------校准----------------- if (correct) { rect.Width--; rect.Height--; } //-----------------定义返回值----------------- GraphicsPath path = new GraphicsPath(); //-----------------特殊情况处理----------------- if (float.IsNaN(radius) || radius <= 0f) { path.AddRectangle(rect); return(path); } //-----------------临时变量定义----------------- float diameter = radius * 2; //直径 float halfWidth = rect.Width / 2f; //宽度一半 float halfHeight = rect.Height / 2f; //高度一半 PointF ptMiddleCenter = new PointF(rect.X + halfWidth, rect.Y + halfHeight); //中心点 float lrDegrees = 0f; //半径大于半高,圆心角 float lrOffset = 0f; //半径大于半高,圆弧到边距离 if ((roundStyle & RoundStyle.All) != 0 && radius > halfHeight) { double lrRadian = Math.Acos((radius - halfHeight) / radius); //弧度 lrDegrees = (float)MathEx.ToDegrees(lrRadian); //角度 lrOffset = (float)(radius * Math.Sin(lrRadian)); } float tbDegrees = 0f; //半径大于半宽,圆心角 float tbOffset = 0f; //半径大于办宽,圆弧到边距离 if ((roundStyle & RoundStyle.All) != 0 && radius > halfWidth) { double tbRadian = Math.Acos((radius - halfWidth) / radius); //弧度 tbDegrees = (float)MathEx.ToDegrees(tbRadian); //角度 tbOffset = (float)(radius * Math.Sin(tbRadian)); } //临时变量 PointF ptBegin; PointF ptEnd; #region 左上 if ((roundStyle & RoundStyle.TopLeft) == 0)//直角 { if ((cornerStyle & CornerStyle.LeftIn) != 0) { ptBegin = new PointF(rect.X + radius, ptMiddleCenter.Y); ptEnd = new PointF(rect.X, rect.Y); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.LeftOut) != 0) { ptBegin = new PointF(rect.X, ptMiddleCenter.Y); ptEnd = new PointF(rect.X + radius, rect.Y); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.TopIn) != 0) { ptBegin = new PointF(rect.X, rect.Y); ptEnd = new PointF(ptMiddleCenter.X, rect.Y + radius); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.TopOut) != 0) { ptBegin = new PointF(rect.X, rect.Y + radius); ptEnd = new PointF(ptMiddleCenter.X, rect.Y); path.AddLine(ptBegin, ptEnd); } else { ptBegin = ptEnd = new PointF(rect.X, rect.Y); path.AddLine(ptBegin, ptEnd); } } else//圆角 { if ((cornerStyle & CornerStyle.LeftIn) != 0) { if (radius > halfHeight) { path.AddArc(rect.X - radius, rect.Y, diameter, diameter, 270 + lrDegrees, -lrDegrees); } else { path.AddArc(rect.X - radius, rect.Y, diameter, diameter, 0, -90); } } else if ((cornerStyle & CornerStyle.LeftOut) != 0) { if (radius > halfHeight) { path.AddArc(rect.X - (radius - lrOffset), rect.Y, diameter, diameter, 270 - lrDegrees, lrDegrees); } else { path.AddArc(rect.X, rect.Y, diameter, diameter, 180, 90); } } else if ((cornerStyle & CornerStyle.TopIn) != 0) { if (radius > halfWidth) { path.AddArc(rect.X, rect.Y - radius, diameter, diameter, 180, -tbDegrees); } else { path.AddArc(rect.X, rect.Y - radius, diameter, diameter, 180, -90); } } else if ((cornerStyle & CornerStyle.TopOut) != 0) { if (radius > halfWidth) { path.AddArc(rect.X, rect.Y - (radius - tbOffset), diameter, diameter, 180, tbDegrees); } else { path.AddArc(rect.X, rect.Y, diameter, diameter, 180, 90); } } else { path.AddArc(rect.X, rect.Y, diameter, diameter, 180, 90); } } #endregion #region 右上 if ((roundStyle & RoundStyle.TopRight) == 0) { if ((cornerStyle & CornerStyle.RightIn) != 0) { ptBegin = new PointF(rect.Right, rect.Y); ptEnd = new PointF(rect.Right - radius, ptMiddleCenter.Y); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.RightOut) != 0) { ptBegin = new PointF(rect.Right - radius, rect.Y); ptEnd = new PointF(rect.Right, ptMiddleCenter.Y); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.TopIn) != 0) { ptBegin = new PointF(ptMiddleCenter.X, rect.Y + radius); ptEnd = new PointF(rect.Right, rect.Y); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.TopOut) != 0) { ptBegin = new PointF(ptMiddleCenter.X, rect.Y); ptEnd = new PointF(rect.Right, rect.Y + radius); path.AddLine(ptBegin, ptEnd); } else//矩形 { ptBegin = ptEnd = new PointF(rect.Right, rect.Y); path.AddLine(ptBegin, ptEnd); } } else { if ((cornerStyle & CornerStyle.RightIn) != 0) { if (radius > halfHeight) { path.AddArc(rect.Right - radius, rect.Y, diameter, diameter, 270, -lrDegrees); } else { path.AddArc(rect.Right - radius, rect.Y, diameter, diameter, 270, -90); } } else if ((cornerStyle & CornerStyle.RightOut) != 0) { if (radius > halfHeight) { path.AddArc(rect.Right - radius - lrOffset, rect.Y, diameter, diameter, 270, lrDegrees); } else { path.AddArc(rect.Right - diameter, rect.Y, diameter, diameter, 270, 90); } } else if ((cornerStyle & CornerStyle.TopIn) != 0) { if (radius > halfWidth) { path.AddArc(rect.Right - diameter, rect.Y - radius, diameter, diameter, tbDegrees, -tbDegrees); } else { path.AddArc(rect.Right - diameter, rect.Y - radius, diameter, diameter, 90, -90); } } else if ((cornerStyle & CornerStyle.TopOut) != 0) { if (radius > halfWidth) { path.AddArc(rect.Right - diameter, rect.Y - (radius - tbOffset), diameter, diameter, 360 - tbDegrees, tbDegrees); } else { path.AddArc(rect.Right - diameter, rect.Y, diameter, diameter, 270, 90); } } else { path.AddArc(rect.Right - diameter, rect.Y, diameter, diameter, 270, 90); } } #endregion #region 右下 if ((roundStyle & RoundStyle.BottomRight) == 0) { if ((cornerStyle & CornerStyle.RightIn) != 0) { ptBegin = new PointF(rect.Right - radius, ptMiddleCenter.Y); ptEnd = new PointF(rect.Right, rect.Bottom); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.RightOut) != 0) { ptBegin = new PointF(rect.Right, ptMiddleCenter.Y); ptEnd = new PointF(rect.Right - radius, rect.Bottom); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.BottomIn) != 0) { ptBegin = new PointF(rect.Right, rect.Bottom); ptEnd = new PointF(ptMiddleCenter.X, rect.Bottom - radius); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.BottomOut) != 0) { ptBegin = new PointF(rect.Right, rect.Bottom - radius); ptEnd = new PointF(ptMiddleCenter.X, rect.Bottom); path.AddLine(ptBegin, ptEnd); } else//矩形 { ptBegin = ptEnd = new PointF(rect.Right, rect.Bottom); path.AddLine(ptBegin, ptEnd); } } else { if ((cornerStyle & CornerStyle.RightIn) != 0) { if (radius > halfHeight) { path.AddArc(rect.Right - radius, rect.Bottom - diameter, diameter, diameter, 90 + lrDegrees, -lrDegrees); } else { path.AddArc(rect.Right - radius, rect.Bottom - diameter, diameter, diameter, 180, -90); } } else if ((cornerStyle & CornerStyle.RightOut) != 0) { if (radius > halfHeight) { path.AddArc(rect.Right - radius - lrOffset, rect.Bottom - diameter, diameter, diameter, 90 - lrDegrees, lrDegrees); } else { path.AddArc(rect.Right - diameter, rect.Bottom - diameter, diameter, diameter, 0, 90); } } else if ((cornerStyle & CornerStyle.BottomIn) != 0) { if (radius > halfWidth) { path.AddArc(rect.Right - diameter, rect.Bottom - radius, diameter, diameter, 0, -tbDegrees); } else { path.AddArc(rect.Right - diameter, rect.Bottom - radius, diameter, diameter, 0, -90); } } else if ((cornerStyle & CornerStyle.BottomOut) != 0) { if (radius > halfWidth) { path.AddArc(rect.Right - diameter, rect.Bottom - radius - tbOffset, diameter, diameter, 0, tbDegrees); } else { path.AddArc(rect.Right - diameter, rect.Bottom - diameter, diameter, diameter, 0, 90); } } else { path.AddArc(rect.Right - diameter, rect.Bottom - diameter, diameter, diameter, 0, 90); } } #endregion #region 左下 if ((roundStyle & RoundStyle.BottomLeft) == 0) { if ((cornerStyle & CornerStyle.LeftIn) != 0) { ptBegin = new PointF(rect.X, rect.Bottom); ptEnd = new PointF(rect.X + radius, ptMiddleCenter.Y); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.LeftOut) != 0) { ptBegin = new PointF(rect.X + radius, rect.Bottom); ptEnd = new PointF(rect.X, ptMiddleCenter.Y); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.BottomIn) != 0) { ptBegin = new PointF(ptMiddleCenter.X, rect.Bottom - radius); ptEnd = new PointF(rect.X, rect.Bottom); path.AddLine(ptBegin, ptEnd); } else if ((cornerStyle & CornerStyle.BottomOut) != 0) { ptBegin = new PointF(ptMiddleCenter.X, rect.Bottom); ptEnd = new PointF(rect.X, rect.Bottom - radius); path.AddLine(ptBegin, ptEnd); } else { ptBegin = ptEnd = new PointF(rect.X, rect.Bottom); path.AddLine(ptBegin, ptEnd); } } else { if ((cornerStyle & CornerStyle.LeftIn) != 0) { if (radius > halfHeight) { path.AddArc(rect.X - radius, rect.Bottom - diameter, diameter, diameter, 90, -lrDegrees); } else { path.AddArc(rect.X - radius, rect.Bottom - diameter, diameter, diameter, 90, -90); } } else if ((cornerStyle & CornerStyle.LeftOut) != 0) { if (radius > halfHeight) { path.AddArc(rect.X - (radius - lrOffset), rect.Bottom - diameter, diameter, diameter, 90, lrDegrees); } else { path.AddArc(rect.X, rect.Bottom - diameter, diameter, diameter, 90, 90); } } else if ((cornerStyle & CornerStyle.BottomIn) != 0) { if (radius > halfWidth) { path.AddArc(rect.X, rect.Bottom - radius, diameter, diameter, 180 + tbDegrees, -tbDegrees); } else { path.AddArc(rect.X, rect.Bottom - radius, diameter, diameter, 270, -90); } } else if ((cornerStyle & CornerStyle.BottomOut) != 0) { if (radius > halfWidth) { path.AddArc(rect.X, rect.Bottom - radius - tbOffset, diameter, diameter, 180 - tbDegrees, tbDegrees); } else { path.AddArc(rect.X, rect.Bottom - diameter, diameter, diameter, 90, 90); } } else { path.AddArc(rect.X, rect.Bottom - diameter, diameter, diameter, 90, 90); } } #endregion //闭合返回 path.CloseFigure(); return(path); }
/// <summary> /// 建立帶有圓角的樣式的路徑。 /// </summary> /// <param name="Rect">用來建立路徑的矩形。</param> /// <param name="Radius">圓角的大小。</param> /// <param name="Style">圓角的樣式。</param> /// <param name="Correction">是否把矩形長寬减 1,以便畫出邊框。</param> /// <returns>建立的路徑。</returns> protected GraphicsPath CreatePath(Rectangle Rect, int Radius, RoundStyle Style, bool Correction) { GraphicsPath path = new GraphicsPath(); int radiusCorrection = Correction ? 1 : 0; switch (Style) { case RoundStyle.None: path.AddRectangle(Rect); break; case RoundStyle.All: path.AddArc(Rect.X, Rect.Y, Radius, Radius, 180, 90); path.AddArc( Rect.Right - Radius - radiusCorrection, Rect.Y, Radius, Radius, 270, 90); path.AddArc( Rect.Right - Radius - radiusCorrection, Rect.Bottom - Radius - radiusCorrection, Radius, Radius, 0, 90); path.AddArc( Rect.X, Rect.Bottom - Radius - radiusCorrection, Radius, Radius, 90, 90); break; case RoundStyle.Left: path.AddArc(Rect.X, Rect.Y, Radius, Radius, 180, 90); path.AddLine( Rect.Right - radiusCorrection, Rect.Y, Rect.Right - radiusCorrection, Rect.Bottom - radiusCorrection); path.AddArc( Rect.X, Rect.Bottom - Radius - radiusCorrection, Radius, Radius, 90, 90); break; case RoundStyle.Right: path.AddArc( Rect.Right - Radius - radiusCorrection, Rect.Y, Radius, Radius, 270, 90); path.AddArc( Rect.Right - Radius - radiusCorrection, Rect.Bottom - Radius - radiusCorrection, Radius, Radius, 0, 90); path.AddLine(Rect.X, Rect.Bottom - radiusCorrection, Rect.X, Rect.Y); break; case RoundStyle.Top: path.AddArc(Rect.X, Rect.Y, Radius, Radius, 180, 90); path.AddArc( Rect.Right - Radius - radiusCorrection, Rect.Y, Radius, Radius, 270, 90); path.AddLine( Rect.Right - radiusCorrection, Rect.Bottom - radiusCorrection, Rect.X, Rect.Bottom - radiusCorrection); break; case RoundStyle.Bottom: path.AddArc( Rect.Right - Radius - radiusCorrection, Rect.Bottom - Radius - radiusCorrection, Radius, Radius, 0, 90); path.AddArc( Rect.X, Rect.Bottom - Radius - radiusCorrection, Radius, Radius, 90, 90); path.AddLine(Rect.X, Rect.Y, Rect.Right - radiusCorrection, Rect.Y); break; } path.CloseFigure(); return(path); }
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); } } } } }
internal static void DrawGradientRoundRect( Graphics g, Rectangle rect, Color begin, Color end, Color border, Color innerBorder, Blend blend, LinearGradientMode mode, int radios, RoundStyle roundStyle, bool drawBorder, bool drawInnderBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radios, roundStyle, true)) { using (LinearGradientBrush brush = new LinearGradientBrush( rect, begin, end, mode)) { brush.Blend = blend; g.FillPath(brush, path); } if (drawBorder) { using (Pen pen = new Pen(border)) { g.DrawPath(pen, path); } } } if (drawInnderBorder) { rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radios, roundStyle, true)) { using (Pen pen = new Pen(innerBorder)) { g.DrawPath(pen, path); } } } }
internal static void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, bool drawBorder, bool drawGlass, LinearGradientMode mode) { RenderHelper.RenderBackgroundInternal(g, rect, baseColor, borderColor, innerBorderColor, style, 8, drawBorder, drawGlass, mode); }
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--; } using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode)) { Color[] colorArray = new Color[] { ColorUtils.GetLightColor(baseColor, 0, 0x23, 0x18, 9), ColorUtils.GetLightColor(baseColor, 0, 13, 8, 3), baseColor, ColorUtils.GetLightColor(baseColor, 0, 0x23, 0x18, 9) }; ColorBlend blend = new ColorBlend(); float[] 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 = CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (drawGlass) { if (baseColor.A > 80) { Rectangle rectangle = rect; if (mode == LinearGradientMode.Vertical) { rectangle.Height = (int)(rectangle.Height * basePosition); } else { rectangle.Width = (int)(rect.Width * basePosition); } using (GraphicsPath path2 = CreatePath(rectangle, roundWidth, RoundStyle.Top, false)) { using (SolidBrush 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; } DrawGlass(g, glassRect, Color.White, 170, 0); } if (!drawBorder) { return; } using (GraphicsPath path3 = CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path3); } } rect.Inflate(-1, -1); using (GraphicsPath path4 = CreatePath(rect, roundWidth, style, false)) { using (Pen pen2 = new Pen(innerBorderColor)) { g.DrawPath(pen2, path4); } return; } } g.FillRectangle(brush, rect); if (drawGlass) { if (baseColor.A > 80) { Rectangle rectangle2 = rect; if (mode == LinearGradientMode.Vertical) { rectangle2.Height = (int)(rectangle2.Height * basePosition); } else { rectangle2.Width = (int)(rect.Width * basePosition); } using (SolidBrush 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; } DrawGlass(g, ef2, Color.White, 200, 0); } if (drawBorder) { using (Pen pen3 = new Pen(borderColor)) { g.DrawRectangle(pen3, rect); } rect.Inflate(-1, -1); using (Pen pen4 = new Pen(innerBorderColor)) { g.DrawRectangle(pen4, rect); } } } }
private void DrawCaptionBorder(Graphics g, Rectangle captionRect, int roundWidth, RoundStyle style, Color innerBorderColor) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(captionRect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.SmoothingMode = SmoothingMode.AntiAlias; g.DrawPath(pen, path); } } }
internal void RenderScrollBarArrowInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, Color arrowColor, RoundStyle roundStyle, bool drawBorder, bool drawGlass, ArrowDirection arrowDirection, LinearGradientMode mode) { RenderHelper.RenderBackgroundInternal(g, rect, baseColor, borderColor, innerBorderColor, roundStyle, 0, 0.45f, drawBorder, drawGlass, mode); using (SolidBrush brush = new SolidBrush(arrowColor)) { this.RenderArrowInternal(g, rect, arrowDirection, brush); } }
private void RenderSkinFormMaximizeBoxInternal( Graphics g, Rectangle rect, ControlBoxState state, bool active, bool minimizeBox, bool maximize, SkinForm form) { Bitmap image = null; SkinPictureForm imageForm = (SkinPictureForm)form; Color baseColor = ColorTable.ControlBoxActive; if (state == ControlBoxState.Pressed) { image = maximize ? (Bitmap)imageForm.MaxDownBack : (Bitmap)imageForm.RestoreDownBack; baseColor = ColorTable.ControlBoxPressed; } else if (state == ControlBoxState.Hover) { image = maximize ? (Bitmap)imageForm.MaxMouseBack : (Bitmap)imageForm.RestoreMouseBack; baseColor = ColorTable.ControlBoxHover; } else { image = maximize ? (Bitmap)imageForm.MaxNormlBack : (Bitmap)imageForm.RestoreNormlBack; baseColor = active ? ColorTable.ControlBoxActive : ColorTable.ControlBoxDeactive; } if (image != null) { g.DrawImage(image, rect); } else { RoundStyle roundStyle = minimizeBox ? RoundStyle.None : RoundStyle.BottomLeft; using (AntiAliasGraphics antiGraphics = new AntiAliasGraphics(g)) { RenderHelper.RenderBackgroundInternal( g, rect, baseColor, baseColor, ColorTable.ControlBoxInnerBorder, roundStyle, 6, .38F, true, false, LinearGradientMode.Vertical); using (Pen pen = new Pen(ColorTable.Border)) { g.DrawLine(pen, rect.X, rect.Y, rect.Right, rect.Y); } using (GraphicsPath path = DrawUtil.CreateMaximizeFlafPath(rect, maximize)) { g.FillPath(Brushes.White, path); using (Pen pen = new Pen(baseColor)) { g.DrawPath(pen, path); } } } } }
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) { 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)) { Color[] colors = new Color[4]; colors[0] = GetColor(baseColor, 0, 35, 24, 9); colors[1] = GetColor(baseColor, 0, 13, 8, 3); colors[2] = baseColor; colors[3] = GetColor(baseColor, 0, 35, 24, 9); ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } if (drawGlass) { RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 170, 0); } if (drawBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } if (drawGlass) { RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } 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); } } } } }
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) { if (drawBorder) { rect.Width--; rect.Height--; } using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[] { GetColor(baseColor, 0, 0x23, 0x18, 9), GetColor(baseColor, 0, 13, 8, 3), baseColor, GetColor(baseColor, 0, 0x23, 0x18, 9) }; ColorBlend blend = new ColorBlend(); float[] CS_0_0000 = new float[4]; CS_0_0000[1] = basePosition; CS_0_0000[2] = basePosition + 0.05f; CS_0_0000[3] = 1f; blend.Positions = CS_0_0000; blend.Colors = colors; brush.InterpolationColors = blend; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (drawGlass) { 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; } CCWin.SkinControl.ControlPaintEx.DrawGlass(g, glassRect, 170, 0); if (baseColor.A > 0) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int) (rectTop.Height * basePosition); } else { rectTop.Width = (int) (rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath(rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff))) { g.FillPath(brushAlpha, pathTop); } } } } if (!drawBorder) { return; } using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } return; } } g.FillRectangle(brush, rect); if (drawGlass) { 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; } CCWin.SkinControl.ControlPaintEx.DrawGlass(g, glassRect, 200, 0); if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int) (rectTop.Height * basePosition); } else { rectTop.Width = (int) (rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff))) { g.FillRectangle(brushAlpha, rectTop); } } } 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); } } } }
internal static void DrawGradientRoundRect(Graphics g, Rectangle rect, Color begin, Color end, Color border, Color innerBorder, Blend blend, LinearGradientMode mode, int radios, RoundStyle roundStyle, bool drawBorder, bool drawInnderBorder) { using (var path = DrawHelper.CreateRoundPath(rect, radios, roundStyle, true)) // { using (var brush = new LinearGradientBrush(rect, begin, end, mode)) { brush.Blend = blend; g.FillPath(brush, path); } if (drawBorder) { using (var pen = new Pen(border)) { g.DrawPath(pen, path); } } } if (drawInnderBorder) { rect.Inflate(-1, -1); using (var path2 = DrawHelper.CreateRoundPath(rect, radios, roundStyle, true)) // { using (var pen2 = new Pen(innerBorder)) { g.DrawPath(pen2, path2); } } } }
private void DrawBorder( Graphics g, Rectangle rect, RoundStyle roundStyle, int radius) { rect.Width -= 1; rect.Height -= 1; using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radius, roundStyle, false)) { using (Pen pen = new Pen(ColorTable.Border)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radius, roundStyle, false)) { using (Pen pen = new Pen(ColorTable.InnerBorder)) { g.DrawPath(pen, path); } } }
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); } }
private void DrawFormBackground(Graphics g, Rectangle rect , int radius , RoundStyle style) { using (AntiAliasGraphics antiGraphics = new AntiAliasGraphics(g)) { Image formImage = ColorTable.CaptionBackground; if (formImage == null) return; g.SmoothingMode = SmoothingMode.AntiAlias; //g.CompositingQuality = CompositingQuality.HighQuality; //g.DrawImage(formImage, rect ); using (Brush brush = new TextureBrush(formImage , WrapMode.Clamp)) { rect.X -= 1; rect.Y -= 1; rect.Width += 1; rect.Height += 1; using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radius, style, false)) { g.FillPath(brush, path); } } } }
public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect, int ownerRadius, RoundStyle ownerRoundTye) { RenderRectangleGlass(g, ownerRect, ownerRadius, ownerRoundTye, RectangleGlassPosition.Top, 90f); }
private void DrawCaptionBorder(Graphics g, Rectangle captionRect , int roundWidth , RoundStyle style , Color innerBorderColor ) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(captionRect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.SmoothingMode = SmoothingMode.AntiAlias; g.DrawPath(pen, 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 CreateRegion(Control control, Rectangle bounds, int radius, RoundStyle roundStyle) { using (var path = DrawHelper.CreateRoundPath(bounds, radius, roundStyle, true)) // { var region = new Region(path); path.Widen(Pens.White); region.Union(path); control.Region = region; } }
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--; } using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[4]; colors[0] = GetColor(baseColor, 0, 35, 24, 9); colors[1] = GetColor(baseColor, 0, 13, 8, 3); colors[2] = baseColor; colors[3] = GetColor(baseColor, 0, 35, 24, 9); ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (drawGlass) { if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 170, 0); } if (drawBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (drawGlass) { if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } 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); } } } } }
/// <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="BasePosition"></param> /// <param name="DrawBorder"></param> /// <param name="DrawGlass"></param> /// <param name="mode"></param> 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 brush = new LinearGradientBrush( Rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[4]; if (this.RStyle == RoundStyle.None) { colors[0] = colors[1] = colors[2] = colors[3] = BaseColor; } else { colors[0] = GetColor(BaseColor, 0, 35, 24, 9); colors[1] = GetColor(BaseColor, 0, 13, 8, 3); colors[2] = BaseColor; colors[3] = GetColor(BaseColor, 0, 68, 69, 54); } ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, BasePosition, BasePosition + 0.05f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; if (Style != RoundStyle.None) { using (GraphicsPath path = SkinButtonGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false)) { G.FillPath(brush, path); } if (BaseColor.A > 80) { Rectangle rectTop = Rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * BasePosition); } else { rectTop.Width = (int)(Rect.Width * BasePosition); } using (GraphicsPath pathTop = SkinButtonGraphicsPathHelper.CreatePath( rectTop, RoundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255))) { G.FillPath(brushAlpha, pathTop); } } } if (DrawGlass) { RectangleF glassRect = Rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = Rect.Y + Rect.Height * BasePosition; glassRect.Height = (Rect.Height - Rect.Height * BasePosition) * 2; } else { glassRect.X = Rect.X + Rect.Width * BasePosition; glassRect.Width = (Rect.Width - Rect.Width * BasePosition) * 2; } this.DrawGlass(G, glassRect, 170, 0); } if (DrawBorder) { using (GraphicsPath path = SkinButtonGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false)) { using (Pen pen = new Pen(BorderColor)) { G.DrawPath(pen, path); } } Rect.Inflate(-1, -1); using (GraphicsPath path = SkinButtonGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false)) { using (Pen pen = new Pen(InnerBorderColor)) { G.DrawPath(pen, path); } } } } else { G.FillRectangle(brush, Rect); if (BaseColor.A > 80) { Rectangle rectTop = Rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * BasePosition); } else { rectTop.Width = (int)(Rect.Width * BasePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255))) { G.FillRectangle(brushAlpha, rectTop); } } if (DrawGlass) { RectangleF glassRect = Rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = Rect.Y + Rect.Height * BasePosition; glassRect.Height = (Rect.Height - Rect.Height * BasePosition) * 2; } else { glassRect.X = Rect.X + Rect.Width * BasePosition; glassRect.Width = (Rect.Width - Rect.Width * BasePosition) * 2; } 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); } } } } }
/// <summary> /// 建立带有圆角样式的路径。 /// </summary> /// <param name="rect">用来建立路径的矩形。</param> /// <param name="_radius">圆角的大小。</param> /// <param name="style">圆角的样式。</param> /// <param name="correction">是否把矩形长宽减 1,以便画出边框。</param> /// <returns>建立的路径。</returns> public static GraphicsPath CreatePath( Rectangle rect, int radius, RoundStyle style, bool correction) { GraphicsPath path = new GraphicsPath(); int radiusCorrection = correction ? 1 : 0; switch (style) { case RoundStyle.None: path.AddRectangle(rect); break; case RoundStyle.All: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); break; case RoundStyle.Left: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddLine( rect.Right - radiusCorrection, rect.Y, rect.Right - radiusCorrection, rect.Bottom - radiusCorrection); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); break; case RoundStyle.Right: path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddLine(rect.X, rect.Bottom - radiusCorrection, rect.X, rect.Y); break; case RoundStyle.Top: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddLine( rect.Right - radiusCorrection, rect.Bottom - radiusCorrection, rect.X, rect.Bottom - radiusCorrection); break; case RoundStyle.Bottom: path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); path.AddLine(rect.X, rect.Y, rect.Right - radiusCorrection, rect.Y); break; } path.CloseFigure(); return(path); }
internal static void RenderBackgroundInternal3( 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 < 1 || rect.Height < 1) { return; } using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Transparent, Color.Transparent, mode)) { FillBrush(brush, baseColor, borderColor, basePosition, drawGlass); if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (drawGlass) { RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 170, 0); if (baseColor.A > 0) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } } if (drawBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (drawGlass) { RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 200, 0); if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } } 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); } } } } }