Class MouseHandler

java.lang.Object
io.github.ocelot.window.input.MouseHandler
All Implemented Interfaces:
WindowEventListener

public class MouseHandler extends Object implements WindowEventListener
Tracks the mouse position, velocity, and pressed buttons. Also supports tracking the mouse while grabbed.
  • Constructor Details

    • MouseHandler

      public MouseHandler(Window window)
  • Method Details

    • mouseMoved

      public void mouseMoved(Window window, double x, double y)
      Description copied from interface: WindowEventListener
      Called when the mouse moves.
      Specified by:
      mouseMoved in interface WindowEventListener
      Parameters:
      window - The window that fired the event
      x - The amount the mouse moved in the x
      y - The amount the mouse moved in the y
    • mousePressed

      public void mousePressed(Window window, int button, KeyMods mods)
      Description copied from interface: WindowEventListener
      Called when a mouse button is pressed.
      Specified by:
      mousePressed in interface WindowEventListener
      Parameters:
      window - The window that fired the event
      button - The button that was pressed. Usually one of:
      Standard Mouse Buttons
      MOUSE_BUTTON_LEFT MOUSE_BUTTON_RIGHT MOUSE_BUTTON_MIDDLE
      mods - The keyboard modifier flags set when the mouse button was pressed
    • mouseReleased

      public void mouseReleased(Window window, int button, KeyMods mods)
      Description copied from interface: WindowEventListener
      Called when a mouse button is released.
      Specified by:
      mouseReleased in interface WindowEventListener
      Parameters:
      window - The window that fired the event
      button - The button that was released. Usually one of:
      Standard Mouse Buttons
      MOUSE_BUTTON_LEFT MOUSE_BUTTON_RIGHT MOUSE_BUTTON_MIDDLE
      mods - The keyboard modifier flags set when the mouse button was released
    • cursorEntered

      public void cursorEntered(Window window, boolean entered)
      Description copied from interface: WindowEventListener
      Called when the mouse enters or exists the window.
      Specified by:
      cursorEntered in interface WindowEventListener
      Parameters:
      window - The window that fired the event
      entered - Whether the cursor entered or left the window
    • grabMouse

      public void grabMouse()
      Grabs the mouse by disabling it and moving it to the center of the window.
    • releaseMouse

      public void releaseMouse()
      Releases the mouse and sets its position to the center of the window.
    • ignoreFirstMovement

      public void ignoreFirstMovement()
      Ignores the first movement velocity of the mouse.
    • isButtonPressed

      public boolean isButtonPressed(int button)
      Checks if the specified mouse button is pressed.
      Parameters:
      button - The button to check
      Returns:
      Whether that button is pressed
    • getMouseX

      public double getMouseX()
      Returns:
      The x position of the mouse
    • getMouseY

      public double getMouseY()
      Returns:
      The y position of the mouse
    • getMouseDX

      public double getMouseDX()
      Returns:
      The x velocity of the mouse
    • getMouseDY

      public double getMouseDY()
      Returns:
      The y velocity of the mouse
    • isMouseGrabbed

      public boolean isMouseGrabbed()
      Returns:
      Whether the mouse is disabled and not currently visible
    • getAccumulatedDX

      public double getAccumulatedDX()
      Returns:
      The total x motion of the mouse since the last query if grabbed
    • getAccumulatedDY

      public double getAccumulatedDY()
      Returns:
      The total y motion of the mouse since the last query if grabbed