]> O.S.I.I.S - jp/crow.git/commitdiff
save/restore ctx only if clipToClientRect=true, add some debuglog for draw() overrides
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 2 Feb 2021 14:09:32 +0000 (15:09 +0100)
committerj-p <jp_bruyere@hotmail.com>
Sat, 6 Feb 2021 19:28:02 +0000 (20:28 +0100)
Crow/Default.style
Crow/src/Widgets/ColorSlider.cs
Crow/src/Widgets/Gauge.cs
Crow/src/Widgets/Group.cs
Crow/src/Widgets/Label.cs
Crow/src/Widgets/PrivateContainer.cs
Crow/src/Widgets/Widget.cs

index 0077a382bb31b385d34af779749fe4b13414fc5b..b99680b1821cdf13de3a76f311662c9fff48789e 100644 (file)
@@ -72,7 +72,8 @@ Button {
 Label {
        Height = "Fit";
        Width = "Fit";
-       Margin = "0";   
+       Margin = "0";
+       ClipToClientRect = "false";
 }
 OldLabel {
        Height = "Fit";
index a1b54d7c85eefecb7085457ae68131f7f9e78a36..f88558b6faa73370f9de900f8b6aff1f52916a35 100644 (file)
@@ -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);
index 079866c25f17a25f79909c6e5d3ac519cf4cec25..5964da02c0d5a1c8bd9f40ec1e570d6f504022c9 100644 (file)
@@ -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);
                }
        }
 }
index a861eaf2d8efd207cf1cc3e375168d1c18e848df..57e452031b07cc0edd8235ea620432fc362d7c94 100644 (file)
@@ -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)
                {
index 8dbb48bac97df0ddd0a75c978e3d47171683ffd6..451e80164c0884a9ad72d609238f82e730774ed7 100644 (file)
@@ -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<byte> 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<byte> 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
 
index 293323e44308b571695fc4641e9e3d99aacace53..b71b9c8dd074b148f208eb0b381e672c6e58e199 100644 (file)
@@ -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)
                {
index 255e17563bc24a42fc8776ce79753ad5c9939968..257bfac07003f5ac59d3cb26d9a7016aed4de8b4 100644 (file)
@@ -1737,10 +1737,8 @@ namespace Crow
                #region Rendering
                /// <summary> This is the common overridable drawing routine to create new widget </summary>
                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
                }
 
                /// <summary>