浏览代码

Adjusted expected test output.

The output images were off-center.
Steven Kirk 8 年之前
父节点
当前提交
d6342e906a

+ 64 - 0
src/Avalonia.Visuals/Rendering/SceneGraph/ClipNode.cs

@@ -0,0 +1,64 @@
+using System;
+using Avalonia.Platform;
+
+namespace Avalonia.Rendering.SceneGraph
+{
+    /// <summary>
+    /// A node in the scene graph which represents a clip push or pop.
+    /// </summary>
+    internal class ClipNode : IDrawOperation
+    {
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ClipNode"/> class that represents an
+        /// clip push.
+        /// </summary>
+        /// <param name="clip">The clip to push.</param>
+        public ClipNode(Rect clip)
+        {
+            Clip = clip;
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ClipNode"/> class that represents an
+        /// opacity pop.
+        /// </summary>
+        public ClipNode()
+        {
+        }
+
+        /// <inheritdoc/>
+        public Rect Bounds => Rect.Empty;
+
+        /// <summary>
+        /// Gets the opacity to be pushed or null if the operation represents a pop.
+        /// </summary>
+        public Rect? Clip { get; }
+
+        /// <inheritdoc/>
+        public bool HitTest(Point p) => false;
+
+        /// <summary>
+        /// Determines if this draw operation equals another.
+        /// </summary>
+        /// <param name="clip">The clip of the other draw operation.</param>
+        /// <returns>True if the draw operations are the same, otherwise false.</returns>
+        /// <remarks>
+        /// The properties of the other draw operation are passed in as arguments to prevent
+        /// allocation of a not-yet-constructed draw operation object.
+        /// </remarks>
+        public bool Equals(Rect? clip) => Clip == clip;
+
+        /// <inheritdoc/>
+        public void Render(IDrawingContextImpl context)
+        {
+            if (Clip.HasValue)
+            {
+                context.PushClip(Clip.Value);
+            }
+            else
+            {
+                context.PopClip();
+            }
+        }
+    }
+}

+ 20 - 2
src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs

@@ -196,7 +196,16 @@ namespace Avalonia.Rendering.SceneGraph
         /// <inheritdoc/>
         public void PopClip()
         {
-            // TODO: Implement
+            var next = NextDrawAs<ClipNode>();
+
+            if (next == null || !next.Equals(null))
+            {
+                Add(new ClipNode());
+            }
+            else
+            {
+                ++_drawOperationindex;
+            }
         }
 
         /// <inheritdoc/>
@@ -229,7 +238,16 @@ namespace Avalonia.Rendering.SceneGraph
         /// <inheritdoc/>
         public void PushClip(Rect clip)
         {
-            // TODO: Implement
+            var next = NextDrawAs<ClipNode>();
+
+            if (next == null || !next.Equals(clip))
+            {
+                Add(new ClipNode(clip));
+            }
+            else
+            {
+                ++_drawOperationindex;
+            }
         }
 
         /// <inheritdoc/>

+ 5 - 5
tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs

@@ -35,14 +35,14 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
                 {
                     context.FillRectangle(
                         Brushes.Red,
-                        control.Bounds,
+                        new Rect(control.Bounds.Size),
                         4);
 
-                    using (context.PushClip(control.Bounds.Deflate(20)))
+                    using (context.PushClip(new Rect(control.Bounds.Size).Deflate(20)))
                     {
                         context.FillRectangle(
                             Brushes.Blue,
-                            control.Bounds,
+                            new Rect(control.Bounds.Size),
                             4);
                     }
                 }),
@@ -64,14 +64,14 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
                 {
                     context.FillRectangle(
                         Brushes.Red,
-                        control.Bounds,
+                        new Rect(control.Bounds.Size),
                         4);
 
                     using (context.PushOpacity(0.5))
                     {
                         context.FillRectangle(
                             Brushes.Blue,
-                            control.Bounds.Deflate(20),
+                            new Rect(control.Bounds.Size).Deflate(20),
                             4);
                     }
                 }),

二进制
tests/TestFiles/Cairo/Controls/CustomRender/Clip.expected.png


二进制
tests/TestFiles/Cairo/Controls/CustomRender/Opacity.expected.png


二进制
tests/TestFiles/Direct2D1/Controls/CustomRender/Clip.expected.png


二进制
tests/TestFiles/Direct2D1/Controls/CustomRender/Opacity.expected.png


二进制
tests/TestFiles/Skia/Controls/CustomRender/Clip.expected.png


二进制
tests/TestFiles/Skia/Controls/CustomRender/Opacity.expected.png