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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
using grapher.Models.Calculations;
using grapher.Models.Mouse;
using grapher.Models.Options;
using grapher.Models.Serialized;
using System;
using System.Windows.Forms;
namespace grapher
{
public class AccelGUI
{
#region Constructors
public AccelGUI(
RawAcceleration accelForm,
AccelCalculator accelCalculator,
AccelCharts accelCharts,
SettingsManager settings,
ApplyOptions applyOptions,
Button writeButton,
MouseWatcher mouseWatcher,
ToolStripMenuItem scaleMenuItem)
{
AccelForm = accelForm;
AccelCalculator = accelCalculator;
AccelCharts = accelCharts;
ApplyOptions = applyOptions;
WriteButton = writeButton;
ScaleMenuItem = scaleMenuItem;
Settings = settings;
Settings.Startup();
RefreshOnRead();
MouseWatcher = mouseWatcher;
ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick);
WriteButton.Click += new System.EventHandler(OnWriteButtonClick);
ButtonTimer = SetupButtonTimer();
ChartRefresh = SetupChartTimer();
SetupWriteButton();
}
#endregion Constructors
#region Properties
public RawAcceleration AccelForm { get; }
public AccelCalculator AccelCalculator { get; }
public AccelCharts AccelCharts { get; }
public SettingsManager Settings { get; }
public ApplyOptions ApplyOptions { get; }
public Button WriteButton { get; }
public Timer ButtonTimer { get; }
public MouseWatcher MouseWatcher { get; }
public ToolStripMenuItem ScaleMenuItem { get; }
private Timer ChartRefresh { get; }
#endregion Properties
#region Methods
public void UpdateActiveSettingsFromFields()
{
var driverSettings = Settings.RawAccelSettings.AccelerationSettings;
var settings = new DriverSettings
{
rotation = ApplyOptions.Rotation.Field.Data,
sensitivity = new Vec2<double>
{
x = ApplyOptions.Sensitivity.Fields.X,
y = ApplyOptions.Sensitivity.Fields.Y
},
combineMagnitudes = ApplyOptions.IsWhole,
modes = ApplyOptions.GetModes(),
args = ApplyOptions.GetArgs(),
minimumTime = driverSettings.minimumTime
};
WriteButtonDelay();
SettingsErrors errors = Settings.TryUpdateActiveSettings(settings);
if (errors.Empty())
{
RefreshOnRead();
}
else
{
throw new Exception($"Bad arguments: \n {SettingsManager.ErrorStringFrom(errors)}");
}
}
public void RefreshOnRead()
{
UpdateShownActiveValues();
UpdateGraph();
}
public void UpdateGraph()
{
AccelCharts.Calculate(
Settings.ActiveAccel,
Settings.RawAccelSettings.AccelerationSettings);
AccelCharts.Bind();
}
public void UpdateShownActiveValues()
{
var settings = Settings.RawAccelSettings.AccelerationSettings;
AccelCharts.ShowActive(settings);
ApplyOptions.SetActiveValues(settings);
}
private Timer SetupChartTimer()
{
Timer chartTimer = new Timer();
chartTimer.Enabled = true;
chartTimer.Interval = 10;
chartTimer.Tick += new System.EventHandler(OnChartTimerTick);
return chartTimer;
}
private Timer SetupButtonTimer()
{
Timer buttonTimer = new Timer();
buttonTimer.Enabled = true;
buttonTimer.Interval = Convert.ToInt32(DriverInterop.WriteDelayMs);
buttonTimer.Tick += new System.EventHandler(OnButtonTimerTick);
return buttonTimer;
}
private void SetupWriteButton()
{
WriteButton.Top = AccelCharts.Top + AccelCharts.TopChartHeight - Constants.WriteButtonVerticalOffset;
SetWriteButtonDefault();
}
private void SetWriteButtonDefault()
{
WriteButton.Text = Constants.WriteButtonDefaultText;
WriteButton.Enabled = true;
WriteButton.Update();
}
private void SetWriteButtonDelay()
{
WriteButton.Enabled = false;
WriteButton.Text = $"{Constants.WriteButtonDelayText} : {ButtonTimer.Interval} ms";
WriteButton.Update();
}
private void OnScaleMenuItemClick(object sender, EventArgs e)
{
UpdateGraph();
}
private void OnWriteButtonClick(object sender, EventArgs e)
{
UpdateActiveSettingsFromFields();
}
private void OnButtonTimerTick(object sender, EventArgs e)
{
ButtonTimer.Stop();
SetWriteButtonDefault();
}
private void WriteButtonDelay()
{
SetWriteButtonDelay();
ButtonTimer.Start();
}
private void OnChartTimerTick(object sender, EventArgs e)
{
AccelCharts.DrawLastMovement();
MouseWatcher.UpdateLastMove();
}
#endregion Methods
}
}
|