Exemplo n.º 1
0
        public void SetClip(RectangleF rect)
        {
            ResetClip();
            clipBounds = rect;
            var parameters = new sd.LayerParameters
            {
                ContentBounds     = clipBounds.ToDx(),
                GeometricMask     = new sd.RectangleGeometry(SDFactory.D2D1Factory, rect.ToDx()),
                MaskAntialiasMode = Control.AntialiasMode,
                MaskTransform     = s.Matrix3x2.Identity,
                Opacity           = 1f
            };

            clipLayer = new sd.Layer(Control);
            Control.PushLayer(ref parameters, clipLayer);
        }
Exemplo n.º 2
0
        public void SetClip(IGraphicsPath path)
        {
            ResetClip();
            clipBounds = path.Bounds;
            var parameters = new sd.LayerParameters
            {
                ContentBounds     = clipBounds.ToDx(),
                GeometricMask     = path.ToGeometry(),
                MaskAntialiasMode = Control.AntialiasMode,
                MaskTransform     = s.Matrix3x2.Identity,
                Opacity           = 1f
            };

            clipLayer = new sd.Layer(Control);
            Control.PushLayer(ref parameters, clipLayer);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates and pushes a D2D layer if necessary. Returns the layer or null if not required.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="renderTarget">The render target.</param>
        /// <param name="rootElement"></param>
        /// <returns></returns>
        public static D2D.Layer CreateAndPushLayerIfNecessary(this Jupiter.FrameworkElement element, D2D.RenderTarget renderTarget, Jupiter.FrameworkElement rootElement)
        {
            if (element.Opacity >= 1)
                //element.Clip == null &&
                //element.RenderTransform == null)
            {
                return null;
            }

            var layer = new D2D.Layer(renderTarget);
            var layerParameters = new D2D.LayerParameters();
            layerParameters.Opacity = (float)element.Opacity;
            layerParameters.ContentBounds = element.GetBoundingRect(rootElement).ToSharpDX();
            renderTarget.PushLayer(ref layerParameters, layer);

            return layer;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates and pushes a D2D layer if necessary. Returns the layer or null if not required.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="renderTarget">The render target.</param>
        /// <param name="rootElement"></param>
        /// <returns></returns>
        public static D2D.Layer CreateAndPushLayerIfNecessary(this Jupiter.FrameworkElement element, D2D.RenderTarget renderTarget, Jupiter.FrameworkElement rootElement)
        {
            if (element.Opacity >= 1)
            //element.Clip == null &&
            //element.RenderTransform == null)
            {
                return(null);
            }

            var layer           = new D2D.Layer(renderTarget);
            var layerParameters = new D2D.LayerParameters();

            layerParameters.Opacity       = (float)element.Opacity;
            layerParameters.ContentBounds = element.GetBoundingRect(rootElement).ToSharpDX();
            renderTarget.PushLayer(ref layerParameters, layer);

            return(layer);
        }
Exemplo n.º 5
0
        public static void PushLayer(
            this D2D1.RenderTarget target,
            DXM.RawRectangleF clipBounds,
            D2D1.Geometry geometryPath,
            float opacity)
        {
            var layerParameters = new D2D1.LayerParameters()
            {
                GeometricMask = geometryPath,
                MaskTransform = Identity,
                ContentBounds = clipBounds,
                LayerOptions  = D2D1.LayerOptions.None,
                Opacity       = opacity,
                OpacityBrush  = null
            };

            target.PushLayer(ref layerParameters, null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Pushes an opacity value.
        /// </summary>
        /// <param name="opacity">The opacity.</param>
        /// <returns>A disposable used to undo the opacity.</returns>
        public IDisposable PushOpacity(double opacity)
        {
            if (opacity < 1)
            {
                var parameters = new LayerParameters
                {
                    ContentBounds = RectangleF.Infinite,
                    MaskTransform = Matrix3x2.Identity,
                    Opacity = (float)opacity,
                };

                var layer = new Layer(this.renderTarget);

                this.renderTarget.PushLayer(ref parameters, layer);

                return Disposable.Create(() =>
                {
                    this.renderTarget.PopLayer();
                });
            }
            else
            {
                return Disposable.Empty;
            }
        }
Exemplo n.º 7
0
        public void PushOpacityMask(IBrush mask, Rect bounds)
        {
            var parameters = new LayerParameters
            {
                ContentBounds = PrimitiveExtensions.RectangleInfinite,
                MaskTransform = PrimitiveExtensions.Matrix3x2Identity,
                Opacity = 1,
                OpacityBrush = CreateBrush(mask, bounds.Size).PlatformBrush
            };
            var layer = _layerPool.Count != 0 ? _layerPool.Pop() : new Layer(_renderTarget);
            _renderTarget.PushLayer(ref parameters, layer);

            _layers.Push(layer);
        }
Exemplo n.º 8
0
        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);

        }
Exemplo n.º 9
0
        /// <summary>
        /// Pushes an opacity value.
        /// </summary>
        /// <param name="opacity">The opacity.</param>
        /// <returns>A disposable used to undo the opacity.</returns>
        public void PushOpacity(double opacity)
        {
            if (opacity < 1)
            {
                var parameters = new LayerParameters
                {
                    ContentBounds = PrimitiveExtensions.RectangleInfinite,
                    MaskTransform = PrimitiveExtensions.Matrix3x2Identity,
                    Opacity = (float) opacity,
                };

                var layer = _layerPool.Count != 0 ? _layerPool.Pop() : new Layer(_renderTarget);
                _renderTarget.PushLayer(ref parameters, layer);

                _layers.Push(layer);
            }
            else
                _layers.Push(null);
        }
Exemplo n.º 10
0
        public void Clear(SolidBrush brush)
        {
            if (Control != null)
            {
                var color = brush != null ? brush.Color : Colors.Transparent;
                // drawing to an image, so we can clear to transparent
                if (image != null)
                {
                    if (clipParams != null)
                    {
                        // can't clear the current layer otherwise it will not be applied to main layer
                        // This creates a copy of the current context, inverses the current clip, and draws the image back clipping
                        // the cleared path.

                        // end clip layer and current drawing session
                        Control.PopLayer();
                        Control.EndDraw();

                        // create a copy of the current state
                        var copy = image.Clone();
                        var bmp  = copy.ToDx(Control);

                        Control.BeginDraw();

                        // clear existing contents
                        Control.Clear(null);
                        var size = Control.Size;

                        // create an inverse geometry
                        var inverse = new sd.PathGeometry(SDFactory.D2D1Factory);
                        var sink    = inverse.Open();
                        var bounds  = new s.RectangleF(0, 0, size.Width, size.Height);
                        var geom    = new sd.RectangleGeometry(SDFactory.D2D1Factory, bounds);
                        geom.Combine(clipGeometry, sd.CombineMode.Exclude, sink);
                        sink.Close();

                        // create a new mask layer with inverse geometry
                        var parameters = new sd.LayerParameters
                        {
                            ContentBounds     = bounds,
                            GeometricMask     = inverse,
                            MaskAntialiasMode = Control.AntialiasMode,
                            MaskTransform     = s.Matrix3x2.Identity,
                            Opacity           = 1f
                        };
                        Control.PushLayer(ref parameters, HelperLayer);

                        // draw bitmap of contents back, clipping to the inverse of the clip region
                        Control.DrawBitmap(bmp, 1f, sd.BitmapInterpolationMode.NearestNeighbor);
                        Control.PopLayer();

                        // restore our clip path
                        parameters = clipParams.Value;
                        Control.PushLayer(ref parameters, HelperLayer);

                        copy.Dispose();
                    }
                }
                else
                {
                    // alpha is not supported on a drawable, so blend with black as the base color.
                    color = Color.Blend(Colors.Black, color);
                }

                Control.Clear(color.ToDx());
            }
        }
Exemplo n.º 11
0
 public override void PushOpacity(double opacity)
 {
     Layer layer = new Layer(this.target);
     LayerParameters p = new LayerParameters();
     p.Opacity = (float)opacity;
     this.target.PushLayer(ref p, layer);
     this.stack.Push(layer);
 }