public void UpdateMouseInput() { if (_scheduleMouseWheelFocus != null) { if (_scheduleMouseWheelFocus.AcceptsMouseWheelFocus) { _previousMouseWheelFocus = FocusedMouseWheelWidget; FocusedMouseWheelWidget = _scheduleMouseWheelFocus; } _scheduleMouseWheelFocus = null; } if (MouseInfoGetter == null) { return; } var mouseInfo = MouseInfoGetter(); var mousePosition = mouseInfo.Position; if (SpriteBatchBeginParams.TransformMatrix != null) { // Apply transform var t = Vector2.Transform( new Vector2(mousePosition.X, mousePosition.Y), SpriteBatchBeginParams.InverseTransform); mousePosition = new Point((int)t.X, (int)t.Y); } MousePosition = mousePosition; HandleButton(mouseInfo.IsLeftButtonDown, _lastMouseInfo.IsLeftButtonDown, MouseButtons.Left); HandleButton(mouseInfo.IsMiddleButtonDown, _lastMouseInfo.IsMiddleButtonDown, MouseButtons.Middle); HandleButton(mouseInfo.IsRightButtonDown, _lastMouseInfo.IsRightButtonDown, MouseButtons.Right); #if STRIDE var handleWheel = mouseInfo.Wheel != 0; #else var handleWheel = mouseInfo.Wheel != _lastMouseInfo.Wheel; #endif if (handleWheel) { var delta = mouseInfo.Wheel; #if !STRIDE delta -= _lastMouseInfo.Wheel; #endif MouseWheelChanged.Invoke(delta); if (FocusedMouseWheelWidget != null) { FocusedMouseWheelWidget.OnMouseWheel(delta); } } _lastMouseInfo = mouseInfo; }
protected void FireMouseWheelChanged(float delta) { MouseWheelChanged?.Invoke(this, new GenericEventArgs <float>(delta)); }
public virtual void OnMouseWheel(float delta) { MouseWheelChanged.Invoke(this, delta); }
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(); }
public void UpdateInput() { if (MouseInfoGetter != null) { var mouseInfo = MouseInfoGetter(); var mousePosition = mouseInfo.Position; if (SpriteBatchBeginParams.TransformMatrix != null) { // Apply transform var t = Vector2.Transform( new Vector2(mousePosition.X, mousePosition.Y), SpriteBatchBeginParams.InverseTransform); mousePosition = new Point((int)t.X, (int)t.Y); } MousePosition = mousePosition; HandleButton(mouseInfo.IsLeftButtonDown, _lastMouseInfo.IsLeftButtonDown, MouseButtons.Left); HandleButton(mouseInfo.IsMiddleButtonDown, _lastMouseInfo.IsMiddleButtonDown, MouseButtons.Middle); HandleButton(mouseInfo.IsRightButtonDown, _lastMouseInfo.IsRightButtonDown, MouseButtons.Right); #if XENKO var handleWheel = mouseInfo.Wheel != 0; #else var handleWheel = mouseInfo.Wheel != _lastMouseInfo.Wheel; #endif if (handleWheel) { var delta = mouseInfo.Wheel; #if !XENKO delta -= _lastMouseInfo.Wheel; #endif MouseWheelChanged.Invoke(this, delta); if (FocusedMouseWheelWidget != null) { FocusedMouseWheelWidget.OnMouseWheel(delta); } } _lastMouseInfo = mouseInfo; } if (DownKeysGetter != null) { _downKeys = DownKeysGetter(); if (_downKeys != null && _lastDownKeys != null) { var now = DateTime.Now; foreach (var key in _downKeys) { if (!_lastDownKeys.Contains(key)) { KeyDownHandler?.Invoke(key); _lastKeyDown = now; _keyDownCount = 0; } } foreach (var key in _lastDownKeys) { if (!_downKeys.Contains(key)) { // Key had been released KeyUp.Invoke(this, key); if (_focusedKeyboardWidget != null && _focusedKeyboardWidget.Active) { _focusedKeyboardWidget.OnKeyUp(key); } _lastKeyDown = null; _keyDownCount = 0; } else if (_lastKeyDown != null && ((_keyDownCount == 0 && (now - _lastKeyDown.Value).TotalMilliseconds > RepeatKeyDownStartInMs) || (_keyDownCount > 0 && (now - _lastKeyDown.Value).TotalMilliseconds > RepeatKeyDownInternalInMs))) { KeyDownHandler?.Invoke(key); _lastKeyDown = now; ++_keyDownCount; } } } _lastDownKeys = _downKeys.ToArray(); } #if !XENKO try { UpdateTouch(); } catch (Exception) { } #endif }
private void onMouseWheelChanged(object sender, MouseWheelEventArgs e) { MouseWheelChanged?.Invoke(e); }