Package io.github.ocelot.window.input
Class MouseHandler
java.lang.Object
io.github.ocelot.window.input.MouseHandler
- All Implemented Interfaces:
WindowEventListener
Tracks the mouse position, velocity, and pressed buttons. Also supports tracking the mouse while grabbed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcursorEntered(Window window, boolean entered) Called when the mouse enters or exists the window.doubledoubledoubledoubledoubledoublevoidGrabs the mouse by disabling it and moving it to the center of the window.voidIgnores the first movement velocity of the mouse.booleanisButtonPressed(int button) Checks if the specified mouse button is pressed.booleanvoidmouseMoved(Window window, double x, double y) Called when the mouse moves.voidmousePressed(Window window, int button, KeyMods mods) Called when a mouse button is pressed.voidmouseReleased(Window window, int button, KeyMods mods) Called when a mouse button is released.voidReleases the mouse and sets its position to the center of the window.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.ocelot.window.WindowEventListener
charTyped, filesDropped, focusChanged, framebufferResized, keyPressed, keyReleased, keyRepeated, mouseScrolled, windowClosed, windowMoved, windowResized
-
Constructor Details
-
MouseHandler
-
-
Method Details
-
mouseMoved
Description copied from interface:WindowEventListenerCalled when the mouse moves.- Specified by:
mouseMovedin interfaceWindowEventListener- Parameters:
window- The window that fired the eventx- The amount the mouse moved in the xy- The amount the mouse moved in the y
-
mousePressed
Description copied from interface:WindowEventListenerCalled when a mouse button is pressed.- Specified by:
mousePressedin interfaceWindowEventListener- Parameters:
window- The window that fired the eventbutton- The button that was pressed. Usually one of:
Standard Mouse Buttons MOUSE_BUTTON_LEFTMOUSE_BUTTON_RIGHTMOUSE_BUTTON_MIDDLEmods- The keyboard modifier flags set when the mouse button was pressed
-
mouseReleased
Description copied from interface:WindowEventListenerCalled when a mouse button is released.- Specified by:
mouseReleasedin interfaceWindowEventListener- Parameters:
window- The window that fired the eventbutton- The button that was released. Usually one of:
Standard Mouse Buttons MOUSE_BUTTON_LEFTMOUSE_BUTTON_RIGHTMOUSE_BUTTON_MIDDLEmods- The keyboard modifier flags set when the mouse button was released
-
cursorEntered
Description copied from interface:WindowEventListenerCalled when the mouse enters or exists the window.- Specified by:
cursorEnteredin interfaceWindowEventListener- Parameters:
window- The window that fired the evententered- 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
-