From 721fa8de23a9c56396c1df9f012682b7f65775fb Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sun, 14 Aug 2016 15:07:08 +0200 Subject: [PATCH] adjusting stroke position to have sharper lines, ClipToClientRect property --- Templates/GroupBox.template | 14 ++++++---- Tests/Interfaces/Divers/imlEditor.crow | 2 +- Tests/Interfaces/basicTests/0.crow | 6 ++-- src/Cairo/CairoHelpers.cs | 10 ++++--- src/ExtensionsMethods.cs | 8 ++++-- src/GraphicObjects/Border.cs | 19 +++++++------ src/GraphicObjects/GraphicObject.cs | 38 +++++++++++++++++--------- src/GraphicObjects/Group.cs | 10 +++++-- src/GraphicObjects/PrivateContainer.cs | 9 ++++-- src/GraphicObjects/Scroller.cs | 8 ++++-- src/GraphicObjects/TabItem.cs | 21 +++++++------- src/GraphicObjects/TabView.cs | 9 ++++-- src/GraphicObjects/TemplatedControl.cs | 9 ++++-- 13 files changed, 101 insertions(+), 62 deletions(-) diff --git a/Templates/GroupBox.template b/Templates/GroupBox.template index a373a29c..4e70ceae 100755 --- a/Templates/GroupBox.template +++ b/Templates/GroupBox.template @@ -1,12 +1,16 @@ - - - - \ No newline at end of file diff --git a/Tests/Interfaces/Divers/imlEditor.crow b/Tests/Interfaces/Divers/imlEditor.crow index bbad04ef..17e711a5 100644 --- a/Tests/Interfaces/Divers/imlEditor.crow +++ b/Tests/Interfaces/Divers/imlEditor.crow @@ -14,7 +14,7 @@ ValueChanged="./_scroller_ValueChanged"> diff --git a/Tests/Interfaces/basicTests/0.crow b/Tests/Interfaces/basicTests/0.crow index 50312cce..c41c1317 100755 --- a/Tests/Interfaces/basicTests/0.crow +++ b/Tests/Interfaces/basicTests/0.crow @@ -1,5 +1,7 @@ - - + + + \ No newline at end of file diff --git a/src/Cairo/CairoHelpers.cs b/src/Cairo/CairoHelpers.cs index 8f9e6325..b2b71f96 100644 --- a/src/Cairo/CairoHelpers.cs +++ b/src/Cairo/CairoHelpers.cs @@ -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); diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index 07c37174..d1b951b9 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -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); diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs index bd72d750..a6e5432b 100644 --- a/src/GraphicObjects/Border.cs +++ b/src/GraphicObjects/Border.cs @@ -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); diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index f8a1e508..d5c92011 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -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); } } + /// + /// When set to True, the 's width and height will be set to Fit. + /// + [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; } } - /// - /// When set to True, the 's width and height will be set to Fit. - /// - [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; } diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 3782640c..66f2f57e 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -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); diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index a6f52f29..5f70dd17 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -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); diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index c248595d..4b83b0cb 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -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) diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index c06a43a9..e14a7815 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -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); diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index fa352b0d..7f87fa11 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -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) diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index 4745b87b..b10d89eb 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -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); -- 2.47.3