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

ToolThresholdControl.axaml.cs « Tools « Controls « UVtools.WPF - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4287b3b62f7f2f132b8d7aabb931a864bd5dc847 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using Avalonia.Markup.Xaml;
using Emgu.CV.CvEnum;
using UVtools.Core.Operations;

namespace UVtools.WPF.Controls.Tools
{
    public class ToolThresholdControl : ToolControl
    {
        private int _selectedPresetIndex;
        private bool _isThresholdEnabled = true;
        private bool _isMaximumEnabled = true;
        private bool _isTypeEnabled = true;
        public OperationThreshold Operation => BaseOperation as OperationThreshold;

        public string[] Presets => new[]
        {
            "Free use",
            "Strip AntiAliasing",
            "Set pixel brightness"
        };

        public bool IsThresholdEnabled
        {
            get => _isThresholdEnabled;
            set => RaiseAndSetIfChanged(ref _isThresholdEnabled, value);
        }

        public bool IsMaximumEnabled
        {
            get => _isMaximumEnabled;
            set => RaiseAndSetIfChanged(ref _isMaximumEnabled, value);
        }

        public bool IsTypeEnabled
        {
            get => _isTypeEnabled;
            set => RaiseAndSetIfChanged(ref _isTypeEnabled, value);
        }

        public int SelectedPresetIndex
        {
            get => _selectedPresetIndex;
            set
            {
                if (!RaiseAndSetIfChanged(ref _selectedPresetIndex, value)) return;

                switch (_selectedPresetIndex)
                {
                    case 0:
                        IsThresholdEnabled = true;
                        IsMaximumEnabled = true;
                        IsTypeEnabled = true;
                        break;
                    case 1:
                        IsThresholdEnabled = true;
                        IsMaximumEnabled = false;
                        IsTypeEnabled = false;
                        Operation.Threshold = 127;
                        Operation.Maximum = 255;
                        Operation.Type = ThresholdType.Binary;
                        break;
                    case 2:
                        IsThresholdEnabled = false;
                        IsMaximumEnabled = true;
                        IsTypeEnabled = false;
                        Operation.Threshold = 254;
                        //Operation.Maximum = 254;
                        Operation.Type = ThresholdType.Binary;
                        break;
                }
            }
        }

        public ToolThresholdControl()
        {
            BaseOperation = new OperationThreshold(SlicerFile);
            if (!ValidateSpawn()) return; 
            InitializeComponent();
        }

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