-
-
Notifications
You must be signed in to change notification settings - Fork 911
/
MouseSimulated.cs
89 lines (71 loc) · 2.6 KB
/
MouseSimulated.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
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Collections.Generic;
using Stride.Core.Mathematics;
namespace Stride.Input
{
public class MouseSimulated : MouseDeviceBase
{
private bool positionLocked;
private Vector2 capturedPosition;
public MouseSimulated(InputSourceSimulated source)
{
Priority = -1000;
SetSurfaceSize(Vector2.One);
Source = source;
Id = Guid.NewGuid();
}
public override string Name => "Simulated Mouse";
public override Guid Id { get; }
public override bool IsPositionLocked => positionLocked;
public override IInputSource Source { get; }
public new MouseDeviceState MouseState => base.MouseState;
public new PointerDeviceState PointerState => base.PointerState;
public override void Update(List<InputEvent> inputEvents)
{
base.Update(inputEvents);
if (positionLocked)
{
MouseState.Position = capturedPosition;
PointerState.GetPointerData(0).Position = capturedPosition;
}
}
public void SimulateMouseDown(MouseButton button)
{
MouseState.HandleButtonDown(button);
}
public void SimulateMouseUp(MouseButton button)
{
MouseState.HandleButtonUp(button);
}
public void SimulateMouseWheel(float wheelDelta)
{
MouseState.HandleMouseWheel(wheelDelta);
}
public override void SetPosition(Vector2 position)
{
if (IsPositionLocked)
{
MouseState.HandleMouseDelta(position * SurfaceSize - capturedPosition);
}
else
{
MouseState.HandleMove(position * SurfaceSize);
}
}
public void SimulatePointer(PointerEventType pointerEventType, Vector2 position, int id = 0)
{
PointerState.PointerInputEvents.Add(new PointerDeviceState.InputEvent { Id = id, Position = position, Type = pointerEventType });
}
public override void LockPosition(bool forceCenter = false)
{
positionLocked = true;
capturedPosition = forceCenter ? new Vector2(0.5f) : Position;
}
public override void UnlockPosition()
{
positionLocked = false;
}
}
}