Spring – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using System;
2 using System.ComponentModel;
3 using System.Drawing;
4 using System.Text.RegularExpressions;
5 using System.Windows.Forms;
6 using Spring.Properties;
7  
8 namespace Spring.Settings
9 {
10 public partial class SettingsForm : Form
11 {
12 #region Public Enums, Properties and Fields
13  
14 public BindingList<string> WhitelistBinding { get; set; }
15  
16 #endregion
17  
18 #region Private Delegates, Events, Enums, Properties, Indexers and Fields
19  
20 private Region PanelRegion { get; set; }
21  
22 private Graphics PanelGraphics { get; set; }
23  
24 private SolidBrush PanelSolidColorBrush { get; set; }
25  
26 private RectangleF PanelBounds { get; }
27  
28 private Configuration.Configuration Configuration { get; }
29  
30 #endregion
31  
32 #region Constructors, Destructors and Finalizers
33  
34 /// <summary>
35 /// Clean up any resources being used.
36 /// </summary>
37 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
38 protected override void Dispose(bool disposing)
39 {
40 if (disposing && components != null)
41 {
42 PanelRegion?.Dispose();
43 PanelRegion = null;
44  
45 PanelGraphics?.Dispose();
46 PanelGraphics = null;
47  
48 PanelSolidColorBrush?.Dispose();
49 PanelSolidColorBrush = null;
50  
51 components.Dispose();
52 }
53  
54 base.Dispose(disposing);
55 }
56  
57 public SettingsForm(Configuration.Configuration springConfiguration) : this()
58 {
59 Configuration = springConfiguration;
60  
61 WhitelistBinding = new BindingList<string>(Configuration.HUD.WhiteList.Whitelist);
62 windowWhiteListListBox.DataSource = WhitelistBinding;
63  
64 enableWindowWhiteListCheckBox.DataBindings.Add(nameof(enableWindowWhiteListCheckBox.Checked),
65 Configuration.HUD,
66 nameof(Configuration.HUD.EnableWhiteList),
67 false,
68 DataSourceUpdateMode.OnPropertyChanged);
69  
70 fuzzTrackBar.DataBindings.Add(nameof(fuzzTrackBar.Value),
71 Configuration.Spring,
72 nameof(Configuration.Spring.Fuzz),
73 false,
74 DataSourceUpdateMode.OnPropertyChanged);
75  
76 textBox2.Text = Configuration.Spring.Fuzz.ToString();
77  
78 hudColorLabel.DataBindings.Add(nameof(hudColorLabel.BackColor),
79 Configuration.HUD,
80 nameof(Configuration.HUD.Color),
81 false,
82 DataSourceUpdateMode.OnPropertyChanged);
83  
84 enableHudCheckBox.DataBindings.Add(nameof(enableHudCheckBox.Checked),
85 Configuration.HUD,
86 nameof(Configuration.HUD.Enable),
87 false,
88 DataSourceUpdateMode.OnPropertyChanged);
89  
90 enableKeyboardCheckbox.DataBindings.Add(nameof(enableKeyboardCheckbox.Checked),
91 Configuration.Spring.Charge,
92 nameof(Configuration.Spring.Charge.Keyboard),
93 false,
94 DataSourceUpdateMode.OnPropertyChanged);
95  
96 useRelativeMouseMovementCheckbox.DataBindings.Add(nameof(useRelativeMouseMovementCheckbox.Checked),
97 Configuration.Spring.Discharge,
98 nameof(Configuration.Spring.Discharge.UseRelativeMouseMovement),
99 false,
100 DataSourceUpdateMode.OnPropertyChanged);
101  
102 enableMouseMoveCheckBox.DataBindings.Add(nameof(enableMouseMoveCheckBox.Checked),
103 Configuration.Spring.Charge,
104 nameof(Configuration.Spring.Charge.MouseMove),
105 false,
106 DataSourceUpdateMode.OnPropertyChanged);
107  
108 enableMouseClickCheckBox.DataBindings.Add(nameof(enableMouseClickCheckBox.Checked),
109 Configuration.Spring.Charge,
110 nameof(Configuration.Spring.Charge.MouseClick),
111 false,
112 DataSourceUpdateMode.OnPropertyChanged);
113  
114 chargeDelayTrackBar.DataBindings.Add(nameof(chargeDelayTrackBar.Value),
115 Configuration.Spring.Charge,
116 nameof(Configuration.Spring.Charge.ChargeSeconds),
117 false,
118 DataSourceUpdateMode.OnPropertyChanged);
119  
120 textBox3.Text = Configuration.Spring.Charge.ChargeSeconds.ToString();
121  
122 maximumRepeatsTrackBar.DataBindings.Add(nameof(maximumRepeatsTrackBar.Value),
123 Configuration.Spring.Charge,
124 nameof(Configuration.Spring.Charge.MaximumRepeats),
125 false,
126 DataSourceUpdateMode.OnPropertyChanged);
127  
128 textBox1.Text = Configuration.Spring.Charge.MaximumRepeats.ToString();
129 }
130  
131 private SettingsForm()
132 {
133 InitializeComponent();
134 Utilities.WindowState.FormTracker.Track(this);
135  
136 PanelGraphics = hudPostionPanel.CreateGraphics();
137 PanelBounds = PanelGraphics.VisibleClipBounds;
138 PanelSolidColorBrush = new SolidBrush(hudPostionPanel.BackColor);
139 PanelRegion = new Region(PanelBounds);
140 }
141  
142 #endregion
143  
144 #region Event Handlers
145  
146 private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
147 {
148 var listBox = (ListBox) sender;
149 var item = listBox.SelectedItem;
150  
151 if (item == null)
152 {
153 return;
154 }
155  
156 whiteListEntryTextBox.Text = item.ToString();
157 }
158  
159 private void Button2_Click(object sender, EventArgs e)
160 {
161 var text = whiteListEntryTextBox.Text;
162  
163 if (string.IsNullOrEmpty(text))
164 {
165 return;
166 }
167  
168 try
169 {
170 var _ = new Regex(text, RegexOptions.Compiled);
171 }
172 catch
173 {
174 return;
175 }
176  
177 if (!WhitelistBinding.Contains(text))
178 {
179 WhitelistBinding.Add(text);
180 }
181 }
182  
183 private void Button3_Click(object sender, EventArgs e)
184 {
185 var item = windowWhiteListListBox.SelectedItem;
186  
187 if (item == null)
188 {
189 return;
190 }
191  
192 var text = item.ToString();
193  
194 if (string.IsNullOrEmpty(text))
195 {
196 return;
197 }
198  
199 if (WhitelistBinding.Contains(text))
200 {
201 WhitelistBinding.Remove(text);
202 }
203 }
204  
205 private void Button1_Click(object sender, EventArgs e)
206 {
207 if (colorDialog1.ShowDialog() != DialogResult.OK)
208 {
209 return;
210 }
211  
212 Configuration.HUD.Color = colorDialog1.Color;
213 hudColorLabel.BackColor = colorDialog1.Color;
214 }
215  
216 private void SpringSettingsForm_Shown(object sender, EventArgs e)
217 {
218 var x = Configuration.HUD.Position.X * PanelBounds.Width / 100f;
219 var y = Configuration.HUD.Position.Y * PanelBounds.Height / 100f;
220  
221 PanelGraphics.FillRegion(PanelSolidColorBrush, PanelRegion);
222  
223 PanelGraphics.DrawIcon(Resources.x,
224 (int) (x - Resources.x.Width / 2f),
225 (int) (y - Resources.x.Height / 2f));
226 }
227  
228 private void HUDPositionPanel_MouseClick(object sender, MouseEventArgs e)
229 {
230 var x = e.Location.X;
231 var y = e.Location.Y;
232  
233 Configuration.HUD.Position.X = (int) (100f * x / PanelBounds.Width);
234 Configuration.HUD.Position.Y = (int) (100f * y / PanelBounds.Height);
235  
236 PanelGraphics.FillRegion(PanelSolidColorBrush, PanelRegion);
237  
238 PanelGraphics.DrawIcon(Resources.x,
239 (int) (x - Resources.x.Width / 2f),
240 (int) (y - Resources.x.Height / 2f));
241 }
242  
243 private void HUDColorLabel_Click(object sender, EventArgs e)
244 {
245 if (colorDialog1.ShowDialog() != DialogResult.OK)
246 {
247 return;
248 }
249  
250 Configuration.HUD.Color = colorDialog1.Color;
251 hudColorLabel.BackColor = colorDialog1.Color;
252 }
253  
254 private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
255 {
256 var x = Configuration.HUD.Position.X * PanelBounds.Width / 100f;
257 var y = Configuration.HUD.Position.Y * PanelBounds.Height / 100f;
258  
259 PanelGraphics.FillRegion(PanelSolidColorBrush, PanelRegion);
260  
261 PanelGraphics.DrawIcon(Resources.x,
262 (int) (x - Resources.x.Width / 2f),
263 (int) (y - Resources.x.Height / 2f));
264 }
265  
266 private void FuzzTrackBar_Scroll(object sender, EventArgs e)
267 {
268 var trackBar = (TrackBar) sender;
269  
270 textBox2.Text = trackBar.Value.ToString();
271 }
272  
273 private void TextBox2_TextChanged(object sender, EventArgs e)
274 {
275 var textBox = (TextBox) sender;
276  
277 if (!int.TryParse(textBox.Text, out var value) ||
278 value < fuzzTrackBar.Minimum ||
279 value > fuzzTrackBar.Maximum)
280 {
281 return;
282 }
283  
284 fuzzTrackBar.Value = value;
285 }
286  
287 private void MaximumRepeatsTrackBar_Scroll(object sender, EventArgs e)
288 {
289 var trackBar = (TrackBar) sender;
290  
291 textBox1.Text = trackBar.Value.ToString();
292 }
293  
294 private void TextBox3_TextChanged(object sender, EventArgs e)
295 {
296 var textBox = (TextBox) sender;
297  
298 if (!int.TryParse(textBox.Text, out var value) ||
299 value < chargeDelayTrackBar.Minimum ||
300 value > chargeDelayTrackBar.Maximum)
301 {
302 return;
303 }
304  
305 chargeDelayTrackBar.Value = value;
306 }
307  
308 private void ChargeDelayTrackBar_Scroll(object sender, EventArgs e)
309 {
310 var trackBar = (TrackBar) sender;
311  
312 textBox3.Text = trackBar.Value.ToString();
313 }
314  
315 private void TextBox1_TextChanged(object sender, EventArgs e)
316 {
317 var textBox = (TextBox) sender;
318  
319 if (!int.TryParse(textBox.Text, out var value) ||
320 value < maximumRepeatsTrackBar.Minimum ||
321 value > maximumRepeatsTrackBar.Maximum)
322 {
323 return;
324 }
325  
326 maximumRepeatsTrackBar.Value = value;
327 }
328  
329 #endregion
330 }
331 }