-
Notifications
You must be signed in to change notification settings - Fork 1
/
NiceTouchForwarder.InterpreterWithGestureTouches.cs
64 lines (55 loc) · 2.21 KB
/
NiceTouchForwarder.InterpreterWithGestureTouches.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
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NiceTouch.GestureReceiving;
namespace NiceTouch
{
public partial class NiceTouchForwarder
{
class InterpreterWithGestureTouchesPool
{
readonly Queue<InterpreterWithGestureTouches> _pool = new Queue<InterpreterWithGestureTouches>();
public readonly List<InterpreterWithGestureTouches> UsersWithTouches = new List<InterpreterWithGestureTouches>();
public void RefreshPool()
{
foreach (InterpreterWithGestureTouches u in UsersWithTouches)
{
_pool.Enqueue(u);
}
UsersWithTouches.Clear();
}
public InterpreterWithGestureTouches New(IGestureInterpreter interpreter)
{
InterpreterWithGestureTouches interpreterWithGestureTouches;
if (_pool.Count == 0)
{
interpreterWithGestureTouches = new InterpreterWithGestureTouches(interpreter, new List<Touch>());
}
else
{
interpreterWithGestureTouches = _pool.Dequeue();
interpreterWithGestureTouches.Replace(interpreter);
}
return interpreterWithGestureTouches;
}
}
class InterpreterWithGestureTouches
{
public InterpreterWithGestureTouches(IGestureInterpreter interpreter, List<Touch> touches)
{
Interpreter = interpreter;
Touches = touches;
}
public void Replace(IGestureInterpreter interpreter)
{
Interpreter = interpreter;
Touches.Clear();
}
public IGestureInterpreter Interpreter { get; private set; }
public List<Touch> Touches { get; }
// need to duplicate this list as it will be recycled and modified in the InterpreterWithGestureTouches pool
public List<Touch> TouchListCopy => Touches.ToList();
public bool JustOneTouch => Touches.Count == 1;
}
}
}