Package de.gurkenlabs.litiengine.input
Class Mouse
java.lang.Object
de.gurkenlabs.litiengine.input.Mouse
- All Implemented Interfaces:
IMouse
,IUpdateable
,java.awt.event.MouseListener
,java.awt.event.MouseMotionListener
,java.awt.event.MouseWheelListener
,java.util.EventListener
public final class Mouse
extends java.lang.Object
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, IMouse, IUpdateable
This implementation provides information about the mouse input in the LITIENGINE.
Nested Class Summary
Nested classes/interfaces inherited from interface de.gurkenlabs.litiengine.input.IMouse
IMouse.MouseClickedListener, IMouse.MouseDraggedListener, IMouse.MouseMovedListener, IMouse.MousePressedListener, IMouse.MousePressingListener, IMouse.MouseReleasedListener
Method Summary
Modifier and Type Method Description void
addMouseListener(java.awt.event.MouseListener listener)
Register mouse listener.void
addMouseMotionListener(java.awt.event.MouseMotionListener listener)
Register mouse motion listener.void
clearExplicitListeners()
Removes all registered event listeners from the Mouse instance.java.awt.geom.Point2D
getLocation()
Gets the current location of the mouse within the game window.java.awt.geom.Point2D
getMapLocation()
Gets the location of the mouse on the current map.java.awt.Point
getTile()
Gets the coordinates of the tile on the map on which the mouse is currently located at.boolean
isGrabMouse()
A flag indicating whether the mouse should be grabbed by the game's window.boolean
isLeftButton(java.awt.event.MouseEvent event)
Returns true if the mouse event specifies the left mouse button.boolean
isLeftButtonPressed()
A flag indicating whether the left mouse button is currently pressed.boolean
isPressed()
A flag indicating whether any mouse button is currently pressed.boolean
isRightButton(java.awt.event.MouseEvent event)
Returns true if the mouse event specifies the right mouse button.boolean
isRightButtonPressed()
A flag indicating whether the right mouse button is currently pressed.void
mouseClicked(java.awt.event.MouseEvent e)
void
mouseDragged(java.awt.event.MouseEvent e)
void
mouseEntered(java.awt.event.MouseEvent e)
void
mouseExited(java.awt.event.MouseEvent e)
void
mouseMoved(java.awt.event.MouseEvent e)
void
mousePressed(java.awt.event.MouseEvent e)
void
mouseReleased(java.awt.event.MouseEvent e)
void
mouseWheelMoved(java.awt.event.MouseWheelEvent e)
void
onClicked(IMouse.MouseClickedListener listener)
Adds the specified mouse clicked listener to receive events when the mouse has been clicked.void
onDragged(IMouse.MouseDraggedListener listener)
Adds the specified mouse dragged listener to receive events when the mouse has been dragged.void
onMoved(IMouse.MouseMovedListener listener)
Adds the specified mouse moved listener to receive events when the mouse has been moved.void
onPressed(IMouse.MousePressedListener listener)
Adds the specified mouse pressed listener to receive events when the mouse has been pressed.void
onPressing(IMouse.MousePressingListener listener)
Adds the specified mouse pressing listener to receive continuous events while the mouse is being pressed.void
onReleased(IMouse.MouseReleasedListener listener)
Adds the specified mouse released listener to receive events when the mouse has been released.void
onWheelMoved(java.awt.event.MouseWheelListener listener)
Adds the specified mouse wheel listener to receive events when the mouse wheel has been moved.void
removeMouseClickedListener(IMouse.MouseClickedListener listener)
Unregisters the specified mouse clicked listener.void
removeMouseDraggedListener(IMouse.MouseDraggedListener listener)
Unregisters the specified mouse dragged listener.void
removeMouseListener(java.awt.event.MouseListener listener)
Unregister mouse listener.void
removeMouseMotionListener(java.awt.event.MouseMotionListener listener)
Unregister mouse motion listener.void
removeMouseMovedListener(IMouse.MouseMovedListener listener)
Unregisters the specified mouse moved listener.void
removeMousePressedListener(IMouse.MousePressedListener listener)
Unregisters the specified mouse pressed listener.void
removeMousePressingListener(IMouse.MousePressingListener listener)
Unregisters the specified mouse pressing listener.void
removeMouseReleasedListener(IMouse.MouseReleasedListener listener)
Unregisters the specified mouse released listener.void
removeMouseWheelListener(java.awt.event.MouseWheelListener listener)
Unregisters the specified mouse wheel listener.void
setGrabMouse(boolean grab)
If set to true, the mouse will be locked to the render component of the game.void
setLocation(double x, double y)
Sets the current mouse location to the specified location in the game window.void
setLocation(java.awt.geom.Point2D adjustMouse)
Sets the current mouse location to the specified location in the game window.void
update()
This method is called by the game loop on all objects that are attached to the loop.
Method Details
update
public void update()Description copied from interface:IUpdateable
This method is called by the game loop on all objects that are attached to the loop. It's called on every tick of the loop and the frequency can be configured using theClientConfiguration
.- Specified by:
update
in interfaceIUpdateable
- See Also:
ClientConfiguration.setMaxFps(int)
getLocation
public java.awt.geom.Point2D getLocation()Description copied from interface:IMouse
Gets the current location of the mouse within the game window.The coordinates are relative to the game window and don't reflect coordinates on the game world.
UseIMouse.getMapLocation()
to get a translated position for the current environment.- Specified by:
getLocation
in interfaceIMouse
- Returns:
- The current location of the mouse within the game window.
- See Also:
IMouse.getMapLocation()
getMapLocation
public java.awt.geom.Point2D getMapLocation()Description copied from interface:IMouse
Gets the location of the mouse on the current map.This translates the current mouse locations to the location on the map by using the current camera.
UseIMouse.getLocation()
to get the location within the game window.- Specified by:
getMapLocation
in interfaceIMouse
- Returns:
- The location of the mouse on the current map.
- See Also:
IMouse.getLocation()
getTile
public java.awt.Point getTile()Description copied from interface:IMouse
Gets the coordinates of the tile on the map on which the mouse is currently located at.isGrabMouse
public boolean isGrabMouse()Description copied from interface:IMouse
A flag indicating whether the mouse should be grabbed by the game's window.- Specified by:
isGrabMouse
in interfaceIMouse
- Returns:
- True if the mouse is locked to the game window; otherwise false.
isLeftButtonPressed
public boolean isLeftButtonPressed()Description copied from interface:IMouse
A flag indicating whether the left mouse button is currently pressed.- Specified by:
isLeftButtonPressed
in interfaceIMouse
- Returns:
- True if the left mouse button is currently pressed; otherwise false.
isPressed
public boolean isPressed()Description copied from interface:IMouse
A flag indicating whether any mouse button is currently pressed.isRightButtonPressed
public boolean isRightButtonPressed()Description copied from interface:IMouse
A flag indicating whether the right mouse button is currently pressed.- Specified by:
isRightButtonPressed
in interfaceIMouse
- Returns:
- True if the right mouse button is currently pressed; otherwise false.
isLeftButton
public boolean isLeftButton(java.awt.event.MouseEvent event)Description copied from interface:IMouse
Returns true if the mouse event specifies the left mouse button.- Specified by:
isLeftButton
in interfaceIMouse
- Parameters:
event
- The MouseEvent object- Returns:
- true if the left mouse button was active.
isRightButton
public boolean isRightButton(java.awt.event.MouseEvent event)Description copied from interface:IMouse
Returns true if the mouse event specifies the right mouse button.- Specified by:
isRightButton
in interfaceIMouse
- Parameters:
event
- The MouseEvent object- Returns:
- true if the right mouse button was active.
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)- Specified by:
mouseClicked
in interfacejava.awt.event.MouseListener
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)- Specified by:
mouseDragged
in interfacejava.awt.event.MouseMotionListener
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)- Specified by:
mouseEntered
in interfacejava.awt.event.MouseListener
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)- Specified by:
mouseExited
in interfacejava.awt.event.MouseListener
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)- Specified by:
mouseMoved
in interfacejava.awt.event.MouseMotionListener
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)- Specified by:
mousePressed
in interfacejava.awt.event.MouseListener
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)- Specified by:
mouseReleased
in interfacejava.awt.event.MouseListener
mouseWheelMoved
public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)- Specified by:
mouseWheelMoved
in interfacejava.awt.event.MouseWheelListener
onClicked
Description copied from interface:IMouse
Adds the specified mouse clicked listener to receive events when the mouse has been clicked.removeMouseClickedListener
Description copied from interface:IMouse
Unregisters the specified mouse clicked listener.- Specified by:
removeMouseClickedListener
in interfaceIMouse
- Parameters:
listener
- The listener to remove.
onDragged
Description copied from interface:IMouse
Adds the specified mouse dragged listener to receive events when the mouse has been dragged.- Specified by:
onDragged
in interfaceIMouse
- Parameters:
listener
- The listener to add.- See Also:
IMouse.MouseDraggedListener.mouseDragged(MouseEvent)
,MouseMotionListener.mouseDragged(MouseEvent)
,MouseEvent.MOUSE_DRAGGED
removeMouseDraggedListener
Description copied from interface:IMouse
Unregisters the specified mouse dragged listener.- Specified by:
removeMouseDraggedListener
in interfaceIMouse
- Parameters:
listener
- The listener to remove.
onMoved
Description copied from interface:IMouse
Adds the specified mouse moved listener to receive events when the mouse has been moved.removeMouseMovedListener
Description copied from interface:IMouse
Unregisters the specified mouse moved listener.- Specified by:
removeMouseMovedListener
in interfaceIMouse
- Parameters:
listener
- The listener to remove.
onPressed
Description copied from interface:IMouse
Adds the specified mouse pressed listener to receive events when the mouse has been pressed.removeMousePressedListener
Description copied from interface:IMouse
Unregisters the specified mouse pressed listener.- Specified by:
removeMousePressedListener
in interfaceIMouse
- Parameters:
listener
- The listener to remove.
onPressing
Description copied from interface:IMouse
Adds the specified mouse pressing listener to receive continuous events while the mouse is being pressed.- Specified by:
onPressing
in interfaceIMouse
- Parameters:
listener
- The listener to add.
removeMousePressingListener
Description copied from interface:IMouse
Unregisters the specified mouse pressing listener.- Specified by:
removeMousePressingListener
in interfaceIMouse
- Parameters:
listener
- The listener to remove.
onReleased
Description copied from interface:IMouse
Adds the specified mouse released listener to receive events when the mouse has been released.- Specified by:
onReleased
in interfaceIMouse
- Parameters:
listener
- The listener to add.- See Also:
MouseListener.mouseReleased(MouseEvent)
,MouseEvent.MOUSE_RELEASED
removeMouseReleasedListener
Description copied from interface:IMouse
Unregisters the specified mouse released listener.- Specified by:
removeMouseReleasedListener
in interfaceIMouse
- Parameters:
listener
- The listener to remove.
onWheelMoved
public void onWheelMoved(java.awt.event.MouseWheelListener listener)Description copied from interface:IMouse
Adds the specified mouse wheel listener to receive events when the mouse wheel has been moved.- Specified by:
onWheelMoved
in interfaceIMouse
- Parameters:
listener
- The listener to add.- See Also:
MouseWheelListener.mouseWheelMoved(java.awt.event.MouseWheelEvent)
,MouseWheelEvent
removeMouseWheelListener
public void removeMouseWheelListener(java.awt.event.MouseWheelListener listener)Description copied from interface:IMouse
Unregisters the specified mouse wheel listener.- Specified by:
removeMouseWheelListener
in interfaceIMouse
- Parameters:
listener
- The listener to remove.
addMouseListener
public void addMouseListener(java.awt.event.MouseListener listener)Description copied from interface:IMouse
Register mouse listener.- Specified by:
addMouseListener
in interfaceIMouse
- Parameters:
listener
- the listener
removeMouseListener
public void removeMouseListener(java.awt.event.MouseListener listener)Description copied from interface:IMouse
Unregister mouse listener.- Specified by:
removeMouseListener
in interfaceIMouse
- Parameters:
listener
- the listener
addMouseMotionListener
public void addMouseMotionListener(java.awt.event.MouseMotionListener listener)Description copied from interface:IMouse
Register mouse motion listener.- Specified by:
addMouseMotionListener
in interfaceIMouse
- Parameters:
listener
- the listener
removeMouseMotionListener
public void removeMouseMotionListener(java.awt.event.MouseMotionListener listener)Description copied from interface:IMouse
Unregister mouse motion listener.- Specified by:
removeMouseMotionListener
in interfaceIMouse
- Parameters:
listener
- the listener
clearExplicitListeners
public void clearExplicitListeners()Description copied from interface:IMouse
Removes all registered event listeners from the Mouse instance. This does not affect registeredMouseListener
,MouseMotionListener
orMouseWheelListener
instances.- Specified by:
clearExplicitListeners
in interfaceIMouse
- See Also:
IMouse.onClicked(MouseClickedListener)
,IMouse.onDragged(MouseDraggedListener)
,IMouse.onMoved(MouseMovedListener)
,IMouse.onPressed(MousePressedListener)
,IMouse.onPressing(MousePressingListener)
,IMouse.onReleased(MouseReleasedListener)
setGrabMouse
public void setGrabMouse(boolean grab)Description copied from interface:IMouse
If set to true, the mouse will be locked to the render component of the game.If this is set to true, the default cursor cannot be used anymore and instead a virtual cursor should be set.
- Specified by:
setGrabMouse
in interfaceIMouse
- Parameters:
grab
- True if the mouse should be grabbed to the game's window, otherwise false.- See Also:
MouseCursor.set(java.awt.Image)
,GameWindow.cursor()
,Game.window()
setLocation
public void setLocation(java.awt.geom.Point2D adjustMouse)Description copied from interface:IMouse
Sets the current mouse location to the specified location in the game window.The location is not a location on the map but a location relative to the game window.
- Specified by:
setLocation
in interfaceIMouse
- Parameters:
adjustMouse
- The location to which the mouse will be moved.- See Also:
IMouse.getLocation()
setLocation
public void setLocation(double x, double y)Description copied from interface:IMouse
Sets the current mouse location to the specified location in the game window.The location is not a location on the map but a location relative to the game window.
- Specified by:
setLocation
in interfaceIMouse
- Parameters:
x
- The x-coordinate to which the mouse will be moved.y
- The y-coordinate to which the mouse will be moved.- See Also:
IMouse.getLocation()