internal bool HandledMouseScroll() { if (!Visible || !enabled) { return(false); } for (var index = children.Count - 1; index >= 0; --index) { if (children[index].HandledMouseScroll()) { return(true); } } if (!RegisterEventTypes.HasFlag(EventType.MouseScroll) || !MouseDirectlyOver) { return(false); } OnMouseScroll(); MouseScrolled?.Invoke(this, EventArgs.Empty); return(true); }
private static void OnMouseScrolled(Screen s, MouseScrollEvent e) { MouseScrolled?.Invoke(s, e); }
/// <summary> /// Determines the input into the simulation. /// </summary> protected void GetInput() { MouseState mouseState = Mouse.GetState(); if (LeftMouseButtonPressed) { // Left button pressed if (mouseState.LeftButton != lastMouseState.LeftButton) { // Left button just pressed LeftMouseButtonJustPressed?.Invoke(this, new EventArgs()); } } else { // Left button not pressed if (mouseState.LeftButton != lastMouseState.LeftButton) { // Left button just released LeftMouseButtonJustReleased?.Invoke(this, new EventArgs()); } } if (RightMouseButtonPressed) { // Right button pressed if (mouseState.RightButton != lastMouseState.RightButton) { // Right button just pressed RightMouseButtonJustPressed?.Invoke(this, new EventArgs()); } } else { // Right button not pressed if (mouseState.RightButton != lastMouseState.RightButton) { // Right button just released RightMouseButtonJustReleased?.Invoke(this, new EventArgs()); } } if (MiddleMouseButtonPressed) { // Middle button pressed if (mouseState.MiddleButton != lastMouseState.MiddleButton) { // Middle button just pressed MiddleMouseButtonJustPressed?.Invoke(this, new EventArgs()); } } else { // Middle button not pressed if (mouseState.MiddleButton != lastMouseState.MiddleButton) { // Middle button just released MiddleMouseButtonJustReleased?.Invoke(this, new EventArgs()); } } // Scrolling int newMouseScroll = mouseState.ScrollWheelValue; // Mouse wheel up if (newMouseScroll > lastMouseState.ScrollWheelValue) { MouseScrolled?.Invoke(this, new MouseScrollArgs(MouseScrollDiretion.Up)); } // Mouse wheel down else if (newMouseScroll < lastMouseState.ScrollWheelValue) { MouseScrolled?.Invoke(this, new MouseScrollArgs(MouseScrollDiretion.Down)); } // Left button hold if (LeftMouseButtonPressed) { if (lastMouseState.LeftButton == ButtonState.Pressed) { if (IsObjectSelected && SelectedObject is IMovable movable && movable.Movable) { // Check for mouse movement if (mouseState.Position != lastMouseState.Position) { // Move object Vector2 mouseMovement = mouseState.Position.ToVector2() - lastMouseState.Position.ToVector2(); objectMoving = true; movable.Moving = true; movable.Move(mouseMovement / Camera.Zoom); } else { movable.Moving = false; } } } } // Middle button hold if (MiddleMouseButtonPressed && !LeftMouseButtonPressed) { if (lastMouseState.MiddleButton == ButtonState.Pressed) { // Check for mouse movement if (mouseState.Position != lastMouseState.Position) { // Move camera Vector2 mouseMovement = mouseState.Position.ToVector2() - lastMouseState.Position.ToVector2(); Camera.Pan(mouseMovement); } } } // Reset relative mouse state lastMouseState = mouseState; }
//this gets called by GLFW (unmanaged code) private void MouseCallback(int btn, int action, int mods) { //scroll (3 was chosen by me, not glfw) if (btn == 3) { MouseScrolled.Invoke(action, this); MouseScrollDirection = action; return; } //left click if (btn == 0 && action == 1) { if (leftLifted) { MouseLeftClick.Invoke(MousePosition, this); MouseLeftClickScaled.Invoke(MousePositionScaled, this); iLastLeft = MousePosition; leftClickToggle = true; } leftLifted = false; } if (btn == 0 && action == 0) { leftLifted = true; MouseLeftRelease.Invoke(MousePosition, this); MouseLeftReleaseScaled.Invoke(MousePositionScaled, this); return; } //right click if (btn == 1 && action == 1) { if (rightLifted) { MouseRightClick.Invoke(MousePosition, this); MouseRightClickScaled.Invoke(MousePositionScaled, this); iLastRight = MousePosition; rightClickToggle = true; } rightLifted = false; return; } if (btn == 1 && action == 0) { rightLifted = true; MouseRightRelease.Invoke(MousePosition, this); MouseRightReleaseScaled.Invoke(MousePositionScaled, this); return; } //middle click if (btn == 2 && action == 1) { if (middleLifted) { MouseMiddleClick.Invoke(MousePosition, this); MouseMiddleClickScaled.Invoke(MousePositionScaled, this); } middleLifted = false; return; } if (btn == 2 && action == 0) { middleLifted = true; MouseMiddleRelease.Invoke(MousePosition, this); MouseMiddleReleaseScaled.Invoke(MousePositionScaled, this); return; } }
private void OnMouseScrolled(IMouse mouse, ScrollWheel scrollWheel) { MouseScrolled?.Invoke(mouse, new Vector2(scrollWheel.X, scrollWheel.Y)); }
public override void OnMouseScrolled(object sender, EventArgs args) { base.OnMouseScrolled(sender, args); MouseScrolled?.Invoke(sender, args); }