summaryrefslogtreecommitdiff
path: root/grapher/Layouts/LayoutBase.cs
blob: 83af292a57c5873c878cccce6ca813c9db7ecb42 (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
using grapher.Models.Options;
using System.Windows.Forms;

namespace grapher.Layouts
{
    public abstract class LayoutBase
    {
        public const string Acceleration = "Acceleration";
        public const string Scale = "Scale";
        public const string Exponent = "Exponent";
        public const string Limit = "Limit";
        public const string Midpoint = "Midpoint";
        public const string Motivity = "Motivity";
        public const string Offset = "Offset";
        public const string Cap = "Cap";
        public const string Weight = "Weight";

        public LayoutBase()
        {
            AccelLayout = new OptionLayout(false, string.Empty);
            ScaleLayout = new OptionLayout(false, string.Empty);
            CapLayout = new OptionLayout(false, string.Empty);
            WeightLayout = new OptionLayout(false, string.Empty);
            OffsetLayout = new OptionLayout(false, string.Empty);
            LimitLayout = new OptionLayout(false, string.Empty);
            ExponentLayout = new OptionLayout(false, string.Empty);
            MidpointLayout = new OptionLayout(false, string.Empty);

            LogarithmicCharts = false;
        }

        /// <summary>
        ///  Gets or sets mapping from acceleration type to identifying integer.
        ///  Must match accel_mode defined in rawaccel-settings.h
        /// </summary>
        public int Index { get; protected set; }

        public string Name { get; protected set; }

        public bool LogarithmicCharts { get; protected set; }

        protected OptionLayout AccelLayout { get; set; }

        protected OptionLayout ScaleLayout { get; set; }

        protected OptionLayout CapLayout { get; set; }

        protected OptionLayout WeightLayout { get; set; }

        protected OptionLayout OffsetLayout { get; set; }

        protected OptionLayout LimitLayout { get; set; }

        protected OptionLayout ExponentLayout { get; set; }

        protected OptionLayout MidpointLayout { get; set; }

        public void Layout(
            IOption accelOption,
            IOption scaleOption,
            IOption capOption,
            IOption weightOption,
            IOption offsetOption,
            IOption limitOption,
            IOption expOption,
            IOption midpointOption,
            int top)
        {

            IOption previous = null;

            foreach (var option in new (OptionLayout, IOption)[] {
                (AccelLayout, accelOption),
                (ScaleLayout, scaleOption),
                (CapLayout, capOption),
                (WeightLayout, weightOption),
                (OffsetLayout, offsetOption),
                (LimitLayout, limitOption),
                (ExponentLayout, expOption),
                (MidpointLayout, midpointOption)})
            {
                option.Item1.Layout(option.Item2);

                if (option.Item2.Visible)
                {
                    if (previous != null)
                    {
                        option.Item2.SnapTo(previous);
                    }
                    else
                    {
                        option.Item2.Top = top;
                    }

                    previous = option.Item2;
                }
            }
        }

        public void Layout(
            IOption accelOption,
            IOption scaleOption,
            IOption capOption,
            IOption weightOption,
            IOption offsetOption,
            IOption limitOption,
            IOption expOption,
            IOption midpointOption)
        {
            Layout(accelOption,
                scaleOption,
                capOption,
                weightOption,
                offsetOption,
                limitOption,
                expOption,
                midpointOption,
                accelOption.Top);
        }
    }
}