]> O.S.I.I.S - jp/crow.git/commitdiff
add corner radius to 3d effect on border
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 26 Aug 2017 16:55:27 +0000 (18:55 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 27 Aug 2017 04:45:06 +0000 (06:45 +0200)
src/GraphicObjects/Border.cs

index 375d73213d301b2c0774742ee555769e41030b82..1e502e9afc5ef9a6682cc182fbe5eaa62e4b0b96 100644 (file)
@@ -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 ();