public void Init(GameWindow game) { if (_game != null) { return; } _game = game; this._originalOSCursor = _game.Cursor; game.MouseDown += (sender, e) => { if (isInputBlocked()) { return; } var button = convert(e.Button); _actions.Enqueue(() => MouseDown.InvokeAsync(new AGS.API.MouseButtonEventArgs(null, button, MousePosition))); }; game.MouseUp += (sender, e) => { if (isInputBlocked()) { return; } var button = convert(e.Button); _actions.Enqueue(() => MouseUp.InvokeAsync(new AGS.API.MouseButtonEventArgs(null, button, MousePosition))); }; game.MouseMove += (sender, e) => { if (isInputBlocked()) { return; } _mouseX = e.Mouse.X; _mouseY = e.Mouse.Y; _actions.Enqueue(() => MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition))); }; game.KeyDown += (sender, e) => { API.Key key = convert(e.Key); _keysDown.Add(key); if (isInputBlocked()) { return; } _actions.Enqueue(() => KeyDown.InvokeAsync(new KeyboardEventArgs(key))); }; game.KeyUp += (sender, e) => { API.Key key = convert(e.Key); _keysDown.Remove(key); if (isInputBlocked()) { return; } _actions.Enqueue(() => KeyUp.InvokeAsync(new KeyboardEventArgs(key))); }; _events.OnRepeatedlyExecuteAlways.Subscribe(onRepeatedlyExecute); }
private void init(GameWindow game) { if (_game != null) { return; } _game = game; _originalOSCursor = game.Cursor; _cursor.PropertyChanged += (sender, e) => { if (_cursor.Cursor != null) { _game.Cursor = MouseCursor.Empty; } }; game.MouseDown += (sender, e) => { if (isInputBlocked()) { return; } var button = convert(e.Button); _actions.Enqueue(() => MouseDown.InvokeAsync(new API.MouseButtonEventArgs(_hitTest.ObjectAtMousePosition, button, MousePosition))); }; game.MouseUp += (sender, e) => { if (isInputBlocked()) { return; } var button = convert(e.Button); _actions.Enqueue(() => MouseUp.InvokeAsync(new API.MouseButtonEventArgs(_hitTest.ObjectAtMousePosition, button, MousePosition))); }; game.MouseMove += (sender, e) => { _mouseX = e.Mouse.X; _mouseY = e.Mouse.Y; _actions.Enqueue(() => MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition))); }; game.KeyDown += (sender, e) => { API.Key key = convert(e.Key); _keysDown.Add(key); if (isInputBlocked()) { return; } _actions.Enqueue(() => KeyDown.InvokeAsync(new KeyboardEventArgs(key))); }; game.KeyUp += (sender, e) => { API.Key key = convert(e.Key); _keysDown.Remove(key); if (isInputBlocked()) { return; } _actions.Enqueue(() => KeyUp.InvokeAsync(new KeyboardEventArgs(key))); }; _events.OnRepeatedlyExecuteAlways.Subscribe(onRepeatedlyExecute); }
private async Task handleMouseButton(Stopwatch sw, Stopwatch doubleClickSw, bool wasDown, bool isDown, MouseButton button) { bool fireDown = !wasDown && isDown && IsMouseIn; bool fireDownOutside = !wasDown && isDown && !IsMouseIn && _isFocused; _isFocused = fireDown; bool fireUp = wasDown && !isDown; if (fireDown) { sw.Restart(); } bool fireClick = false; bool fireDoubleClick = false; if (fireUp) { if (IsMouseIn && sw.ElapsedMilliseconds < 1500 && sw.ElapsedMilliseconds != 0) { fireClick = true; if (doubleClickSw.ElapsedMilliseconds == 0) { doubleClickSw.Restart(); } else { if (doubleClickSw.ElapsedMilliseconds < 1500) { fireDoubleClick = true; } doubleClickSw.Stop(); doubleClickSw.Reset(); } } sw.Stop(); sw.Reset(); } if (fireDown || fireUp || fireClick || fireDownOutside) { MouseButtonEventArgs args = new MouseButtonEventArgs(button, _mouseX, _mouseY); if (fireDown) { await MouseDown.InvokeAsync(_entity, args); } else if (fireUp) { await MouseUp.InvokeAsync(_entity, args); } else if (fireDownOutside) { await LostFocus.InvokeAsync(_entity, args); } if (fireClick) { await MouseClicked.InvokeAsync(_entity, args); } if (fireDoubleClick) { await MouseDoubleClicked.InvokeAsync(_entity, args); } } }