<commit_before>﻿using Avalonia.Controls.Utils;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Platform;
using System;

namespace Avalonia.Controls
{
    public class ExperimentalAcrylicBorder : Decorator
    {
        public static readonly StyledProperty<CornerRadius> CornerRadiusProperty =
            Border.CornerRadiusProperty.AddOwner<ExperimentalAcrylicBorder>();

        public static readonly StyledProperty<ExperimentalAcrylicMaterial> MaterialProperty =
            AvaloniaProperty.Register<ExperimentalAcrylicBorder, ExperimentalAcrylicMaterial>(nameof(Material));

        private readonly BorderRenderHelper _borderRenderHelper = new BorderRenderHelper();

        static ExperimentalAcrylicBorder()
        {
            AffectsRender<ExperimentalAcrylicBorder>(
                MaterialProperty,
                CornerRadiusProperty);
        }


        /// <summary>
        /// Gets or sets the radius of the border rounded corners.
        /// </summary>
        public CornerRadius CornerRadius
        {
            get { return GetValue(CornerRadiusProperty); }
            set { SetValue(CornerRadiusProperty, value); }
        }

        public ExperimentalAcrylicMaterial Material
        {
            get => GetValue(MaterialProperty);
            set => SetValue(MaterialProperty, value);
        }

        protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
        {
            base.OnAttachedToVisualTree(e);

            var tl = (e.Root as TopLevel);

            tl.GetObservable(TopLevel.ActualTransparencyLevelProperty)
                .Subscribe(x =>
                {
                    switch (x)
                    {
                        case WindowTransparencyLevel.Transparent:
                        case WindowTransparencyLevel.None:
                            Material.PlatformTransparencyCompensationLevel = 1;
                            break;

                        case WindowTransparencyLevel.Blur:
                            Material.PlatformTransparencyCompensationLevel = 0.90;
                            break;

                        case WindowTransparencyLevel.AcrylicBlur:
                            Material.PlatformTransparencyCompensationLevel = 0.70;
                            break;
                    }
                });
        }

        protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
        {
            base.OnDetachedFromVisualTree(e);
        }


        public override void Render(DrawingContext context)
        {
            if(context.PlatformImpl is IDrawingContextWithAcrylicLikeSupport idc)
            {
                var cornerRadius = CornerRadius;

                idc.DrawRectangle(
                    Material, 
                    new RoundedRect(
                        new Rect(Bounds.Size), 
                        cornerRadius.TopLeft, cornerRadius.TopRight,
                        cornerRadius.BottomRight, cornerRadius.BottomLeft));
            }<commit_msg>transparency level ajustments.<commit_after>﻿using Avalonia.Controls.Utils;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Platform;
using System;

namespace Avalonia.Controls
{
    public class ExperimentalAcrylicBorder : Decorator
    {
        public static readonly StyledProperty<CornerRadius> CornerRadiusProperty =
            Border.CornerRadiusProperty.AddOwner<ExperimentalAcrylicBorder>();

        public static readonly StyledProperty<ExperimentalAcrylicMaterial> MaterialProperty =
            AvaloniaProperty.Register<ExperimentalAcrylicBorder, ExperimentalAcrylicMaterial>(nameof(Material));

        private readonly BorderRenderHelper _borderRenderHelper = new BorderRenderHelper();

        static ExperimentalAcrylicBorder()
        {
            AffectsRender<ExperimentalAcrylicBorder>(
                MaterialProperty,
                CornerRadiusProperty);
        }


        /// <summary>
        /// Gets or sets the radius of the border rounded corners.
        /// </summary>
        public CornerRadius CornerRadius
        {
            get { return GetValue(CornerRadiusProperty); }
            set { SetValue(CornerRadiusProperty, value); }
        }

        public ExperimentalAcrylicMaterial Material
        {
            get => GetValue(MaterialProperty);
            set => SetValue(MaterialProperty, value);
        }

        protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
        {
            base.OnAttachedToVisualTree(e);

            var tl = (e.Root as TopLevel);

            tl.GetObservable(TopLevel.ActualTransparencyLevelProperty)
                .Subscribe(x =>
                {
                    switch (x)
                    {
                        case WindowTransparencyLevel.Transparent:
                        case WindowTransparencyLevel.None:
                            Material.PlatformTransparencyCompensationLevel = 1;
                            break;

                        case WindowTransparencyLevel.Blur:
                            Material.PlatformTransparencyCompensationLevel = 0.80;
                            break;

                        case WindowTransparencyLevel.AcrylicBlur:
                            Material.PlatformTransparencyCompensationLevel = 0.0;
                            break;
                    }
                });
        }

        protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
        {
            base.OnDetachedFromVisualTree(e);
        }


        public override void Render(DrawingContext context)
        {
            if(context.PlatformImpl is IDrawingContextWithAcrylicLikeSupport idc)
            {
                var cornerRadius = CornerRadius;

                idc.DrawRectangle(
                    Material, 
                    new RoundedRect(
                        new Rect(Bounds.Size), 
                        cornerRadius.TopLeft, cornerRadius.TopRight,
                        cornerRadius.BottomRight, cornerRadius.BottomLeft));
            }
{'fraction_non_alphanumeric': 0.05952380952380952, 'fraction_numerical': 0.0021200260926288322, 'mean_word_length': 1.6993838028169015, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7552291', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1328, 'n_words': 260}