/// <summary> /// Initializes a new instance of the <see cref="AdvancedFrame"/> class. /// </summary> public AdvancedFrame() { BackgroundColor = Color.Transparent; HasShadow = false; Corners = RoundedCorners.none; this.Padding = new Thickness(0, 0, 0, 0); }
public void DrawShape(Rectangle rect, int radius, PenPlus pen, GraphicShape shape, RoundedCorners corners) { if (rect.Width < 1 || rect.Height < 1) return; PathFunc func = GetShapeFunc(shape); GraphicsPath path = func(rect, radius, 0, PathMode.All, corners); this.DrawPath(pen, path); }
private static Image DrawRoundedRectangle( Graphics g, Brush b, Rectangle rec, int radius, RoundedCorners corners, Image img) { int x = rec.X; int y = rec.Y; int diameter = radius * 2; var horiz = new Rectangle(x, y + radius, rec.Width, rec.Height - diameter); var vert = new Rectangle(x + radius, y, rec.Width - diameter, rec.Height); g.FillRectangle(b, horiz); g.FillRectangle(b, vert); if ((corners & RoundedCorners.TopLeft) == RoundedCorners.TopLeft) { g.FillEllipse(b, x, y, diameter, diameter); } else { g.FillRectangle(b, x, y, diameter, diameter); } if ((corners & RoundedCorners.TopRight) == RoundedCorners.TopRight) { g.FillEllipse(b, x + rec.Width - (diameter + 1), y, diameter, diameter); } else { g.FillRectangle(b, x + rec.Width - (diameter + 1), y, diameter, diameter); } if ((corners & RoundedCorners.BottomLeft) == RoundedCorners.BottomLeft) { g.FillEllipse(b, x, y + rec.Height - (diameter + 1), diameter, diameter); } else { g.FillRectangle(b, x, y + rec.Height - (diameter + 1), diameter, diameter); } if ((corners & RoundedCorners.BottomRight) == RoundedCorners.BottomRight) { g.FillEllipse(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter); } else { g.FillRectangle(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter); } AForge.Imaging.Filters.Blur blur = new AForge.Imaging.Filters.Blur(); return(blur.Apply((Bitmap)img)); }
public static void DrawRoundedRectangle(this Graphics g, Color color, Rectangle rec, int radius, RoundedCorners corners) { using (var b = new SolidBrush(color)) { int x = rec.X; int y = rec.Y; int diameter = radius * 2; var horiz = new Rectangle(x, y + radius, rec.Width, rec.Height - diameter); var vert = new Rectangle(x + radius, y, rec.Width - diameter, rec.Height); g.FillRectangle(b, horiz); g.FillRectangle(b, vert); if ((corners & RoundedCorners.TopLeft) == RoundedCorners.TopLeft) { g.FillEllipse(b, x, y, diameter, diameter); } else { g.FillRectangle(b, x, y, diameter, diameter); } if ((corners & RoundedCorners.TopRight) == RoundedCorners.TopRight) { g.FillEllipse(b, x + rec.Width - (diameter + 1), y, diameter, diameter); } else { g.FillRectangle(b, x + rec.Width - (diameter + 1), y, diameter, diameter); } if ((corners & RoundedCorners.BottomLeft) == RoundedCorners.BottomLeft) { g.FillEllipse(b, x, y + rec.Height - (diameter + 1), diameter, diameter); } else { g.FillRectangle(b, x, y + rec.Height - (diameter + 1), diameter, diameter); } if ((corners & RoundedCorners.BottomRight) == RoundedCorners.BottomRight) { g.FillEllipse(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter); } else { g.FillRectangle(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter); } } }
public void TestRoundedCornersRegex() { const string Querystring = "roundedcorners=30"; RoundedCornerLayer expected = new RoundedCornerLayer(30, true, true, true, true); RoundedCorners roundedCorners = new RoundedCorners(); roundedCorners.MatchRegexIndex(Querystring); RoundedCornerLayer actual = roundedCorners.DynamicParameter; Assert.AreEqual(expected, actual); }
public static void FillRoundedRectangle( this Graphics graphics, Brush brush, RectangleF rectangle, int radius, RoundedCorners filter) { graphics.FillRoundedRectangle( brush, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, radius, filter); }
public static void DrawRoundedRectangle( this Graphics graphics, Pen pen, RectangleF rectangle, int radius, RoundedCorners filter) { graphics.DrawRoundedRectangle( pen, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, radius, filter); }
public static void DrawRoundedRectangleBorder(this Graphics g, Color color, Color bColor, Rectangle rec, int radius, int borderWidth, RoundedCorners corners) { g.DrawRoundedRectangle(bColor, rec, radius, corners); if (borderWidth == 0) { return; } rec.Height -= borderWidth * 2; rec.Width -= borderWidth * 2; rec.X += borderWidth; rec.Y += borderWidth; g.DrawRoundedRectangle(color, rec, radius - borderWidth, corners); }
/// <summary> /// Adds rounded corners to the current image. /// </summary> /// <param name="roundedCornerLayer"> /// The <see cref="T:ImageProcessor.Imaging.RoundedCornerLayer"/> containing the properties to round corners on the image. /// </param> /// <returns> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public ImageFactory RoundedCorners(RoundedCornerLayer roundedCornerLayer) { if (this.ShouldProcess) { if (roundedCornerLayer.Radius < 0) { roundedCornerLayer.Radius = 0; } RoundedCorners roundedCorners = new RoundedCorners { DynamicParameter = roundedCornerLayer }; this.CurrentImageFormat.ApplyProcessor(roundedCorners.ProcessImage, this); } return(this); }
/// <summary> /// Renders the buttons; /// </summary> public void Render() { if (buttons == null) { return; } int c = buttons.Count; controls.Clear(); int index = 0; int x = 0; int y = 0; int h = Bounds.Height; int w0 = c > 0 ? Bounds.Width / c : 0; if (buttonWidth > 0) { w0 = Math.Min(buttonWidth, Width); } c--; RoundedCorners corners = c == 0 ? RoundedCorners.All : RoundedCorners.Left; foreach (FluidButton btn in buttons) { btn.BeginInit(); int w = (index != c) ? w0 : (Bounds.Width - x); if (btn.BackColor == Color.Transparent || btn.BackColor.IsEmpty) { btn.BackColor = this.BackColor; } btn.Bounds = new Rectangle(x, y, w + ((index != c) ? (int)ScaleFactor.Width : 0), h); btn.ScaleFactor = ScaleFactor; btn.Corners = corners & Corners; btn.Command = index.ToString(); //btn.Alpha = alpha; btn.Anchor = System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom; btn.EndInit(); index++; controls.Add(btn); x += w; corners = index == c ? RoundedCorners.Right : RoundedCorners.None; } Invalidate(); OnButtonsChanged(); }
/// <summary> /// Rotates the current image by the given angle. /// </summary> /// <param name="rotateLayer"> /// The <see cref="T:ImageProcessor.Imaging.RotateLayer"/> containing the properties to rotate the image. /// </param> /// <returns> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> //public ImageFactory Rotate(RotateLayer rotateLayer) //{ // if (this.ShouldProcess) // { // // Sanitize the input. // if (rotateLayer.Angle > 360 || rotateLayer.Angle < 0) // { // rotateLayer.Angle = 0; // } // Rotate rotate = new Rotate { DynamicParameter = rotateLayer }; // this.Image = rotate.ProcessImage(this); // } // return this; //} /// <summary> /// Adds rounded corners to the current image. /// </summary> /// <param name="roundedCornerLayer"> /// The <see cref="T:ImageProcessor.Imaging.RoundedCornerLayer"/> containing the properties to round corners on the image. /// </param> /// <returns> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public ImageFactory RoundedCorners(RoundedCornerLayer roundedCornerLayer) { if (this.ShouldProcess) { if (roundedCornerLayer.Radius < 0) { roundedCornerLayer.Radius = 0; } RoundedCorners roundedCorners = new RoundedCorners { DynamicParameter = roundedCornerLayer }; this.Image = roundedCorners.ProcessImage(this); } return(this); }
public static void FillRoundedRectangle( this Graphics graphics, Brush brush, float x, float y, float width, float height, float radius, RoundedCorners filter) { var rectangle = new RectangleF(x, y, width, height); var path = graphics.GenerateRoundedRectangle(rectangle, radius, filter); var old = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.FillPath(brush, path); graphics.SmoothingMode = old; }
public static void DrawRoundedRectangleBorderGradiantFill(this Graphics g, Color start, Color end, Color bColor, Rectangle rec, int radius, int borderWidth, RoundedCorners corners) { using (var b = new Bitmap(rec.Width, rec.Height)) using (Graphics gGf = Graphics.FromImage(b)) using (var bMask = new Bitmap(rec.Width, rec.Height)) using (Graphics gMask = Graphics.FromImage(bMask)) { var gfRec = new Rectangle(0, 0, rec.Width, rec.Height); gGf.GradientFill(gfRec, start, end, GradientFillDirection.Vertical); gMask.Clear(Color.White); gMask.DrawRoundedRectangleBorder(Color.Green, bColor, gfRec, radius, borderWidth, corners); var maskAttr = new ImageAttributes(); maskAttr.SetColorKey(Color.Green, Color.Green); gGf.DrawImage(bMask, gfRec, 0, 0, gfRec.Width, gfRec.Height, GraphicsUnit.Pixel, maskAttr); g.DrawAlphaFirstPix(b, rec, gfRec); } }
public static void DrawRoundedBorder(this Graphics g, Color color, Rectangle rec, int radius, int borderWidth, RoundedCorners corners) { using (Bitmap b = new Bitmap(rec.Width, rec.Height)) using (Graphics gb = Graphics.FromImage(b)) { var gfRec = new Rectangle(0, 0, rec.Width, rec.Height); gb.Clear(Color.Green); gb.DrawRoundedRectangle(color, gfRec, radius, corners); gfRec.Height -= borderWidth << 1; gfRec.Width -= borderWidth << 1; gfRec.X += borderWidth; gfRec.Y += borderWidth; gb.DrawRoundedRectangle(Color.Green, gfRec, radius - borderWidth, corners); var maskAttr = new ImageAttributes(); maskAttr.SetColorKey(Color.Green, Color.Green); g.DrawImage(b, rec, 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, maskAttr); } }
public static void DrawRoundedRectangle(Graphics g/*, Color color*/, Rectangle rec, int radius, RoundedCorners corners, Brush b) { //using (var b = new SolidBrush(color)) { int x = rec.X; int y = rec.Y; int diameter = radius * 2; var horiz = new Rectangle(x, y + radius, rec.Width, rec.Height - diameter); var vert = new Rectangle(x + radius, y, rec.Width - diameter, rec.Height); g.FillRectangle(b, horiz); g.FillRectangle(b, vert); if ((corners & RoundedCorners.TopLeft) == RoundedCorners.TopLeft) g.FillEllipse(b, x, y, diameter, diameter); else g.FillRectangle(b, x, y, diameter, diameter); if ((corners & RoundedCorners.TopRight) == RoundedCorners.TopRight) g.FillEllipse(b, x + rec.Width - (diameter + 1), y, diameter, diameter); else g.FillRectangle(b, x + rec.Width - (diameter + 1), y, diameter, diameter); if ((corners & RoundedCorners.BottomLeft) == RoundedCorners.BottomLeft) g.FillEllipse(b, x, y + rec.Height - (diameter + 1), diameter, diameter); else g.FillRectangle(b, x, y + rec.Height - (diameter + 1), diameter, diameter); if ((corners & RoundedCorners.BottomRight) == RoundedCorners.BottomRight) g.FillEllipse(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter); else g.FillRectangle(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter); } }
private static GraphicsPath GetRectPath(Rectangle rect, int r, int reflectionHeight, PathMode mode, RoundedCorners corners) { switch (mode) { case PathMode.Top: rect.Height = reflectionHeight; break; case PathMode.Bottom: rect.Height = rect.Height - reflectionHeight; rect.Y += reflectionHeight; break; } GraphicsPath path = new GraphicsPath(); path.AddRectangle(rect); // path.CloseFigure(); return(path); }
private static GraphicsPath GetRoundPath(Rectangle rect, int r, int reflectionHeight, PathMode mode, RoundedCorners corners) { GraphicsPath path = new GraphicsPath(); int x = rect.X, y = rect.Y, w = rect.Width, h = rect.Height; if (mode != PathMode.Bottom) { if ((corners & RoundedCorners.TopLeft) != 0) { path.AddArc(x, y, r, r, 180, 90); } else { path.AddLine(x, y, x + r, y); } if ((corners & RoundedCorners.TopRight) != 0) { path.AddArc(x + w - r, y, r, r, 270, 90); } else { path.AddLine(x + w - r, y, x + w, y); } } RectangleF gr = new RectangleF(x, y + r, w, h - r); if (mode != PathMode.All) { Point pt1 = new Point(x + w, y + reflectionHeight); Point pt2 = new Point(x, y + reflectionHeight); if (mode == PathMode.Top) { path.AddLine(pt1, pt2); } else { //pt1.Y--; //pt2.Y--; path.AddLine(pt2, pt1); } } if (mode != PathMode.Top) { if ((corners & RoundedCorners.BottomRight) != 0) { path.AddArc(x + w - r, y + h - r, r, r, 0, 90); } else { path.AddLine(x + w, y + h, x + w - r, y + h); } if ((corners & RoundedCorners.BottomLeft) != 0) { path.AddArc(x, y + h - r, r, r, 90, 90); } else { path.AddLine(x + r, y + h, x, y + h); } } path.CloseFigure(); return(path); }
private static GraphicsPath GenerateRoundedRectangle( this Graphics graphics, RectangleF rectangle, float radius, RoundedCorners filter) { var path = new GraphicsPath(); if (radius <= 0.0F || filter == RoundedCorners.None) { path.AddRectangle(rectangle); path.CloseFigure(); return(path); } if (radius >= (Math.Min(rectangle.Width, rectangle.Height)) / 3) { return(graphics.GenerateCapsule(rectangle)); } var diameter = radius * 2.0F; var sizeF = new SizeF(diameter, diameter); var arc = new RectangleF(rectangle.Location, sizeF); if ((RoundedCorners.TopLeft & filter) == RoundedCorners.TopLeft) { path.AddArc(arc, 180, 90); } else { path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y); path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y); } arc.X = rectangle.Right - diameter; if ((RoundedCorners.TopRight & filter) == RoundedCorners.TopRight) { path.AddArc(arc, 270, 90); } else { path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y); path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X + arc.Width, arc.Y); } arc.Y = rectangle.Bottom - diameter; if ((RoundedCorners.BottomRight & filter) == RoundedCorners.BottomRight) { path.AddArc(arc, 0, 90); } else { path.AddLine(arc.X + arc.Width, arc.Y, arc.X + arc.Width, arc.Y + arc.Height); path.AddLine(arc.X, arc.Y + arc.Height, arc.X + arc.Width, arc.Y + arc.Height); } arc.X = rectangle.Left; if ((RoundedCorners.BottomLeft & filter) == RoundedCorners.BottomLeft) { path.AddArc(arc, 90, 90); } else { path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X, arc.Y + arc.Height); path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y); } path.CloseFigure(); return(path); }
private static GraphicsPath GetNextPath(Rectangle rect, int r, int reflectionHeight, PathMode mode, RoundedCorners corners) { GraphicsPath path = new GraphicsPath(); int x = rect.X, y = rect.Y, w = rect.Width, h = rect.Height; int h2 = rect.Height / 2; int offset = (h - h2 * 2); int r2 = r / 2; if (mode != PathMode.Bottom) { path.AddArc(x, y, r, r, 180, 90); path.AddArc(x + w - h2 - r2, y, r, r, 270, 45); path.AddArc(x + w - r, y + h2 - r2, r, r, 270 + 45, 45); } RectangleF gr = new RectangleF(x, y + r, w, h - r); if (mode != PathMode.All) { Point pt1 = new Point(x + w, y + h2); Point pt2 = new Point(x, y + h2); if (mode == PathMode.Top) { path.AddLine(pt1, pt2); } else { path.AddLine(pt2, pt1); } } if (mode != PathMode.Top) { path.AddArc(x + w - r, y + h2 - r2, r, r, 0, 45); path.AddArc(x + w - h2 - r2 + offset, y + h - r, r, r, 45, 45); path.AddArc(x, y + h - r, r, r, 90, 90); } path.CloseFigure(); return(path); }
private static Image DrawRoundedRectangle( Graphics g, Brush b, Rectangle rec, int radius, RoundedCorners corners, Image img) { int x = rec.X; int y = rec.Y; int diameter = radius * 2; var horiz = new Rectangle(x, y + radius, rec.Width, rec.Height - diameter); var vert = new Rectangle(x + radius, y, rec.Width - diameter, rec.Height); g.FillRectangle(b, horiz); g.FillRectangle(b, vert); if ((corners & RoundedCorners.TopLeft) == RoundedCorners.TopLeft) g.FillEllipse(b, x, y, diameter, diameter); else g.FillRectangle(b, x, y, diameter, diameter); if ((corners & RoundedCorners.TopRight) == RoundedCorners.TopRight) g.FillEllipse(b, x + rec.Width - (diameter + 1), y, diameter, diameter); else g.FillRectangle(b, x + rec.Width - (diameter + 1), y, diameter, diameter); if ((corners & RoundedCorners.BottomLeft) == RoundedCorners.BottomLeft) g.FillEllipse(b, x, y + rec.Height - (diameter + 1), diameter, diameter); else g.FillRectangle(b, x, y + rec.Height - (diameter + 1), diameter, diameter); if ((corners & RoundedCorners.BottomRight) == RoundedCorners.BottomRight) g.FillEllipse(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter); else g.FillRectangle(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter); AForge.Imaging.Filters.Blur blur = new AForge.Imaging.Filters.Blur(); return blur.Apply((Bitmap)img); }
private static GraphicsPath GetEllipsePath(Rectangle rect, int r, int reflectionHeight, PathMode mode, RoundedCorners corners) { GraphicsPath path = new GraphicsPath(); switch (mode) { case PathMode.All: path.AddEllipse(rect); break; case PathMode.Top: path.AddArc(rect, 180, 180); break; case PathMode.Bottom: path.AddArc(rect, 0, 180); break; } path.CloseFigure(); return path; }
protected override void InitControl() { base.InitControl(); EnableDoubleBuffer = false; Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; BackColor = Color.Black; ForeColor = Color.White; rows = new ButtonGroup[] { new ButtonGroup(), new ButtonGroup(), new ButtonGroup(), new ButtonGroup(), }; int index = 0; int buttonIndex = 0; foreach (ButtonGroup row in rows) { RoundedCorners corners; switch (index++) { case 0: corners = RoundedCorners.Top; break; case 3: corners = RoundedCorners.Bottom; break; default: corners = RoundedCorners.None; break; } row.Anchor = AnchorStyles.None; row.ButtonWidth = ScaleX(54); //row.Buttons.RaiseListChangedEvents = false; for (int i = 0; i < 4; i++) { row.Corners = corners; FluidButton btn = new FlatButton(labels[buttonIndex]); btn.Tag = buttonIndex; btn.Command = i.ToString(); buttons[buttonIndex] = btn; if (i != 3) btn.PaintButtonText += new EventHandler<FluidPaintEventArgs>(btn_PaintButtonText); btn.Click += new EventHandler(btn_Click); // btn.ForeColor = ForeColor; switch (buttonIndex) { //case 3: btn.BackColor = Color.FromArgb(48, 0, 0); break; case 15: btn.BackColor = Color.FromArgb(0, 40, 0); break; default: btn.BackColor = BackColor; break; } row.Buttons.Add(btn); buttonIndex++; } //row.Buttons.RaiseListChangedEvents = true; //row.Render(); controls.Add(row); } Layout(); }
public void GradientFillShape(Rectangle rect, int radius, Color startColor, Color endColor, GradientMode gradientMode, GraphicShape shape, RoundedCorners corners) { if (rect.Width < 1 || rect.Height < 1) { return; } PathFunc func = GetShapeFunc(shape); SmoothingMode mode = SmoothingMode; try { SmoothingMode = SmoothingMode.None; int x = rect.X, y = rect.Y, w = rect.Width, h = rect.Height; int reflectionHeight = h / 2; PointF p1 = new PointF(x, y); PointF p2 = new PointF(x, y + reflectionHeight); if (gradientMode == GradientMode.Top) { PathMode pathMode = endColor.A == 255 ? PathMode.Bottom : PathMode.All; using (GraphicsPath path = func(rect, radius, reflectionHeight, pathMode, corners)) { using (SolidBrushPlus brush = new SolidBrushPlus(endColor)) { this.FillPath(brush, path); } } using (GraphicsPath path = func(rect, radius, reflectionHeight, PathMode.Top, corners)) { using (LinearGradientBrush brush = new LinearGradientBrush(p1, p2, startColor, endColor)) { this.FillPath(brush, path); } } } else { PathMode pathMode = endColor.A == 255 ? PathMode.Top : PathMode.All; using (GraphicsPath path = func(rect, radius, reflectionHeight, PathMode.All, corners)) { using (SolidBrushPlus brush = new SolidBrushPlus(endColor)) { this.FillPath(brush, path); } } using (GraphicsPath path = func(rect, radius, reflectionHeight, PathMode.Bottom, corners)) { p1.Y = y + reflectionHeight - 1; p2.Y = y + h; using (LinearGradientBrush brush = new LinearGradientBrush(p1, p2, endColor, startColor)) { this.FillPath(brush, path); } } } } finally { SmoothingMode = mode; } }
private static GraphicsPath GetEllipsePath(Rectangle rect, int r, int reflectionHeight, PathMode mode, RoundedCorners corners) { GraphicsPath path = new GraphicsPath(); switch (mode) { case PathMode.All: path.AddEllipse(rect); break; case PathMode.Top: path.AddArc(rect, 180, 180); break; case PathMode.Bottom: path.AddArc(rect, 0, 180); break; } path.CloseFigure(); return(path); }
private static GraphicsPath GetRoundPath(Rectangle rect, int r, int reflectionHeight, PathMode mode, RoundedCorners corners) { GraphicsPath path = new GraphicsPath(); int x = rect.X, y = rect.Y, w = rect.Width, h = rect.Height; if (mode != PathMode.Bottom) { if ((corners & RoundedCorners.TopLeft) != 0) path.AddArc(x, y, r, r, 180, 90); else path.AddLine(x, y, x + r, y); if ((corners & RoundedCorners.TopRight) != 0) path.AddArc(x + w - r, y, r, r, 270, 90); else path.AddLine(x + w - r, y, x + w, y); } RectangleF gr = new RectangleF(x, y + r, w, h - r); if (mode != PathMode.All) { Point pt1 = new Point(x + w, y + reflectionHeight); Point pt2 = new Point(x, y + reflectionHeight); if (mode == PathMode.Top) { path.AddLine(pt1, pt2); } else { //pt1.Y--; //pt2.Y--; path.AddLine(pt2, pt1); } } if (mode != PathMode.Top) { if ((corners & RoundedCorners.BottomRight) != 0) path.AddArc(x + w - r, y + h - r, r, r, 0, 90); else path.AddLine(x + w, y + h, x + w - r, y + h); if ((corners & RoundedCorners.BottomLeft) != 0) path.AddArc(x, y + h - r, r, r, 90, 90); else path.AddLine(x + r, y + h, x, y + h); } path.CloseFigure(); return path; }
/// <summary> /// Paints a rounded rectangle with a gradient. /// </summary> /// <param name="rect">The rectangle to paint.</param> /// <param name="radius">The radius of the corner.</param> /// <param name="startColor">The start color of the gradiant.</param> /// <param name="endColor">The end color of the gradiant.</param> /// <param name="gradientMode">The gradiant mode.</param> /// <param name="corners">Specifies which corners to be rounded.</param> public void GradientFillRoundRectangle(Rectangle rect, int radius, Color startColor, Color endColor, GradientMode gradientMode, RoundedCorners corners) { GradientFillShape(rect, radius, startColor, endColor, gradientMode, GraphicShape.Rounded, corners); }
private static GraphicsPath GetNextPath(Rectangle rect, int r, int reflectionHeight, PathMode mode, RoundedCorners corners) { GraphicsPath path = new GraphicsPath(); int x = rect.X, y = rect.Y, w = rect.Width, h = rect.Height; int h2 = rect.Height / 2; int offset = (h - h2 * 2); int r2 = r / 2; if (mode != PathMode.Bottom) { path.AddArc(x, y, r, r, 180, 90); path.AddArc(x + w - h2 - r2, y, r, r, 270, 45); path.AddArc(x + w - r, y + h2 - r2, r, r, 270 + 45, 45); } RectangleF gr = new RectangleF(x, y + r, w, h - r); if (mode != PathMode.All) { Point pt1 = new Point(x + w, y + h2); Point pt2 = new Point(x, y + h2); if (mode == PathMode.Top) { path.AddLine(pt1, pt2); } else { path.AddLine(pt2, pt1); } } if (mode != PathMode.Top) { path.AddArc(x + w - r, y + h2 - r2, r, r, 0, 45); path.AddArc(x + w - h2 - r2 + offset, y + h - r, r, r, 45, 45); path.AddArc(x, y + h - r, r, r, 90, 90); } path.CloseFigure(); return path; }
public static void DrawRoundedRectangleGradiantFill(this Graphics g, Color start, Color end, Rectangle rec, int radius, RoundedCorners corners) { DrawRoundedRectangleBorderGradiantFill(g, start, end, Color.White, rec, radius, 0, corners); }
public void DrawShape(Rectangle rect, int radius, PenPlus pen, GraphicShape shape, RoundedCorners corners) { if (rect.Width < 1 || rect.Height < 1) { return; } PathFunc func = GetShapeFunc(shape); GraphicsPath path = func(rect, radius, 0, PathMode.All, corners); this.DrawPath(pen, path); }
/// <summary> /// Renders the buttons; /// </summary> public void Render() { if (buttons == null) return; int c = buttons.Count; controls.Clear(); int index = 0; int x = 0; int y = 0; int h = Bounds.Height; int w0 = c > 0 ? Bounds.Width / c : 0; if (buttonWidth > 0) w0 = Math.Min(buttonWidth, Width); c--; RoundedCorners corners = c == 0 ? RoundedCorners.All : RoundedCorners.Left; foreach (FluidButton btn in buttons) { btn.BeginInit(); int w = (index != c) ? w0 : (Bounds.Width - x); if (btn.BackColor == Color.Transparent || btn.BackColor.IsEmpty) { btn.BackColor = this.BackColor; } btn.Bounds = new Rectangle(x, y, w + ((index != c) ? (int)ScaleFactor.Width : 0), h); btn.ScaleFactor = ScaleFactor; btn.Corners = corners & Corners; btn.Command = index.ToString(); //btn.Alpha = alpha; btn.Anchor = System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom; btn.EndInit(); index++; controls.Add(btn); x += w; corners = index == c ? RoundedCorners.Right : RoundedCorners.None; } Invalidate(); OnButtonsChanged(); }
public void GradientFillShape(Rectangle rect, int radius, Color startColor, Color endColor, GradientMode gradientMode, GraphicShape shape, RoundedCorners corners) { if (rect.Width < 1 || rect.Height < 1) return; PathFunc func = GetShapeFunc(shape); SmoothingMode mode = SmoothingMode; try { SmoothingMode = SmoothingMode.None; int x = rect.X, y = rect.Y, w = rect.Width, h = rect.Height; int reflectionHeight = h / 2; PointF p1 = new PointF(x, y); PointF p2 = new PointF(x, y + reflectionHeight); if (gradientMode == GradientMode.Top) { PathMode pathMode = endColor.A == 255 ? PathMode.Bottom : PathMode.All; using (GraphicsPath path = func(rect, radius, reflectionHeight, pathMode, corners)) { using (SolidBrushPlus brush = new SolidBrushPlus(endColor)) { this.FillPath(brush, path); } } using (GraphicsPath path = func(rect, radius, reflectionHeight, PathMode.Top, corners)) { using (LinearGradientBrush brush = new LinearGradientBrush(p1, p2, startColor, endColor)) { this.FillPath(brush, path); } } } else { PathMode pathMode = endColor.A == 255 ? PathMode.Top : PathMode.All; using (GraphicsPath path = func(rect, radius, reflectionHeight, PathMode.All, corners)) { using (SolidBrushPlus brush = new SolidBrushPlus(endColor)) { this.FillPath(brush, path); } } using (GraphicsPath path = func(rect, radius, reflectionHeight, PathMode.Bottom, corners)) { p1.Y = y + reflectionHeight - 1; p2.Y = y + h; using (LinearGradientBrush brush = new LinearGradientBrush(p1, p2, endColor, startColor)) { this.FillPath(brush, path); } } } } finally { SmoothingMode = mode; } }
private static GraphicsPath GetRectPath(Rectangle rect, int r, int reflectionHeight, PathMode mode, RoundedCorners corners) { switch (mode) { case PathMode.Top: rect.Height = reflectionHeight; break; case PathMode.Bottom: rect.Height = rect.Height - reflectionHeight; rect.Y += reflectionHeight; break; } GraphicsPath path = new GraphicsPath(); path.AddRectangle(rect); // path.CloseFigure(); return path; }