Browse Source

Added support for path/geometry clipping and fix bug in Cairo StreamGeometryContextImpl.FillContains.

Jeremy Koritzinsky 9 years ago
parent
commit
8f96486b86

+ 1 - 1
src/Avalonia.SceneGraph/VisualTree/TransformedBounds.cs

@@ -49,7 +49,7 @@ namespace Avalonia.VisualTree
                 context.LineTo(Bounds.BottomRight * Transform);
                 context.LineTo(Bounds.BottomLeft * Transform);
                 context.LineTo(Bounds.TopLeft * Transform);
-                context.EndFigure(true);
+                context.EndFigure(false);
             }
             return geometry;
         }

+ 12 - 0
src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs

@@ -340,5 +340,17 @@ namespace Avalonia.Cairo.Media
 			
 			return SetBrush(pen.Brush, destinationSize);
         }
+
+        public void PushGeometryClip(Geometry clip)
+        {
+            _context.Save();
+            _context.AppendPath(((StreamGeometryImpl)clip.PlatformImpl).Path);
+            _context.Clip();
+        }
+
+        public void PopGeometryClip()
+        {
+            _context.Restore();
+        }
     }
 }

+ 5 - 1
src/Gtk/Avalonia.Cairo/Media/StreamGeometryContextImpl.cs

@@ -64,7 +64,11 @@ namespace Avalonia.Cairo.Media
 
         internal bool FillContains(Point point)
         {
-            return _context.InFill(point.X, point.Y);
+            using (var context = new Cairo.Context(new Cairo.ImageSurface(Cairo.Format.Argb32, 0, 0)))
+            {
+                context.AppendPath(Path);
+                return context.InFill(point.X, point.Y); 
+            }
         }
 
         public void LineTo(Point point)

+ 26 - 0
src/Windows/Avalonia.Direct2D1/Media/DrawingContext.cs

@@ -276,6 +276,11 @@ namespace Avalonia.Direct2D1.Media
         }
 
         public void PopOpacity()
+        {
+            PopLayer();
+        }
+
+        private void PopLayer()
         {
             var layer = _layers.Pop();
             if (layer != null)
@@ -324,5 +329,26 @@ namespace Avalonia.Direct2D1.Media
                 return new SolidColorBrushImpl((Avalonia.Media.SolidColorBrush)null, _renderTarget);
             }
         }
+
+        public void PushGeometryClip(Avalonia.Media.Geometry clip)
+        {
+            var parameters = new LayerParameters
+            {
+                ContentBounds = PrimitiveExtensions.RectangleInfinite,
+                MaskTransform = PrimitiveExtensions.Matrix3x2Identity,
+                Opacity = 1,
+                GeometricMask = ((GeometryImpl)clip.PlatformImpl).Geometry
+            };
+            var layer = _layerPool.Count != 0 ? _layerPool.Pop() : new Layer(_renderTarget);
+            _renderTarget.PushLayer(ref parameters, layer);
+
+            _layers.Push(layer);
+
+        }
+
+        public void PopGeometryClip()
+        {
+            PopLayer();
+        }
     }
 }