From 3025ab70f5fc51819f5980908a8a98d5d6426b7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Sat, 26 Aug 2017 18:55:27 +0200 Subject: [PATCH] add corner radius to 3d effect on border --- src/GraphicObjects/Border.cs | 91 +++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 23 deletions(-) diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs index 375d7321..1e502e9a 100644 --- a/src/GraphicObjects/Border.cs +++ b/src/GraphicObjects/Border.cs @@ -119,34 +119,79 @@ namespace Crow CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); gr.Fill (); - if (BorderWidth > 0) { - Foreground.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth); - } - - if (BorderStyle != BorderStyle.Normal) { + if (BorderStyle == BorderStyle.Normal) { + if (BorderWidth > 0) { + Foreground.SetAsSource (gr, rBack); + CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth); + } + }else{ gr.LineWidth = 1.0; - gr.SetSourceColor (sunkenColor); - gr.MoveTo (0.5 + rBack.Left, rBack.Bottom); - gr.LineTo (0.5 + rBack.Left, 0.5 + rBack.Y); - gr.LineTo (rBack.Right, 0.5 + rBack.Y); - if (BorderStyle == BorderStyle.Raised) { - gr.MoveTo (-1.5 + rBack.Right, 2.0 + rBack.Y); - gr.LineTo (-1.5 + rBack.Right, -1.5 + rBack.Bottom); - gr.LineTo (2.0 + rBack.Left, -1.5 + rBack.Bottom); + if (CornerRadius > 0.0) { + double radius = CornerRadius; + if ((radius > rBack.Height / 2.0) || (radius > rBack.Width / 2.0)) + radius = Math.Min(rBack.Height / 2.0, rBack.Width / 2.0); + gr.SetSourceColor (sunkenColor); + gr.MoveTo(0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); + gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI, Math.PI * 0.75); + gr.MoveTo(0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); + gr.LineTo(0.5 + rBack.Left, 0.5 + rBack.Top + radius); + gr.Arc (0.5 + rBack.Left + radius, 0.5 + rBack.Top + radius, radius, Math.PI , Math.PI*1.5); + gr.LineTo(-0.5 + rBack.Right - radius, 0.5 + rBack.Top); + gr.Arc (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, Math.PI*1.5 , Math.PI*1.75); + gr.Stroke(); + if (BorderStyle == BorderStyle.Raised) { + gr.MoveTo (-1.5 + rBack.Right , 1.5 + rBack.Top + radius); + gr.ArcNegative (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius-1.0, 0, -Math.PI * 0.25); + gr.MoveTo (-1.5 + rBack.Right , 1.5 + rBack.Top + radius); + gr.LineTo (-1.5 + rBack.Right , -1.5 + rBack.Bottom - radius); + gr.Arc (-0.5 + rBack.Right -radius, -0.5 + rBack.Bottom - radius, radius-1.0, 0, Math.PI /2.0); + gr.LineTo (1.5 + rBack.Left + radius, -1.5 + rBack.Bottom); + gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius-1.0, Math.PI / 2.0, Math.PI*0.75 ); + gr.Stroke (); + + gr.SetSourceColor (raiseColor); + gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); + gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI, Math.PI * 0.75); + gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); + gr.LineTo (1.5 + rBack.Left, 1.5 + rBack.Top + radius); + gr.Arc (0.5 + rBack.Left + radius, 0.5 + rBack.Top + radius, radius - 1.0, Math.PI, Math.PI * 1.5); + gr.LineTo (-1.5 + rBack.Right - radius, 1.5 + rBack.Top); + gr.Arc (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius - 1.0, Math.PI * 1.5, Math.PI * 1.75); + } else { + gr.Stroke (); + gr.SetSourceColor (raiseColor); + } + gr.MoveTo (-0.5 + rBack.Right , 0.5 + rBack.Top + radius); + gr.ArcNegative (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, 0, -Math.PI * 0.25); + gr.MoveTo (-0.5 + rBack.Right , 0.5 + rBack.Top + radius); + gr.LineTo (-0.5 + rBack.Right , -0.5 + rBack.Bottom - radius); + gr.Arc (-0.5 + rBack.Right -radius, -0.5 + rBack.Bottom - radius, radius, 0, Math.PI /2.0); + gr.LineTo (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom); + gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI / 2.0, Math.PI*0.75 ); gr.Stroke (); - gr.SetSourceColor (raiseColor); - gr.MoveTo (1.5 + rBack.Left, -1.0 + rBack.Bottom); - gr.LineTo (1.5 + rBack.Left, 1.5 + rBack.Y); - gr.LineTo (rBack.Right, 1.5 + rBack.Y); } else { + gr.SetSourceColor (sunkenColor); + gr.MoveTo (0.5 + rBack.Left, rBack.Bottom); + gr.LineTo (0.5 + rBack.Left, 0.5 + rBack.Y); + gr.LineTo (rBack.Right, 0.5 + rBack.Y); + if (BorderStyle == BorderStyle.Raised) { + gr.MoveTo (-1.5 + rBack.Right, 2.0 + rBack.Y); + gr.LineTo (-1.5 + rBack.Right, -1.5 + rBack.Bottom); + gr.LineTo (2.0 + rBack.Left, -1.5 + rBack.Bottom); + gr.Stroke (); + gr.SetSourceColor (raiseColor); + gr.MoveTo (1.5 + rBack.Left, -1.0 + rBack.Bottom); + gr.LineTo (1.5 + rBack.Left, 1.5 + rBack.Y); + gr.LineTo (rBack.Right, 1.5 + rBack.Y); + } else { + gr.Stroke (); + gr.SetSourceColor (raiseColor); + } + gr.MoveTo (-0.5 + rBack.Right, 1.5 + rBack.Y); + gr.LineTo (-0.5 + rBack.Right, -0.5 + rBack.Bottom); + gr.LineTo (1.0 + rBack.Left, -0.5 + rBack.Bottom); gr.Stroke (); - gr.SetSourceColor (raiseColor); } - gr.MoveTo (-0.5 + rBack.Right, 1.5 + rBack.Y); - gr.LineTo (-0.5 + rBack.Right, -0.5 + rBack.Bottom); - gr.LineTo (1.0 + rBack.Left, -0.5 + rBack.Bottom); - gr.Stroke (); } gr.Save (); -- 2.47.3