public static void GUIEvents() { var current = Event.current; switch (current.type) { case EventType.MouseDown: if (mouseDownEvent != null) { mouseDownEvent.Invoke(); } break; case EventType.MouseDrag: if (mouseDragEvent != null) { mouseDragEvent.Invoke(); } break; case EventType.MouseUp: if (mouseUpEvent != null) { mouseUpEvent.Invoke(); } break; } }
internal void MouseDrag(MouseEventArgs e) { OnMouseDragged?.Invoke(e); }
public void Update() { #region Keybaord KeyboardState keyboardState = Keyboard.GetState(); Keys[] keyPressed = keyboardState.GetPressedKeys(); IEnumerable <Keys> keyJustPressed = keyPressed.Where(key => !_pressedKeys.Any(k => k == key)); foreach (Keys key in keyJustPressed) { OnKeyDown?.Invoke(null, key); } IEnumerable <Keys> keyJustUpped = _pressedKeys.Where(key => !keyPressed.Any(k => k == key)); foreach (Keys key in keyJustUpped) { OnKeyUp?.Invoke(null, key); } _pressedKeys = keyPressed; #endregion Keybaord #region Mouse MouseState mouseState = Mouse.GetState(); if (mouseState.LeftButton != _previousLeftButtonState) { _previousLeftButtonState = mouseState.LeftButton; if (_previousLeftButtonState == ButtonState.Pressed) { OnMouseButtonDown?.Invoke(this, mouseState); } else { OnMouseButtonUp?.Invoke(this, mouseState); } } if (mouseState.RightButton != _previousRightButtonState) { _previousRightButtonState = mouseState.RightButton; if (_previousRightButtonState == ButtonState.Pressed) { OnMouseButtonDown?.Invoke(this, mouseState); } else { OnMouseButtonUp?.Invoke(this, mouseState); } } if (mouseState.ScrollWheelValue != _previousScrollValue) { if (mouseState.ScrollWheelValue < _previousScrollValue) { OnMouseWheelUp?.Invoke(this, mouseState); } else { OnMouseWheelDown?.Invoke(this, mouseState); } _previousScrollValue = mouseState.ScrollWheelValue; } if (mouseState.Position != _previousMousePosition) { OnMouseMoved?.Invoke(this, mouseState); if (mouseState.LeftButton == ButtonState.Pressed) { OnMouseDragged?.Invoke(this, mouseState); } } _previousMousePosition = mouseState.Position; #endregion Mouse }