Переглянути джерело

Reimplemented Driver.FillRect to directly use Contnets vs calling Move/AddRune

Tig 1 рік тому
батько
коміт
de1a844787

+ 1 - 1
Terminal.Gui/Application.cs

@@ -882,7 +882,7 @@ public static partial class Application
         }
         else
         {
-            Driver.UpdateCursor ();
+            //Driver.UpdateCursor ();
         }
 
         if (state.Toplevel != Top && !state.Toplevel.Modal && (Top.NeedsDisplay || Top.SubViewNeedsDisplay || Top.LayoutNeeded))

+ 25 - 21
Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

@@ -314,28 +314,23 @@ public abstract class ConsoleDriver
         // TODO: This method is really "Clear Contents" now and should not be abstract (or virtual)
         Contents = new Cell [Rows, Cols];
         //CONCURRENCY: Unsynchronized access to Clip isn't safe.
-        Clip = new (0, 0, Cols, Rows);
+        // TODO: ClearContents should not clear the clip; it should only clear the contents. Move clearing it elsewhere.
+        Clip = Screen;
         _dirtyLines = new bool [Rows];
 
         lock (Contents)
         {
-            // Can raise an exception while is still resizing.
-            try
+            for (var row = 0; row < Rows; row++)
             {
-                for (var row = 0; row < Rows; row++)
+                for (var c = 0; c < Cols; c++)
                 {
-                    for (var c = 0; c < Cols; c++)
+                    Contents [row, c] = new Cell
                     {
-                        Contents [row, c] = new Cell
-                        {
-                            Rune = (Rune)' ', Attribute = new Attribute (Color.White, Color.Black), IsDirty = true
-                        };
-                        _dirtyLines [row] = true;
-                    }
+                        Rune = (Rune)' ', Attribute = new Attribute (Color.White, Color.Black), IsDirty = true
+                    };
+                    _dirtyLines [row] = true;
                 }
             }
-            catch (IndexOutOfRangeException)
-            { }
         }
     }
 
@@ -343,18 +338,27 @@ public abstract class ConsoleDriver
     /// <returns><see langword="true"/> upon success</returns>
     public abstract bool EnsureCursorVisibility ();
 
-    // TODO: Move FillRect to ./Drawing	
-    /// <summary>Fills the specified rectangle with the specified rune.</summary>
-    /// <param name="rect"></param>
-    /// <param name="rune"></param>
+    /// <summary>Fills the specified rectangle with the specified rune, using <see cref="CurrentAttribute"/></summary>
+    /// <remarks>
+    /// The value of <see cref="Clip"/> is honored. Any parts of the rectangle not in the clip will not be drawn.
+    /// </remarks>
+    /// <param name="rect">The Screen-relative rectangle.</param>
+    /// <param name="rune">The Rune used to fill the rectangle</param>
     public void FillRect (Rectangle rect, Rune rune = default)
     {
-        for (int r = rect.Y; r < rect.Y + rect.Height; r++)
+        rect = Rectangle.Intersect (rect, Clip);
+        lock (Contents)
         {
-            for (int c = rect.X; c < rect.X + rect.Width; c++)
+            for (int r = rect.Y; r < rect.Y + rect.Height; r++)
             {
-                Move (c, r);
-                AddRune (rune == default (Rune) ? new Rune (' ') : rune);
+                for (int c = rect.X; c < rect.X + rect.Width; c++)
+                {
+                    Contents [r, c] = new Cell
+                    {
+                        Rune = (Rune)' ', Attribute = CurrentAttribute, IsDirty = true
+                    };
+                    _dirtyLines [r] = true;
+                }
             }
         }
     }

+ 14 - 5
UICatalog/Scenarios/Scrolling.cs

@@ -24,6 +24,7 @@ public class Scrolling : Scenario
             Y = 3,
             Width = Dim.Fill (3),
             Height = Dim.Fill (3),
+            BorderStyle = LineStyle.None
         };
 
         var label = new Label { X = 0, Y = 0 };
@@ -37,13 +38,13 @@ public class Scrolling : Scenario
             Width = 60,
             Height = 20,
             ColorScheme = Colors.ColorSchemes ["TopLevel"],
-            ContentSize = new (200, 100),
+            ContentSize = new (120, 40),
 
             //ContentOffset = Point.Empty,
             ShowVerticalScrollIndicator = true,
             ShowHorizontalScrollIndicator = true
         };
-        scrollView.Padding.Thickness = new (1);
+       // scrollView.Padding.Thickness = new (1);
 
         label.Text = $"{scrollView}\nContentSize: {scrollView.ContentSize}\nContentOffset: {scrollView.ContentOffset}";
 
@@ -58,6 +59,7 @@ public class Scrolling : Scenario
             Height = 2,
             ColorScheme = Colors.ColorSchemes ["Error"]
         };
+        horizontalRuler.Visible = false;
         scrollView.Add (horizontalRuler);
 
         const string vrule = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
@@ -71,9 +73,11 @@ public class Scrolling : Scenario
             Height = Dim.Fill (),
             ColorScheme = Colors.ColorSchemes ["Error"]
         };
+        horizontalRuler.Visible = false;
         scrollView.Add (verticalRuler);
 
         var pressMeButton = new Button { X = 3, Y = 3, Text = "Press me!" };
+        pressMeButton.Visible = false;
         pressMeButton.Accept += (s, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
         scrollView.Add (pressMeButton);
 
@@ -85,6 +89,7 @@ public class Scrolling : Scenario
             Width = Dim.Fill (3),
             Text = "A very long button. Should be wide enough to demo clipping!"
         };
+        aLongButton.Visible = false;
         aLongButton.Accept += (s, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
         scrollView.Add (aLongButton);
 
@@ -95,7 +100,8 @@ public class Scrolling : Scenario
                             Y = 5,
                             Width = 50,
                             ColorScheme = Colors.ColorSchemes ["Dialog"],
-                            Text = "This is a test of..."
+                            Text = "This is a test of...",
+                            //Visible = false
                         }
                        );
 
@@ -106,7 +112,8 @@ public class Scrolling : Scenario
                             Y = 10,
                             Width = 50,
                             ColorScheme = Colors.ColorSchemes ["Dialog"],
-                            Text = "... the emergency broadcast system."
+                            Text = "... the emergency broadcast system.",
+                            Visible = false
                         }
                        );
 
@@ -117,7 +124,8 @@ public class Scrolling : Scenario
                             Y = 99,
                             Width = 50,
                             ColorScheme = Colors.ColorSchemes ["Dialog"],
-                            Text = "Last line"
+                            Text = "Last line",
+                            Visible = false
                         }
                        );
 
@@ -223,6 +231,7 @@ public class Scrolling : Scenario
 
         // Add a progress bar to cause constant redraws
         var progress = new ProgressBar { X = Pos.Right (scrollView) + 1, Y = Pos.AnchorEnd (2), Width = 50 };
+
         app.Add (progress);
 
         var pulsing = true;