public ImmutableExperimentalAcrylicMaterial(IExperimentalAcrylicMaterial brush)
 {
     BackgroundSource = brush.BackgroundSource;
     TintColor        = brush.TintColor;
     TintOpacity      = brush.TintOpacity;
     FallbackColor    = brush.FallbackColor;
     MaterialColor    = brush.MaterialColor;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RectangleNode"/> class.
 /// </summary>
 /// <param name="transform">The transform.</param>
 /// <param name="material"></param>
 /// <param name="rect">The rectangle to draw.</param>
 public ExperimentalAcrylicNode(
     Matrix transform,
     IExperimentalAcrylicMaterial material,
     RoundedRect rect)
     : base(rect.Rect, transform)
 {
     Transform = transform;
     Material  = material.ToImmutable();
     Rect      = rect;
 }
        /// <inheritdoc/>
        public void DrawRectangle(IExperimentalAcrylicMaterial material, RoundedRect rect)
        {
            var next = NextDrawAs <ExperimentalAcrylicNode>();

            if (next == null || !next.Item.Equals(Transform, material, rect))
            {
                Add(new ExperimentalAcrylicNode(Transform, material, rect));
            }
            else
            {
                ++_drawOperationindex;
            }
        }
Пример #4
0
        internal PaintWrapper CreateAcrylicPaint(SKPaint paint, IExperimentalAcrylicMaterial material, bool disposePaint = false)
        {
            var paintWrapper = new PaintWrapper(paint, disposePaint);

            paint.IsAntialias = true;

            double opacity = _currentOpacity;

            var tintOpacity =
                material.BackgroundSource == AcrylicBackgroundSource.Digger ?
                material.TintOpacity : 1;

            const double noiseOpcity = 0.0225;

            var tintColor = material.TintColor;
            var tint      = new SKColor(tintColor.R, tintColor.G, tintColor.B, tintColor.A);

            if (s_acrylicNoiseShader == null)
            {
                using (var stream = typeof(DrawingContextImpl).Assembly.GetManifestResourceStream("Avalonia.Skia.Assets.NoiseAsset_256X256_PNG.png"))
                    using (var bitmap = SKBitmap.Decode(stream))
                    {
                        s_acrylicNoiseShader = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat)
                                               .WithColorFilter(CreateAlphaColorFilter(noiseOpcity));
                    }
            }

            using (var backdrop = SKShader.CreateColor(new SKColor(material.MaterialColor.R, material.MaterialColor.G, material.MaterialColor.B, material.MaterialColor.A)))
                using (var tintShader = SKShader.CreateColor(tint))
                    using (var effectiveTint = SKShader.CreateCompose(backdrop, tintShader))
                        using (var compose = SKShader.CreateCompose(effectiveTint, s_acrylicNoiseShader))
                        {
                            paint.Shader = compose;

                            if (material.BackgroundSource == AcrylicBackgroundSource.Digger)
                            {
                                paint.BlendMode = SKBlendMode.Src;
                            }

                            return(paintWrapper);
                        }
        }
Пример #5
0
        /// <inheritdoc />
        public void DrawRectangle(IExperimentalAcrylicMaterial material, RoundedRect rect)
        {
            if (rect.Rect.Height <= 0 || rect.Rect.Width <= 0)
            {
                return;
            }
            CheckLease();

            var rc            = rect.Rect.ToSKRect();
            var isRounded     = rect.IsRounded;
            var needRoundRect = rect.IsRounded;

            using var skRoundRect = needRoundRect ? new SKRoundRect() : null;

            if (needRoundRect)
            {
                skRoundRect.SetRectRadii(rc,
                                         new[]
                {
                    rect.RadiiTopLeft.ToSKPoint(), rect.RadiiTopRight.ToSKPoint(),
                    rect.RadiiBottomRight.ToSKPoint(), rect.RadiiBottomLeft.ToSKPoint(),
                });
            }

            if (material != null)
            {
                using (var paint = CreateAcrylicPaint(_fillPaint, material))
                {
                    if (isRounded)
                    {
                        Canvas.DrawRoundRect(skRoundRect, paint.Paint);
                    }
                    else
                    {
                        Canvas.DrawRect(rc, paint.Paint);
                    }
                }
            }
        }
 /// <summary>
 /// Determines if this draw operation equals another.
 /// </summary>
 /// <param name="transform">The transform of the other draw operation.</param>
 /// <param name="material">The fill of the other draw operation.</param>
 /// <param name="rect">The rectangle 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(Matrix transform, IExperimentalAcrylicMaterial material, RoundedRect rect)
 {
     return(transform == Transform &&
            Equals(material, Material) &&
            rect.Equals(Rect));
 }
        /// <summary>
        /// Converts a brush to an immutable brush.
        /// </summary>
        /// <param name="material">The brush.</param>
        /// <returns>
        /// The result of calling <see cref="IMutableBrush.ToImmutable"/> if the brush is mutable,
        /// otherwise <paramref name="material"/>.
        /// </returns>
        public static IExperimentalAcrylicMaterial ToImmutable(this IExperimentalAcrylicMaterial material)
        {
            Contract.Requires <ArgumentNullException>(material != null);

            return((material as IMutableExperimentalAcrylicMaterial)?.ToImmutable() ?? material);
        }
Пример #8
0
        /// <summary>
        /// Converts a brush to an immutable brush.
        /// </summary>
        /// <param name="material">The brush.</param>
        /// <returns>
        /// The result of calling <see cref="IMutableBrush.ToImmutable"/> if the brush is mutable,
        /// otherwise <paramref name="material"/>.
        /// </returns>
        public static IExperimentalAcrylicMaterial ToImmutable(this IExperimentalAcrylicMaterial material)
        {
            _ = material ?? throw new ArgumentNullException(nameof(material));

            return((material as IMutableExperimentalAcrylicMaterial)?.ToImmutable() ?? material);
        }