Skip to content

Commit 6e07967

Browse files
committed
changes
1 parent 0c06cf7 commit 6e07967

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/EventPi.Abstractions/PanConfig.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Drawing;
2+
3+
namespace EventPi.Abstractions
4+
{
5+
public record struct PanConfig(int Size, Point Center) : IParsable<PanConfig>
6+
{
7+
public PanConfig(int size, int cx, int cy) : this(size, new Point(cx, cy))
8+
{
9+
10+
}
11+
public static PanConfig Parse(string s, IFormatProvider? provider = null)
12+
{
13+
if (string.IsNullOrEmpty(s)) throw new ArgumentNullException(nameof(s));
14+
15+
var parts = s.Split('_');
16+
if (parts.Length != 3) throw new FormatException("Invalid format for PanConfig.");
17+
18+
var size = int.Parse(parts[0]);
19+
var cx = int.Parse(parts[1]);
20+
var cy = int.Parse(parts[2]);
21+
22+
return new PanConfig(size, cx, cy);
23+
24+
}
25+
public static implicit operator Guid(PanConfig pan)
26+
{
27+
return pan.ToString().ToGuid();
28+
}
29+
public static bool TryParse(string? input, IFormatProvider? formatProvider, out PanConfig result)
30+
{
31+
try
32+
{
33+
result = Parse(input!, formatProvider);
34+
return true;
35+
}
36+
catch
37+
{
38+
result = default;
39+
return false;
40+
}
41+
}
42+
public override string ToString()
43+
{
44+
return $"{Size}_{Center.X}_{Center.Y}";
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)