]> O.S.I.I.S - jp/crow.git/commitdiff
border tests
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Nov 2017 23:31:40 +0000 (00:31 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Nov 2017 23:31:40 +0000 (00:31 +0100)
src/GraphicObjects/Border.cs
src/GraphicObjects/Label.cs

index 1e502e9afc5ef9a6682cc182fbe5eaa62e4b0b96..ef210b5788363231839480a7007e8de02c7155ef 100644 (file)
@@ -46,19 +46,19 @@ namespace Crow
                #region private fields
                int _borderWidth;
                BorderStyle _borderStyle;
-               Fill raiseColor = Color.Gray;
+               Fill raisedColor = Color.Gray;
                Fill sunkenColor = Color.Jet;
                #endregion
 
                #region public properties
                [XmlAttributeAttribute]
-               public virtual Fill RaiseColor {
-                       get { return raiseColor; }
+               public virtual Fill RaisedColor {
+                       get { return raisedColor; }
                        set {
-                               if (raiseColor == value)
+                               if (raisedColor == value)
                                        return;
-                               raiseColor = value;
-                               NotifyValueChanged ("RaiseColor", raiseColor);
+                               raisedColor = value;
+                               NotifyValueChanged ("RaisedColor", raisedColor);
                                RegisterForRedraw ();
                        }
                }
@@ -109,47 +109,62 @@ namespace Crow
                }
                protected override void onDraw (Cairo.Context gr)
                {
+                       drawborder2 (gr);
+
+                       gr.Save ();
+                       if (ClipToClientRect) {
+                               //clip to client zone
+                               CairoHelpers.CairoRectangle (gr, ClientRectangle,Math.Max(0.0, CornerRadius-Margin));
+                               gr.Clip ();
+                       }
+
+                       if (child != null)
+                               child.Paint (ref gr);
+                       gr.Restore ();
+               }
+               void drawborder2(Cairo.Context gr){
                        Rectangle rBack = new Rectangle (Slot.Size);
 
                        //rBack.Inflate (-Margin);
-//                     if (BorderWidth > 0) 
-//                             rBack.Inflate (-BorderWidth / 2);                       
+                       //                      if (BorderWidth > 0)
+                       //                              rBack.Inflate (-BorderWidth / 2);
 
                        Background.SetAsSource (gr, rBack);
                        CairoHelpers.CairoRectangle(gr, rBack, CornerRadius);
                        gr.Fill ();
 
+
                        if (BorderStyle == BorderStyle.Normal) {
                                if (BorderWidth > 0) {
                                        Foreground.SetAsSource (gr, rBack);
-                                       CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth);
+                                       CairoHelpers.CairoRectangle (gr, rBack, CornerRadius, BorderWidth);
                                }
-                       }else{
+                       } else {
                                gr.LineWidth = 1.0;
                                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);
+                                               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();
+                                       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.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.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.SetSourceColor (raisedColor);
                                                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);
@@ -159,15 +174,15 @@ namespace Crow
                                                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.SetSourceColor (raisedColor);
                                        }
-                                       gr.MoveTo (-0.5 + rBack.Right , 0.5 + rBack.Top + radius);
+                                       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.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.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI / 2.0, Math.PI * 0.75);
                                        gr.Stroke ();
                                } else {
                                        gr.SetSourceColor (sunkenColor);
@@ -179,13 +194,13 @@ namespace Crow
                                                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.SetSourceColor (raisedColor);
                                                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.SetSourceColor (raisedColor);
                                        }
                                        gr.MoveTo (-0.5 + rBack.Right, 1.5 + rBack.Y);
                                        gr.LineTo (-0.5 + rBack.Right, -0.5 + rBack.Bottom);
@@ -193,18 +208,45 @@ namespace Crow
                                        gr.Stroke ();
                                }
                        }
+               }
+               void drawborder1(Cairo.Context gr){
+                       Rectangle rBack = new Rectangle (Slot.Size);
 
-                       gr.Save ();
-                       if (ClipToClientRect) {
-                               //clip to client zone
-                               CairoHelpers.CairoRectangle (gr, ClientRectangle,Math.Max(0.0, CornerRadius-Margin));
-                               gr.Clip ();
-                       }
+                       //rBack.Inflate (-Margin);
+                       //                      if (BorderWidth > 0)
+                       //                              rBack.Inflate (-BorderWidth / 2);
 
-                       if (child != null)
-                               child.Paint (ref gr);
-                       gr.Restore ();
-               }               
+                       Background.SetAsSource (gr, rBack);
+                       CairoHelpers.CairoRectangle(gr, rBack, CornerRadius);
+                       gr.Fill ();
+
+                       double bw = _borderWidth;
+                       double crad = CornerRadius;
+
+                       if (bw > 0) {
+                               if (BorderStyle == BorderStyle.Normal)
+                                       Foreground.SetAsSource (gr, rBack);
+                               else {
+                                       if (BorderStyle == BorderStyle.Sunken)
+                                               gr.SetSourceColor (raisedColor);
+                                       else
+                                               gr.SetSourceColor (sunkenColor);
+
+                                       CairoHelpers.CairoRectangle (gr, rBack, crad, bw);
+
+                                       if (BorderStyle == BorderStyle.Sunken)
+                                               gr.SetSourceColor (sunkenColor);
+                                       else
+                                               gr.SetSourceColor (raisedColor);
+
+                                       bw /= 2.0;
+                                       rBack.Width -= (int)Math.Round(bw);
+                                       rBack.Height -= (int)Math.Round(bw);
+                               }
+
+                               CairoHelpers.CairoRectangle (gr, rBack, crad, bw);
+                       }
+               }
                #endregion
        }
 }
index 214e14ed456d4893c4997bbcea79fa35a3255eb6..e477c3f693e9134b248be270d5fc2d0353d05f49 100644 (file)
@@ -265,7 +265,6 @@ namespace Crow
                {
                        get {
                                return lines [CurrentLine] [CurrentColumn];
-                               //return _currentCol > lines[CurrentLine].Length ? (char)0 : lines [CurrentLine] [CurrentColumn];
                        }
                }
                /// <summary>