private void CheckButtonPressed(Func <MouseState, ButtonState> getButtonState, MouseButton button) { if (getButtonState(MouseState) != ButtonState.Pressed || getButtonState(_previousState) != ButtonState.Released) { return; } var args = new MouseEventArgs(_gameTime.TotalGameTime, _previousState, MouseState, button); MouseDown?.Invoke(this, args); _mouseDownArgs = args; if (_previousClickArgs == null) { return; } // If the last click was recent var clickMilliseconds = (args.Time - _previousClickArgs.Time).TotalMilliseconds; if (clickMilliseconds <= DoubleClickMilliseconds) { MouseDoubleClicked?.Invoke(this, args); _hasDoubleClicked = true; } _previousClickArgs = null; }
private void CheckButtonPressed(Func <MouseState, ButtonState> getButtonState, MouseButton button) { if ((getButtonState(_currentState) == ButtonState.Pressed) && (getButtonState(_previousState) == ButtonState.Released)) { var args = new MouseEventArgs(ViewportAdapter, _gameTime.TotalGameTime, _previousState, _currentState, button); MouseDown?.Invoke(this, args); _mouseDownArgs = args; if (_previousClickArgs != null) { // If the last click was recent var clickMilliseconds = (args.Time - _previousClickArgs.Time).TotalMilliseconds; if (clickMilliseconds <= DoubleClickMilliseconds) { MouseDoubleClicked?.Invoke(this, args); _hasDoubleClicked = true; } _previousClickArgs = null; } } }
private void _mouseListener_MouseDoubleClicked(object sender, MouseEventArgs e) { _scene?.FireMouseDoubleClick(e); MouseDoubleClicked?.Invoke(sender, e); #if DEBUG Logger.Log("Mouse double-clicked."); #endif }
protected virtual void OnMouseDoubleClicked() { MouseDoubleClicked?.Invoke(this, null); if (doubleClickingTogglesBenchmark) { plt.Benchmark(toggle: true); Render(); } }
public void MouseClickRelease(Vector2 position) { if (DateTime.Now - SecondMouseDownTime < TimeSpan.FromMilliseconds(150)) { MouseDoubleClicked?.Invoke(this, position); } else if (DateTime.Now - FirstMouseDownTime < TimeSpan.FromMilliseconds(150)) { MouseClicked?.Invoke(this, position); } }
public override void Dispose() { _aggregator.Unsubscribe(Entity); MouseEnter?.Dispose(); MouseLeave?.Dispose(); MouseMove?.Dispose(); MouseClicked?.Dispose(); MouseDoubleClicked?.Dispose(); MouseDown?.Dispose(); MouseUp?.Dispose(); LostFocus?.Dispose(); base.Dispose(); }
public void Start() { if (isRunning) { return; } Prepare(); isRunning = true; IntPtr handleIn = GetStdHandle(STD_INPUT_HANDLE); thread = new Thread( () => { while (true) { uint numRead = 0; INPUT_RECORD[] record = new INPUT_RECORD[1]; record[0] = new INPUT_RECORD(); ReadConsoleInput(handleIn, record, 1, ref numRead); if (isRunning) { switch (record[0].EventType) { case INPUT_RECORD.MOUSE_EVENT: var mouseEvent = record[0].MouseEvent; if (mouseEvent.dwButtonState == dwButtonStates.FROM_LEFT_1ST_BUTTON_PRESSED) { MouseClicked?.Invoke(this, CreateEventArgs(mouseEvent)); } if (mouseEvent.dwEventFlags == dwEventFlags.DOUBLE_CLICK) { MouseDoubleClicked?.Invoke(this, CreateEventArgs(mouseEvent)); } else if (mouseEvent.dwEventFlags == dwEventFlags.MOUSE_MOVED) { MouseMoved?.Invoke(this, CreateEventArgs(mouseEvent)); } else if (mouseEvent.dwEventFlags == dwEventFlags.MOUSE_HWHEELED || mouseEvent.dwEventFlags == dwEventFlags.MOUSE_WHEELED) { MouseWheelChanged?.Invoke(this, CreateEventArgs(mouseEvent)); } break; case INPUT_RECORD.KEY_EVENT: var keyEvent = record[0].KeyEvent; if (keyEvent.bKeyDown) { KeyDown?.Invoke(this, CreateEventArgs(keyEvent)); } break; case INPUT_RECORD.WINDOW_BUFFER_SIZE_EVENT: WindowBufferSizeEvent?.Invoke(record[0].WindowBufferSizeEvent); break; } } else { uint numWritten = 0; WriteConsoleInput(handleIn, record, 1, ref numWritten); return; } } }); thread.Start(); }
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); } } }
protected virtual void OnMouseDoubleClicked(MouseEventArgs e) { MouseDoubleClicked?.Invoke(this, e); }