summaryrefslogtreecommitdiff
path: root/grapher/Models/Options/OffsetOptions.cs
blob: 0b01ab9fa91c28427317f3f429e2ac7e7326080d (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace grapher.Models.Options
{
    public class OffsetOptions
    {
        public OffsetOptions(
            ToolStripMenuItem velocityGainOffsetCheck,
            ToolStripMenuItem legacyOffsetCheck,
            Option offsetOption)
        {
            VelocityGainOffsetCheck = velocityGainOffsetCheck;
            LegacyOffsetCheck = legacyOffsetCheck;
            OffsetOption = offsetOption;

            VelocityGainOffsetCheck.Click += new System.EventHandler(OnVelocityGainOffsetClick);
            LegacyOffsetCheck.Click += new System.EventHandler(OnLegacyOffsetClick);

            VelocityGainOffsetCheck.CheckedChanged += new System.EventHandler(OnVelocityGainOffsetCheckedChange);
            LegacyOffsetCheck.CheckedChanged += new System.EventHandler(OnLegacyOffsetCheckedChange);

            VelocityGainOffsetCheck.Checked = true;
        }

        public ToolStripMenuItem VelocityGainOffsetCheck { get; }

        public ToolStripMenuItem LegacyOffsetCheck { get; }

        public Option OffsetOption { get; }

        public bool IsLegacy { get; private set; }

        public double LegacyOffset 
        { 
            get
            {
                if (IsLegacy)
                {
                    return OffsetOption.Field.Data;
                }
                else
                {
                    return 0;
                }
            } 
        }

        public double Offset
        {
            get
            {
                if (IsLegacy)
                {
                    return 0;
                }
                else
                {
                    return OffsetOption.Field.Data;
                }
            }
        }

        public void SetActiveValue(double offset, double legacyOffset)
        {
            if (offset > 0)
            {
                OffsetOption.SetActiveValue(offset);
            }
            else
            {
                OffsetOption.SetActiveValue(legacyOffset);
            }
        }

        public void OnVelocityGainOffsetClick(object sender, EventArgs e)
        {
            if (!VelocityGainOffsetCheck.Checked)
            {
                VelocityGainOffsetCheck.Checked = true;
                LegacyOffsetCheck.Checked = false;
            }
        }

        public void OnLegacyOffsetClick(object sender, EventArgs e)
        {
            if (!LegacyOffsetCheck.Checked)
            {
                LegacyOffsetCheck.Checked = true;
                VelocityGainOffsetCheck.Checked = false;
            }
        }

        public void OnVelocityGainOffsetCheckedChange(object sender, EventArgs e)
        {
            if (VelocityGainOffsetCheck.Checked)
            {
                EnableVelocityGainOffset();
            }
        }

        public void OnLegacyOffsetCheckedChange(object sender, EventArgs e)
        {
            if (LegacyOffsetCheck.Checked)
            {
                EnableLegacyOffset();
            }
        }

        public void EnableVelocityGainOffset()
        {
            IsLegacy = false;
        }

        public void EnableLegacyOffset()
        {
            IsLegacy = true;
        }
    }
}