summaryrefslogtreecommitdiff
path: root/grapher/Models/Options/Cap/CapOptions.cs
blob: 144cd7966f8a27a4751c9268f0710cc9ee5f1dfc (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace grapher.Models.Options.Cap
{
    public class CapOptions : OptionBase
    {
        public enum CapType
        {
            In,
            Out,
            Both,
        }

        public CapOptions(
            ComboBox capTypeDropDown,
            Option capIn,
            Option capOut,
            Option slope)
        {
            CapTypeDropdown = capTypeDropDown;
            In = capIn;
            Out = capOut;
            Slope = slope;

            SetupCapTypeDropdown(CapTypeDropdown);
            CapTypeDropdown.SelectedItem = CapType.In;
        }

        public ComboBox CapTypeDropdown { get; }

        public Option In { get; }

        public Option Out { get; }

        public Option Slope { get; }

        public CapType SelectedCapType { get; private set; }

        public override int Left
        {
            get => In.Left;

            set
            {
                In.Left = value;
                Out.Left = value;
                Slope.Left = value;
            }
        }

        public override int Top
        {
            get => CapTypeDropdown.Top;
            set
            {
                CapTypeDropdown.Top = value;
                Layout();
            }
        }

        public override int Height
        {
            get => BottomElement.Top + BottomElement.Height - CapTypeDropdown.Top;
        }

        public override int Width
        {
            get => CapTypeDropdown.Width;

            set
            {
                CapTypeDropdown.Width = value;
                In.Width = value;
                Out.Width = value;
                Slope.Width = value;
            }
        }

        public override bool Visible
        {
            get => CapTypeDropdown.Visible;
        }

        private Option BottomElement { get; set; }

        public void Layout()
        {
            Layout(CapTypeDropdown.Top + CapTypeDropdown.Height + Constants.OptionVerticalSeperation);
        }

        private void Layout(int top)
        {
            switch (SelectedCapType)
            {
                case CapType.In:
                    Slope.Show();
                    In.Show();
                    Out.Hide();

                    Slope.Top = top;
                    In.SnapTo(Slope);
                    BottomElement = In;
                    break;
                case CapType.Out:
                    Slope.Show();
                    In.Hide();
                    Out.Show();

                    Slope.Top = top;
                    In.SnapTo(Slope);
                    BottomElement = In;
                    break;
                case CapType.Both:
                    Slope.Hide();
                    In.Show();
                    Out.Show();

                    In.Top = top;
                    Out.SnapTo(In);
                    BottomElement = Out;
                    break;
            }
        }

        private void FindSelectedTypeFromDropdown()
        {
            SelectedCapType = (CapType)CapTypeDropdown.SelectedItem;
        }

        private void OnCapTypeDropdownSelectedItemChanged(object sender, EventArgs e)
        {
            FindSelectedTypeFromDropdown();
            Layout();
        }

        private void SetupCapTypeDropdown(ComboBox capTypeDropDown)
        {
            capTypeDropDown.Items.Clear();
            capTypeDropDown.DataSource = Enum.GetValues(typeof(CapType));
        }
    }
}