]> O.S.I.I.S - jp/crow.git/commitdiff
adjusting stroke position to have sharper lines, ClipToClientRect property
authorjpbruyere <jp.bruyere@hotmail.com>
Sun, 14 Aug 2016 13:07:08 +0000 (15:07 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Sun, 14 Aug 2016 13:07:08 +0000 (15:07 +0200)
13 files changed:
Templates/GroupBox.template
Tests/Interfaces/Divers/imlEditor.crow
Tests/Interfaces/basicTests/0.crow
src/Cairo/CairoHelpers.cs
src/ExtensionsMethods.cs
src/GraphicObjects/Border.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/PrivateContainer.cs
src/GraphicObjects/Scroller.cs
src/GraphicObjects/TabItem.cs
src/GraphicObjects/TabView.cs
src/GraphicObjects/TemplatedControl.cs

index a373a29c2e958751e8f6495eb03f56b60cda3d25..4e70ceae75cb5f0a13b0eefa712d777bbaf20ec9 100755 (executable)
@@ -1,12 +1,16 @@
 <?xml version="1.0"?>
 <Container Background="{./Background}" Height="{./HeightPolicy}" Width="{./WidthPolicy}">
        <Group Height="{./HeightPolicy}" Width="{./WidthPolicy}">
-               <Border CornerRadius="5" BorderWidth="1" Margin="6" Foreground="{./Foreground}"
+               <VerticalStack Spacing="0"
                        Height="{./HeightPolicy}" Width="{./WidthPolicy}">
-                       <Container Name="Content" Margin="10" MinimumSize="70,10"
-                                       Height="{../../../HeightPolicy}" Width="{../../../WidthPolicy}"/>
-               </Border>
-               <Label Text="{./Caption}" VerticalAlignment="Top" Left="15"
+                       <GraphicObject Height="6" Width="{./WidthPolicy}"/>
+                       <Border  CornerRadius="5" BorderWidth="1" Margin="10" Foreground="{./Foreground}"
+                               Height="{./HeightPolicy}" Width="{./WidthPolicy}">
+                               <Container Name="Content" Margin="0" MinimumSize="70,10"
+                                               Height="{../../../HeightPolicy}" Width="{../../../WidthPolicy}"/>
+                       </Border>
+               </VerticalStack>
+               <Label Text="{./Caption}" VerticalAlignment="Top" Left="8"
                        Background="Clear" Margin="1"/>
        </Group>
 </Container>
\ No newline at end of file
index bbad04efd1c1041dcf9384d01017bc3adba5f9f3..17e711a54273fbe527b5084d1180ecc219f2b107 100644 (file)
@@ -14,7 +14,7 @@
                                                ValueChanged="./_scroller_ValueChanged">
                                        <TextBox Background="White" Height="Fit"
                                                        VerticalAlignment="Top"
-                                                       TextAlignment="TopLeft" Font="mono, 10"
+                                                       TextAlignment="TopLeft" Font="mono, 12"
                                                        TextChanged="onImlSourceChanged"
                                                        Text="{CurSources}" Multiline="true"/>
                                </Scroller>
index 50312cced62f39e8a5f6831c340a9bfc4db52a89..c41c13178d23ffc96afdb02d1227a876fffa3870 100755 (executable)
@@ -1,5 +1,7 @@
 <?xml version="1.0"?>
-<Border Width="80%" Height="80%" Background="DarkRed">
-       <TextBox Multiline="true" Font="mono, 12" Margin="0"
+<Group Background="SeaGreen" Fit="true" Margin="1">
+<Border Foreground="White" Margin="10" Width="Fit" Height="Fit" Background="DarkRed" BorderWidth="1">
+       <TextBox Multiline="true" Font="mono, 12" Margin="0" 
                Text="this is a test of double click\n and here a second line of text\n and again a third one"/>
 </Border>
+</Group>
\ No newline at end of file
index 8f9e63255ab85ced5d6977b533df9b88beecf841..b2b71f9616e20e37c4551ce83696ea852ed58afb 100644 (file)
@@ -31,7 +31,7 @@ namespace Crow
 
             return arr[minp];
         }
