-
Notifications
You must be signed in to change notification settings - Fork 282
Expand file tree
/
Copy pathConfiguration.cs
More file actions
366 lines (289 loc) · 10.5 KB
/
Configuration.cs
File metadata and controls
366 lines (289 loc) · 10.5 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
using System;
using System.IO;
using System.Windows;
using System.Xml;
using System.Xml.Serialization;
namespace TabletDriverGUI
{
[XmlRootAttribute("Configuration", IsNullable = true)]
public class Configuration
{
public const string DEFAULT_CONFIG_FILE = "config/configs/Default.xml";
public int ConfigVersion;
public string TabletName;
public Area ScreenArea;
[XmlArray("ScreenAreas")]
[XmlArrayItem("ScreenArea")]
public Area[] ScreenAreas;
public Area SelectedScreenArea;
public Area TabletArea;
[XmlArray("TabletAreas")]
[XmlArrayItem("TabletArea")]
public Area[] TabletAreas;
public Area SelectedTabletArea;
public Area TabletFullArea;
public bool ForceAspectRatio;
public double Rotation;
public bool Invert;
public OutputPositioning Positioning;
public OutputModes Mode;
public enum OutputPositioning
{
Absolute = 0,
Relative = 1
}
public enum OutputModes
{
Standard = 0,
WindowsInk = 1,
Compatibility = 2
}
// Smoothing filter
public bool SmoothingEnabled;
public double SmoothingLatency;
public int SmoothingInterval;
public bool SmoothingOnlyWhenButtons;
// Noise filter
public bool NoiseFilterEnabled;
public int NoiseFilterBuffer;
public double NoiseFilterThreshold;
// Anti-smoothing filter
public bool AntiSmoothingEnabled;
public class AntiSmoothingSetting
{
public bool Enabled;
public double Velocity;
public double Shape;
public double Compensation;
public AntiSmoothingSetting()
{
Enabled = false;
Velocity = 0;
Shape = 0.5;
Compensation = 0;
}
}
[XmlArray("AntiSmoothingSettingsList")]
[XmlArrayItem("AntiSmoothingSettings")]
public AntiSmoothingSetting[] AntiSmoothingSettings;
public bool AntiSmoothingOnlyWhenHover;
public double AntiSmoothingDragMultiplier;
public Area DesktopSize;
public bool AutomaticDesktopSize;
[XmlArray("ButtonMap")]
[XmlArrayItem("Button")]
public string[] ButtonMap;
public bool DisableButtons;
[XmlArray("TabletButtonMap")]
[XmlArrayItem("Button")]
public string[] TabletButtonMap;
public bool DisableTabletButtons;
public double PressureSensitivity;
public double PressureDeadzoneLow;
public double PressureDeadzoneHigh;
public double ScrollSensitivity;
public double ScrollAcceleration;
public bool ScrollStopCursor;
public bool ScrollDrag;
[XmlArray("CustomCommands")]
[XmlArrayItem("Command")]
public string[] CustomCommands;
public int WindowWidth;
public int WindowHeight;
public class TabletViewSettings
{
public string BackgroundColor;
public string InfoColor;
public string InputColor;
public string OutputColor;
public string LatencyColor;
public string DrawColor;
public int InputTrailLength;
public int OutputTrailLength;
public int DrawLength;
public string Font;
public double FontSize;
public Point OffsetText;
public Point OffsetPressure;
public bool FadeInOut;
public bool Borderless;
public TabletViewSettings()
{
BackgroundColor = "#FFFFFF";
InfoColor = "#000000";
InputColor = "#33AA33";
OutputColor = "#AA3333";
LatencyColor = "#3333AA";
DrawColor = "#000000";
InputTrailLength = 30;
OutputTrailLength = 30;
DrawLength = 0;
Font = "Segoe UI";
FontSize = 25;
OffsetPressure = new Point(0, 0);
OffsetText = new Point(0, 0);
FadeInOut = false;
Borderless = false;
}
}
public TabletViewSettings TabletView;
public bool AutomaticRestart;
public bool RunAtStartup;
public string DriverPath;
public string DriverArguments;
public bool DebuggingEnabled;
public bool DeveloperMode;
public class Preset
{
public string Name;
public Action<Configuration> Action;
public Preset(string name, Action<Configuration> action)
{
Name = name;
Action = action;
}
public override string ToString() => Name;
}
public Configuration()
{
ConfigVersion = 2;
// Screen Map
ScreenArea = null;
ScreenAreas = new Area[3];
for (int i = 0; i < ScreenAreas.Length; i++)
{
ScreenAreas[i] = new Area(0, 0, 0, 0)
{
IsEnabled = false
};
}
ScreenAreas[0].IsEnabled = true;
ScreenAreas[1] = new Area(1000, 500, 500, 250);
// Tablet area
TabletArea = null;
TabletAreas = new Area[ScreenAreas.Length];
for (int i = 0; i < GetAreaCount(); i++)
TabletAreas[i] = new Area(100, 56, 50, 28);
TabletFullArea = new Area(100, 50, 50, 25);
Mode = OutputModes.Standard;
ForceAspectRatio = true;
Rotation = 0;
DesktopSize = new Area(0, 0, 0, 0);
AutomaticDesktopSize = true;
ButtonMap = new string[] { "MOUSE1", "MOUSE2", "MOUSE3" };
DisableButtons = false;
TabletButtonMap = new string[16];
for (int i = 0; i < 16; i++) TabletButtonMap[i] = "";
DisableTabletButtons = false;
PressureSensitivity = 0;
ScrollSensitivity = 0.5;
ScrollAcceleration = 1.0;
ScrollStopCursor = false;
SmoothingEnabled = false;
SmoothingLatency = 0;
SmoothingInterval = 4;
SmoothingOnlyWhenButtons = false;
NoiseFilterEnabled = false;
NoiseFilterBuffer = 10;
NoiseFilterThreshold = 0.5;
AntiSmoothingEnabled = false;
AntiSmoothingSettings = new AntiSmoothingSetting[5];
for (int i = 0; i < AntiSmoothingSettings.Length; i++)
AntiSmoothingSettings[i] = new AntiSmoothingSetting();
AntiSmoothingDragMultiplier = 1.0;
AntiSmoothingOnlyWhenHover = false;
CustomCommands = new string[0];
WindowWidth = 700;
WindowHeight = 700;
TabletView = new TabletViewSettings();
AutomaticRestart = true;
RunAtStartup = false;
DriverPath = "bin/TabletDriverService.exe";
DriverArguments = "config/init.cfg";
DebuggingEnabled = false;
DeveloperMode = false;
}
//
// Get number of areas
//
public int GetAreaCount()
{
if (ScreenAreas.Length <= TabletAreas.Length)
return ScreenAreas.Length;
return TabletAreas.Length;
}
//
// Get maximum number of areas
//
public int GetMaxAreaCount() => 5;
//
// Get number of enabled areas
//
public int GetEnabledAreaCount()
{
int count = 0;
foreach (Area area in ScreenAreas)
{
if (area.IsEnabled) count++;
}
return count;
}
//
// Clear anti-smoothing filter settings
//
public void ClearAntiSmoothingSettings()
{
for (int i = 0; i < AntiSmoothingSettings.Length; i++)
{
AntiSmoothingSettings[i].Enabled = false;
AntiSmoothingSettings[i].Velocity = 0;
AntiSmoothingSettings[i].Shape = 0.5;
AntiSmoothingSettings[i].Compensation = 0;
}
}
//
// Set anti-smoothing filter settings
//
public void SetAntiSmoothingSetting(int index, bool enabled, double velocity, double shape, double compensation)
{
AntiSmoothingSettings[index].Enabled = enabled;
AntiSmoothingSettings[index].Velocity = velocity;
AntiSmoothingSettings[index].Shape = shape;
AntiSmoothingSettings[index].Compensation = compensation;
}
//
// Write configuration to a XML file
//
public void Write(string filename)
{
var serializer = new XmlSerializer(typeof(Configuration));
var xmlWriterSettings = new XmlWriterSettings { Indent = true };
using (var file = new StreamWriter(filename))
{
var writer = XmlWriter.Create(file, xmlWriterSettings);
serializer.Serialize(file, this);
}
}
//
// Create configuration from a XML file
//
public static Configuration CreateFromFile(string filename)
{
if (!File.Exists(filename))
throw new FileNotFoundException("Could not find configuration file", filename);
var serializer = new XmlSerializer(typeof(Configuration));
using (var file = File.OpenRead(filename))
{
return (Configuration)serializer.Deserialize(file);
}
}
public static string GetSelectedConfig()
{
if (!File.Exists("config/.current"))
return DEFAULT_CONFIG_FILE;
return File.ReadAllText("config/.current").Trim('\r', '\n', '\t', ' ');
}
public static void SetSelectedConfig(string path)
=> File.WriteAllText("config/.current", path);
}
}