12public sealed class MouseEventPoller : IDisposable
19 public static MouseEventPoller?
Instance {
get;
private set; }
38 ArgumentNullException.ThrowIfNull(adapter);
40 if (mouseEventConfiguration ==
null)
43 trackMouseMovement:
true,
48 Instance =
new MouseEventPoller(adapter, mouseEventConfiguration);
67 private readonly Dictionary<MouseButton, MouseButtonState> _buttonStates =
new();
68 private Point _lastPosition =
new(0, 0);
69 private int _lastScrollDelta;
70 private bool _isDisposed;
106 public IReadOnlyDictionary<MouseButton, MouseButtonState>
ButtonStates => _buttonStates;
149 internal void PollForEvents(
long tick)
158 bool anyButtonChange =
false;
159 bool isAnyButtonDown =
false;
162 foreach (var kvp
in _buttonStates.ToList())
164 var button = kvp.Key;
165 var state = kvp.Value;
167 bool isCurrentlyDown = pressed.Contains(button);
168 bool justPressed = isCurrentlyDown && !state.IsDown;
169 bool justReleased = !isCurrentlyDown && state.IsDown;
171 state.JustPressed = justPressed;
172 state.JustReleased = justReleased;
173 state.IsDown = isCurrentlyDown;
175 anyButtonChange |= justPressed || justReleased;
176 _buttonStates[button] = state;
179 isAnyButtonDown =
true;
183 bool moved = (
Configuration?.TrackMouseMovement ??
false) && _lastPosition != currentPos;
186 bool scrolled = scrollDelta != 0;
187 _lastScrollDelta = scrollDelta;
189 if (anyButtonChange || moved || scrolled || isAnyButtonDown)
200 _lastPosition = currentPos;
226 public void StartMonitoringMouse(
bool trackMouseMovement =
true,
double timeBetweenEvents = -1,
bool isPaused =
false)
228 if (timeBetweenEvents < 0)
245 if (_isDisposed)
return;
251 if (ReferenceEquals(
Instance,
this))
Represents the core game engine singleton responsible for managing the main update loop,...
static Engine Instance
Gets the singleton instance of the Engine.
EngineConfiguration Configuration
Gets the current engine configuration settings.