Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ToolBlurControl.axaml.cs « Tools « Controls « UVtools.WPF - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 88058ec8819f463496051bd5a7fe2caaafb04365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using UVtools.Core.Operations;

namespace UVtools.WPF.Controls.Tools
{
    public class ToolBlurControl : ToolControl
    {
        private int _selectedAlgorithmIndex;
        private bool _isSizeEnabled = true;
        private bool _isKernelVisible;
        private KernelControl _kernelCtrl;
        public OperationBlur Operation => BaseOperation as OperationBlur;

        public int SelectedAlgorithmIndex
        {
            get => _selectedAlgorithmIndex;
            set
            {
                if(!RaiseAndSetIfChanged(ref _selectedAlgorithmIndex, value) || value < 0) return;
                Operation.BlurOperation = (OperationBlur.BlurAlgorithm) OperationBlur.BlurTypes[_selectedAlgorithmIndex].Tag;
                IsKernelVisible = Operation.BlurOperation == OperationBlur.BlurAlgorithm.Filter2D;
                IsSizeEnabled = Operation.BlurOperation != OperationBlur.BlurAlgorithm.Pyramid &&
                                Operation.BlurOperation != OperationBlur.BlurAlgorithm.Filter2D;
            }
        }

        public bool IsSizeEnabled
        {
            get => _isSizeEnabled;
            set => RaiseAndSetIfChanged(ref _isSizeEnabled, value);
        }

        public bool IsKernelVisible
        {
            get => _isKernelVisible;
            set => RaiseAndSetIfChanged(ref _isKernelVisible, value);
        }

        public ToolBlurControl()
        {
            InitializeComponent();
            BaseOperation = new OperationBlur();
            _kernelCtrl = this.Find<KernelControl>("KernelCtrl");
        }

        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);
        }

        public override bool UpdateOperation()
        {
            Operation.Kernel.Matrix = _kernelCtrl.GetMatrix();
            Operation.Kernel.Anchor = _kernelCtrl.Anchor;
            return !(Operation.Kernel.Matrix is null);
        }
    }
}