-
Notifications
You must be signed in to change notification settings - Fork 1
/
SettingsControl.cs
174 lines (166 loc) · 6.13 KB
/
SettingsControl.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace cavapa
{
public partial class SettingsControl : UserControl {
public double FrameSmoothingAlpha {
get {
return trackBarExFrameSmoothAlpha.Val;
}
set {
trackBarExFrameSmoothAlpha.Val = value;
}
}
public bool EnableShadowReduction {
get {
return checkBoxShadowReduceEnabled.Checked;
}
set {
checkBoxShadowReduceEnabled.Checked = value;
}
}
public bool EnableDespeckle {
get {
return checkBoxDeSpeckle.Checked;
}
set {
checkBoxDeSpeckle.Checked = value;
}
}
public double MovementHistoryDecay {
get {
return trackBarExGlowTrail.Val;
}
set {
trackBarExGlowTrail.Val = value;
}
}
public double MovementScoreMul {
get {
return trackBarExMoveScoreMul.Val;
}
set {
trackBarExMoveScoreMul.Val = value;
}
}
public double MovementPixMul {
get {
return trackBarExMoveMul.Val;
}
set {
trackBarExMoveMul.Val = value;
}
}
public double MovementNoiseFloor {
get {
return trackBarExNoiseThresh.Val;
}
set {
trackBarExNoiseThresh.Val = value;
}
}
public Button AcceptButton {
get {
return this.buttonApply; // ! not really
}
}
public Button CloseButton {
get {
return this.buttonClose;
}
}
public const string _settingsFilename = "cavapa_settings.txt";
public SettingsControl() {
InitializeComponent();
}
private void SettingsControl_Load(object sender, EventArgs e) {
LoadSettings();
}
public void SaveSettings(string filepath = _settingsFilename) {
var ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
using (TextWriter file = File.CreateText(filepath)) {
file.WriteLine($"# \"{Path.GetFileName(filepath)}\"");
file.WriteLine($"# CAVAPA v{ver.ToString()} settings file.");
file.WriteLine($"# Created " + DateTime.Now.ToString());
file.WriteLine();
file.WriteLine($"FrameSmoothingAlpha={FrameSmoothingAlpha.ToString()}");
file.WriteLine($"EnableShadowReduction={EnableShadowReduction.ToString()}");
file.WriteLine($"MovementHistoryDecay={MovementHistoryDecay.ToString()}");
file.WriteLine($"MovementScoreMul={MovementScoreMul.ToString()}");
file.WriteLine($"MovementPixMul={MovementPixMul.ToString()}");
file.WriteLine($"MovementNoiseFloor={MovementNoiseFloor.ToString()}");
file.WriteLine($"EnableDespeckle={EnableDespeckle.ToString()}");
file.WriteLine();
file.Flush();
file.Close();
}
}
public void LoadSettings(string filepath = _settingsFilename) {
if (!File.Exists(filepath))
return;
using (TextReader file = File.OpenText(filepath)) {
var data = new Dictionary<string, string>();
String line = "";
while (true) {
line = file.ReadLine();
if (line == null)
break;
line = line.Trim(); // trim whitespace
if (line.Length == 0 || line[1] == '#')
continue;
if (line.Contains('#')) {
line = line.Substring(0, line.IndexOf('#')).Trim(); // ignore after the #
}
string[] splitLine = line.Split(new char[] { '=' });
if (splitLine.Length == 2) {
data[splitLine[0]] = splitLine[1];
}
}
file.Close();
if (data.ContainsKey("FrameSmoothingAlpha")) {
double d = 0;
if (double.TryParse(data["FrameSmoothingAlpha"], out d))
FrameSmoothingAlpha = d;
}
if (data.ContainsKey("EnableShadowReduction")) {
bool d = false;
if (bool.TryParse(data["EnableShadowReduction"], out d))
EnableShadowReduction = d;
}
if (data.ContainsKey("EnableDespeckle")) {
bool d = false;
if (bool.TryParse(data["EnableDespeckle"], out d))
EnableDespeckle = d;
}
if (data.ContainsKey("MovementHistoryDecay")) {
double d = 0;
if (double.TryParse(data["MovementHistoryDecay"], out d))
MovementHistoryDecay = d;
}
if (data.ContainsKey("MovementScoreMul")) {
double d = 0;
if (double.TryParse(data["MovementScoreMul"], out d))
MovementScoreMul = d;
}
if (data.ContainsKey("MovementPixMul")) {
double d = 0;
if (double.TryParse(data["MovementPixMul"], out d))
MovementPixMul = d;
}
if (data.ContainsKey("MovementNoiseFloor")) {
double d = 0;
if (double.TryParse(data["MovementNoiseFloor"], out d))
MovementNoiseFloor = d;
}
}
}
}
}