-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTouchpadContact.cs
55 lines (45 loc) · 1.42 KB
/
TouchpadContact.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RawInput.Touchpad
{
public struct TouchpadContact : IEquatable<TouchpadContact>
{
public int ContactId { get; }
public int X { get; }
public int Y { get; }
public TouchpadContact(int contactId, int x, int y) =>
(this.ContactId, this.X, this.Y) = (contactId, x, y);
public override bool Equals(object obj) => (obj is TouchpadContact other) && Equals(other);
public bool Equals(TouchpadContact other) =>
(this.ContactId == other.ContactId) && (this.X == other.X) && (this.Y == other.Y);
public static bool operator ==(TouchpadContact a, TouchpadContact b) => a.Equals(b);
public static bool operator !=(TouchpadContact a, TouchpadContact b) => !(a == b);
public override int GetHashCode() => (this.ContactId, this.X, this.Y).GetHashCode();
public override string ToString() => $"Contact ID:{ContactId} Point:{X},{Y}";
}
internal class TouchpadContactCreator
{
public int? ContactId { get; set; }
public int? X { get; set; }
public int? Y { get; set; }
public bool TryCreate(out TouchpadContact contact)
{
if (ContactId.HasValue && X.HasValue && Y.HasValue)
{
contact = new TouchpadContact(ContactId.Value, X.Value, Y.Value);
return true;
}
contact = default;
return false;
}
public void Clear()
{
ContactId = null;
X = null;
Y = null;
}
}
}