From: Jean-Philippe Bruyère Date: Tue, 2 Feb 2021 14:09:32 +0000 (+0100) Subject: save/restore ctx only if clipToClientRect=true, add some debuglog for draw() overrides X-Git-Tag: v0.9.5-beta~82 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=78ad0db46c706b098fa5037378d0f0f4d0f518f4;p=jp%2Fcrow.git save/restore ctx only if clipToClientRect=true, add some debuglog for draw() overrides --- diff --git a/Crow/Default.style b/Crow/Default.style index 0077a382..b99680b1 100644 --- a/Crow/Default.style +++ b/Crow/Default.style @@ -72,7 +72,8 @@ Button { Label { Height = "Fit"; Width = "Fit"; - Margin = "0"; + Margin = "0"; + ClipToClientRect = "false"; } OldLabel { Height = "Fit"; diff --git a/Crow/src/Widgets/ColorSlider.cs b/Crow/src/Widgets/ColorSlider.cs index a1b54d7c..f88558b6 100644 --- a/Crow/src/Widgets/ColorSlider.cs +++ b/Crow/src/Widgets/ColorSlider.cs @@ -132,6 +132,8 @@ namespace Crow } protected override void onDraw (Context gr) { + DbgLogger.StartEvent (DbgEvtType.GODraw, this); + base.onDraw (gr); RectangleD r = ClientRectangle; @@ -227,6 +229,8 @@ namespace Crow gr.SetSource (Colors.White); gr.LineWidth = 1.0; gr.Stroke (); + + DbgLogger.EndEvent (DbgEvtType.GODraw); } public override void OnLayoutChanges (LayoutingType layoutType) { base.OnLayoutChanges (layoutType); diff --git a/Crow/src/Widgets/Gauge.cs b/Crow/src/Widgets/Gauge.cs index 079866c2..5964da02 100644 --- a/Crow/src/Widgets/Gauge.cs +++ b/Crow/src/Widgets/Gauge.cs @@ -80,6 +80,8 @@ namespace Crow { #endregion protected override void onDraw (Context gr) { + DbgLogger.StartEvent (DbgEvtType.GODraw, this); + base.onDraw (gr); Rectangle cb = ClientRectangle; @@ -93,6 +95,8 @@ namespace Crow { Foreground.SetAsSource (IFace, gr, cb); CairoHelpers.CairoRectangle (gr, cb, CornerRadius); gr.Fill (); + + DbgLogger.EndEvent (DbgEvtType.GODraw); } } } diff --git a/Crow/src/Widgets/Group.cs b/Crow/src/Widgets/Group.cs index a861eaf2..57e45203 100644 --- a/Crow/src/Widgets/Group.cs +++ b/Crow/src/Widgets/Group.cs @@ -284,11 +284,12 @@ namespace Crow } protected override void onDraw (Context gr) { - base.onDraw (gr); + DbgLogger.StartEvent (DbgEvtType.GODraw, this); - gr.Save (); + base.onDraw (gr); if (ClipToClientRect) { + gr.Save (); //clip to client zone CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); gr.Clip (); @@ -300,7 +301,11 @@ namespace Crow Children[i].Paint (gr); childrenRWLock.ExitReadLock (); - gr.Restore (); + + if (ClipToClientRect) + gr.Restore (); + + DbgLogger.EndEvent (DbgEvtType.GODraw); } protected override void UpdateCache (Context ctx) { diff --git a/Crow/src/Widgets/Label.cs b/Crow/src/Widgets/Label.cs index 8dbb48ba..451e8016 100644 --- a/Crow/src/Widgets/Label.cs +++ b/Crow/src/Widgets/Label.cs @@ -403,11 +403,14 @@ namespace Crow gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize (Font.Size); gr.FontOptions = Interface.FontRenderingOptions; - gr.Antialias = Interface.Antialias; - - //gr.Save (); + gr.Antialias = Interface.Antialias; Rectangle cb = ClientRectangle; + if (ClipToClientRect) { + gr.Save (); + CairoHelpers.CairoRectangle (gr, cb, CornerRadius); + gr.Clip (); + } fe = gr.FontExtents; int lineHeight = (int)(fe.Ascent + fe.Descent); @@ -440,88 +443,82 @@ namespace Crow IFace.forceTextCursor = true; } - if (string.IsNullOrEmpty (_text)) { - //gr.Restore (); - return; - } - - Foreground.SetAsSource (IFace, gr); - - TextExtents extents; - Span bytes = stackalloc byte[128]; - int y = cb.Y; + if (!string.IsNullOrEmpty (_text)) { + Foreground.SetAsSource (IFace, gr); - for (int i = 0; i < lines.Count; i++) { - int encodedBytes = -1; - if (lines[i].Length > 0) { + TextExtents extents; + Span bytes = stackalloc byte[128]; + int y = cb.Y; - int size = lines[i].Length * 4 + 1; - if (bytes.Length < size) - bytes = size > 512 ? new byte[size] : stackalloc byte[size]; + for (int i = 0; i < lines.Count; i++) { + int encodedBytes = -1; + if (lines[i].Length > 0) { + int size = lines[i].Length * 4 + 1; + if (bytes.Length < size) + bytes = size > 512 ? new byte[size] : stackalloc byte[size]; - encodedBytes = Crow.Text.Encoding.ToUtf8 (_text.GetLine (lines[i]), bytes); - bytes[encodedBytes++] = 0; + encodedBytes = Crow.Text.Encoding.ToUtf8 (_text.GetLine (lines[i]), bytes); + bytes[encodedBytes++] = 0; - if (lines[i].LengthInPixel < 0) { - gr.TextExtents (bytes.Slice (0, encodedBytes), out extents); - lines.UpdateLineLengthInPixel (i, (int)extents.XAdvance); + if (lines[i].LengthInPixel < 0) { + gr.TextExtents (bytes.Slice (0, encodedBytes), out extents); + lines.UpdateLineLengthInPixel (i, (int)extents.XAdvance); + } } - } - Rectangle lineRect = new Rectangle ( - Width.IsFit && !Multiline ? cb.X : (int)getX (cb.Width, lines[i]) + cb.X, - y, - lines[i].LengthInPixel, - lineHeight); + Rectangle lineRect = new Rectangle ( + Width.IsFit && !Multiline ? cb.X : (int)getX (cb.Width, lines[i]) + cb.X, + y, lines[i].LengthInPixel, lineHeight); - if (encodedBytes > 0) { - gr.MoveTo (lineRect.X, lineRect.Y + fe.Ascent); - gr.ShowText (bytes.Slice (0, encodedBytes)); - } + if (encodedBytes > 0) { + gr.MoveTo (lineRect.X, lineRect.Y + fe.Ascent); + gr.ShowText (bytes.Slice (0, encodedBytes)); + } - if (HasFocus && selectionNotEmpty) { - Rectangle selRect = lineRect; - if (_multiline) { - if (i >= selStart.Line && i <= selEnd.Line) { - if (selStart.Line == selEnd.Line) { - selRect.X = (int)selStart.VisualCharXPosition + cb.X; - selRect.Width = (int)(selEnd.VisualCharXPosition - selStart.VisualCharXPosition); - } else if (i == selStart.Line) { - int newX = (int)selStart.VisualCharXPosition + cb.X; - selRect.Width -= (newX - selRect.X) - 10; - selRect.X = newX; - } else if (i == selEnd.Line) { - selRect.Width = (int)selEnd.VisualCharXPosition - selRect.X; - } else - selRect.Width += 10; + if (HasFocus && selectionNotEmpty) { + Rectangle selRect = lineRect; + if (_multiline) { + if (i >= selStart.Line && i <= selEnd.Line) { + if (selStart.Line == selEnd.Line) { + selRect.X = (int)selStart.VisualCharXPosition + cb.X; + selRect.Width = (int)(selEnd.VisualCharXPosition - selStart.VisualCharXPosition); + } else if (i == selStart.Line) { + int newX = (int)selStart.VisualCharXPosition + cb.X; + selRect.Width -= (newX - selRect.X) - 10; + selRect.X = newX; + } else if (i == selEnd.Line) { + selRect.Width = (int)selEnd.VisualCharXPosition - selRect.X; + } else + selRect.Width += 10; + } else { + y += lineHeight; + continue; + } } else { - y += lineHeight; - continue; + selRect.X = (int)selStart.VisualCharXPosition + cb.X; + selRect.Width = (int)(selEnd.VisualCharXPosition - selStart.VisualCharXPosition); } - } else { - selRect.X = (int)selStart.VisualCharXPosition + cb.X; - selRect.Width = (int)(selEnd.VisualCharXPosition - selStart.VisualCharXPosition); - } - gr.SetSource (selBackground); - gr.Rectangle (selRect); - if (encodedBytes < 0) - gr.Fill (); - else { - gr.FillPreserve (); - gr.Save (); - gr.Clip (); - gr.SetSource (SelectionForeground); - gr.MoveTo (lineRect.X, lineRect.Y + fe.Ascent); - gr.ShowText (bytes.Slice (0, encodedBytes)); - gr.Restore (); + gr.SetSource (selBackground); + gr.Rectangle (selRect); + if (encodedBytes < 0) + gr.Fill (); + else { + gr.FillPreserve (); + gr.Save (); + gr.Clip (); + gr.SetSource (SelectionForeground); + gr.MoveTo (lineRect.X, lineRect.Y + fe.Ascent); + gr.ShowText (bytes.Slice (0, encodedBytes)); + gr.Restore (); + } + Foreground.SetAsSource (IFace, gr); } - Foreground.SetAsSource (IFace, gr); + y += lineHeight; } - y += lineHeight; } - - //gr.Restore (); + if (ClipToClientRect) + gr.Restore (); } #endregion diff --git a/Crow/src/Widgets/PrivateContainer.cs b/Crow/src/Widgets/PrivateContainer.cs index 293323e4..b71b9c8d 100644 --- a/Crow/src/Widgets/PrivateContainer.cs +++ b/Crow/src/Widgets/PrivateContainer.cs @@ -182,11 +182,13 @@ namespace Crow } protected override void onDraw (Context gr) { + DbgLogger.StartEvent (DbgEvtType.GODraw, this); + base.onDraw (gr); - gr.Save (); if (ClipToClientRect) { + gr.Save (); //clip to client zone CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); gr.Clip (); @@ -196,7 +198,11 @@ namespace Crow if (child.Visible) child.Paint (gr); } - gr.Restore (); + + if (ClipToClientRect) + gr.Restore (); + + DbgLogger.EndEvent (DbgEvtType.GODraw); } protected override void UpdateCache (Context ctx) { diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index 255e1756..257bfac0 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -1737,10 +1737,8 @@ namespace Crow #region Rendering /// This is the common overridable drawing routine to create new widget protected virtual void onDraw(Context gr) - { - #if DEBUG_LOG + { DbgLogger.StartEvent(DbgEvtType.GODraw, this); - #endif Rectangle rBack = new Rectangle (Slot.Size); @@ -1748,9 +1746,7 @@ namespace Crow CairoHelpers.CairoRectangle (gr, rBack, cornerRadius); gr.Fill (); - #if DEBUG_LOG DbgLogger.EndEvent (DbgEvtType.GODraw); - #endif } ///