-               public static void CairoRectangle(Cairo.Context gr, Rectangle r, double radius, bool stroke = false)
+               public static void CairoRectangle(Cairo.Context gr, Rectangle r, double radius, double stroke = 0.0)
                {
                        if (radius > 0)
                                CairoHelpers.DrawRoundedRectangle (gr, r, radius, stroke);
@@ -42,10 +42,12 @@ namespace Crow
                {
                        gr.Arc(r.X + r.Width/2, r.Y + r.Height/2, Math.Min(r.Width,r.Height)/2, 0, 2*Math.PI);
                }
-               public static void DrawRoundedRectangle(Cairo.Context gr, Rectangle r, double radius, bool stroke = false)
+               public static void DrawRoundedRectangle(Cairo.Context gr, Rectangle r, double radius, double stroke = 0.0)
         {
-                       if (stroke) {
-                               DrawRoundedRectangle (gr, r.X + 0.5, r.Y + 0.5, r.Width - 1.0, r.Height - 1.0, radius);
+                       if (stroke>0.0) {
+                               gr.LineWidth = stroke;
+                               double hsw = stroke / 2.0;
+                               DrawRoundedRectangle (gr, r.X + hsw, r.Y + hsw, r.Width - stroke, r.Height - stroke, radius);
                                gr.Stroke ();
                        }else
                                DrawRoundedRectangle(gr, r.X, r.Y, r.Width, r.Height, radius);
index 07c371745347a8fd1822f09b239bbd3f05f1faec..d1b951b94ce2d920ded74aef89e6838b326e811c 100644 (file)
@@ -26,10 +26,12 @@ namespace Crow
        public static class ExtensionsMethods
        {
                #region Cairo extensions
-               public static void Rectangle(this Cairo.Context ctx, Rectangle r, bool stroke = false)
+               public static void Rectangle(this Cairo.Context ctx, Rectangle r, double stroke = 0.0)
                {
-                       if (stroke) {
-                               ctx.Rectangle (r.X + 0.5, r.Y + 0.5, r.Width - 1.0, r.Height - 1.0);
+                       if (stroke > 0.0) {
+                               ctx.LineWidth = stroke;
+                               double shw = stroke / 2.0;
+                               ctx.Rectangle (r.X + shw, r.Y + shw, r.Width - stroke, r.Height - stroke);
                                ctx.Stroke ();
                        }else
                                ctx.Rectangle (r.X, r.Y, r.Width, r.Height);
index bd72d7508721b0be1c4393499d267794f4fb2c04..a6e5432b29b045522da9bb7a529019eb26156d08 100644 (file)
@@ -44,24 +44,25 @@ namespace Crow
                {
                        Rectangle rBack = new Rectangle (Slot.Size);
 
-                       rBack.Inflate (-Margin);
-                       if (BorderWidth > 0) 
-                               rBack.Inflate (-BorderWidth / 2);                       
+                       //rBack.Inflate (-Margin);
+//                     if (BorderWidth > 0) 
+//                             rBack.Inflate (-BorderWidth / 2);                       
 
                        Background.SetAsSource (gr, rBack);
                        CairoHelpers.CairoRectangle(gr, rBack, CornerRadius);
                        gr.Fill ();
 
-                       if (BorderWidth > 0) {
-                               gr.LineWidth = BorderWidth;
+                       if (BorderWidth > 0) {                          
                                Foreground.SetAsSource (gr, rBack);
-                               CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, true);
+                               CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth);
                        }
 
                        gr.Save ();
-                       //clip to client zone
-                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
-                       gr.Clip ();
+                       if (ClipToClientRect) {
+                               //clip to client zone
+                               CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
+                               gr.Clip ();
+                       }
 
                        if (child != null)
                                child.Paint (ref gr);
index f8a1e5088cb9de709e231fb3713fd7bf7f6025bd..d5c920112620a0f5b2b65f492da6df876f7d08aa 100644 (file)
@@ -81,6 +81,7 @@ namespace Crow
                Size maximumSize = "0,0";
                Size minimumSize = "0,0";
                bool cacheEnabled = false;
+               bool clipToClientRect = true;
                object dataSource;
                string style;
                #endregion
@@ -184,6 +185,17 @@ namespace Crow
                                NotifyValueChanged ("CacheEnabled", cacheEnabled);
                        }
                }
+               [XmlAttributeAttribute()][DefaultValue(true)]
+               public virtual bool ClipToClientRect {
+                       get { return clipToClientRect; }
+                       set {
+                               if (clipToClientRect == value)
+                                       return;
+                               clipToClientRect = value;
+                               NotifyValueChanged ("ClipToClientRect", clipToClientRect);
+                               this.RegisterForRedraw ();
+                       }
+               }
                [XmlAttributeAttribute()][DefaultValue("unamed")]
                public virtual string Name {
                        get { return name; }
@@ -240,6 +252,19 @@ namespace Crow
                                this.RegisterForLayouting (LayoutingType.Y);
                        }
                }
+               /// <summary>
+               /// When set to True, the <see cref="T:Crow.GraphicObject"/>'s width and height will be set to Fit.
+               /// </summary>
+               [XmlAttributeAttribute()][DefaultValue(false)]
+               public virtual bool Fit {
+                       get { return Width == Measure.Fit && Height == Measure.Fit ? true : false; }
+                       set {
+                               if (value == Fit)
+                                       return;
+
+                               Width = Height = Measure.Fit;
+                       }
+               }
                [XmlAttributeAttribute()][DefaultValue("Stretched")]
                public virtual Measure Width {
                        get { return width; }
@@ -314,19 +339,6 @@ namespace Crow
                [XmlIgnore]public virtual Measure HeightPolicy { get {
                                return Height.Units == Unit.Percent || Height.IsFixed ?
                                        Measure.Stretched : Measure.Fit; } }
-               /// <summary>
-               /// When set to True, the <see cref="T:Crow.GraphicObject"/>'s width and height will be set to Fit.
-               /// </summary>
-               [XmlAttributeAttribute()][DefaultValue(false)]
-               public virtual bool Fit {
-                       get { return Width == Measure.Fit && Height == Measure.Fit ? true : false; }
-                       set {
-                               if (value == Fit)
-                                       return;
-
-                               Width = Height = Measure.Fit;
-                       }
-               }
                [XmlAttributeAttribute()][DefaultValue(false)]
                public virtual bool Focusable {
                        get { return focusable; }
index 3782640c53c398947bad0c670d3fdc94c914fe89..66f2f57e860c67983ee29e1da48d5a9e4caa0072 100644 (file)
@@ -169,9 +169,13 @@ namespace Crow
                        base.onDraw (gr);
 
                        gr.Save ();
-                       //clip to client zone
-                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
-                       gr.Clip ();
+
+                       if (ClipToClientRect) {
+                               //clip to client zone
+                               CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
+                               gr.Clip ();
+                       }
+
                        lock (children) {
                                foreach (GraphicObject g in Children) {
                                        g.Paint (ref gr);
index a6f52f2910ba92ca871036a2aead08bbccf0a38c..5f70dd17a42cdff9af0827e45b451507979c68a6 100644 (file)
@@ -158,9 +158,12 @@ namespace Crow
                        base.onDraw (gr);
 
                        gr.Save ();
-                       //clip to client zone
-                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
-                       gr.Clip ();
+
+                       if (ClipToClientRect) {
+                               //clip to client zone
+                               CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
+                               gr.Clip ();
+                       }
 
                        if (child != null)
                                child.Paint (ref gr);
index c248595d803971acd0397cc96d86fecdc5a3d7a1..4b83b0cb1bde26ad9ba10887f5b13a6cc7e332d6 100644 (file)
@@ -215,9 +215,11 @@ namespace Crow
                        gr.Fill ();
 
                        gr.Save ();
-                       //clip to scrolled client zone
-                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
-                       gr.Clip ();
+                       if (ClipToClientRect) {
+                               //clip to scrolled client zone
+                               CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
+                               gr.Clip ();
+                       }
 
                        gr.Translate (-ScrollX, -ScrollY);
                        if (child != null)
index c06a43a9357c0742c87f354a9b4c8a3c355ca991..e14a7815ec4c1d882eee491868f2b1dcca7253b0 100644 (file)
@@ -102,18 +102,19 @@ namespace Crow
                protected override void onDraw (Cairo.Context gr)
                {
                        int spacing = (Parent as TabView).Spacing;
-                       gr.MoveTo (0, TabTitle.Slot.Bottom);
-                       gr.LineTo (TabTitle.Slot.Left - spacing, TabTitle.Slot.Bottom);
+
+                       gr.MoveTo (0, TabTitle.Slot.Bottom-0.5);
+                       gr.LineTo (TabTitle.Slot.Left - spacing, TabTitle.Slot.Bottom-0.5);
                        gr.CurveTo (
-                               TabTitle.Slot.Left - spacing / 2, TabTitle.Slot.Bottom,
-                               TabTitle.Slot.Left - spacing / 2, 1,
-                               TabTitle.Slot.Left, 1);
-                       gr.LineTo (TabTitle.Slot.Right, 1);
+                               TabTitle.Slot.Left - spacing / 2, TabTitle.Slot.Bottom-0.5,
+                               TabTitle.Slot.Left - spacing / 2, 0.5,
+                               TabTitle.Slot.Left, 0.5);
+                       gr.LineTo (TabTitle.Slot.Right, 0.5);
                        gr.CurveTo (
-                               TabTitle.Slot.Right + spacing / 2, 1,
-                               TabTitle.Slot.Right + spacing / 2, TabTitle.Slot.Bottom,
-                               TabTitle.Slot.Right + spacing, TabTitle.Slot.Bottom);
-                       gr.LineTo (Slot.Width, TabTitle.Slot.Bottom);
+                               TabTitle.Slot.Right + spacing / 2, 0.5,
+                               TabTitle.Slot.Right + spacing / 2, TabTitle.Slot.Bottom-0.5,
+                               TabTitle.Slot.Right + spacing, TabTitle.Slot.Bottom-0.5);
+                       gr.LineTo (Slot.Width, TabTitle.Slot.Bottom-0.5);
 
                        gr.LineWidth = 1;
                        Foreground.SetAsSource (gr);
index fa352b0d1a6c384164e80787dfb0ef526d1c21f0..7f87fa111d175518d361428dd08056dc23aeddfb 100644 (file)
@@ -159,9 +159,12 @@ namespace Crow
                        gr.Fill ();
 
                        gr.Save ();
-                       //clip to client zone
-                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
-                       gr.Clip ();
+
+                       if (ClipToClientRect) {
+                               //clip to client zone
+                               CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
+                               gr.Clip ();
+                       }
 
                        for (int i = 0; i < Children.Count; i++) {
                                if (i == SelectedTab)
index 4745b87b6cddd7c1cdccae208a91f899736cba20..b10d89eb98e1045fd91c7dadcca44774a1294e3e 100644 (file)
@@ -82,9 +82,12 @@ namespace Crow
                protected override void onDraw (Cairo.Context gr)
                {
                        gr.Save ();
-                       //clip to client zone
-                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
-                       gr.Clip ();
+
+                       if (ClipToClientRect) {
+                               //clip to client zone
+                               CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
+                               gr.Clip ();
+                       }
 
                        if (child != null)
                                child.Paint (ref gr);