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.
  • 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 the ClientConfiguration.
      Specified by:
      update in interface IUpdateable
      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.
      Use IMouse.getMapLocation() to get a translated position for the current environment.

      Specified by:
      getLocation in interface IMouse
      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.
      Use IMouse.getLocation() to get the location within the game window.

      Specified by:
      getMapLocation in interface IMouse
      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.
      Specified by:
      getTile in interface IMouse
      Returns:
      The tile 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 interface IMouse
      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 interface IMouse
      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.
      Specified by:
      isPressed in interface IMouse
      Returns:
      True if any mouse button is currently pressed; otherwise false.
    • isRightButtonPressed

      public boolean isRightButtonPressed()
      Description copied from interface: IMouse
      A flag indicating whether the right mouse button is currently pressed.
      Specified by:
      isRightButtonPressed in interface IMouse
      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 interface IMouse
      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 interface IMouse
      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 interface java.awt.event.MouseListener
    • mouseDragged

      public void mouseDragged​(java.awt.event.MouseEvent e)
      Specified by:
      mouseDragged in interface java.awt.event.MouseMotionListener
    • mouseEntered

      public void mouseEntered​(java.awt.event.MouseEvent e)
      Specified by:
      mouseEntered in interface java.awt.event.MouseListener
    • mouseExited

      public void mouseExited​(java.awt.event.MouseEvent e)
      Specified by:
      mouseExited in interface java.awt.event.MouseListener
    • mouseMoved

      public void mouseMoved​(java.awt.event.MouseEvent e)
      Specified by:
      mouseMoved in interface java.awt.event.MouseMotionListener
    • mousePressed

      public void mousePressed​(java.awt.event.MouseEvent e)
      Specified by:
      mousePressed in interface java.awt.event.MouseListener
    • mouseReleased

      public void mouseReleased​(java.awt.event.MouseEvent e)
      Specified by:
      mouseReleased in interface java.awt.event.MouseListener
    • mouseWheelMoved

      public void mouseWheelMoved​(java.awt.event.MouseWheelEvent e)
      Specified by:
      mouseWheelMoved in interface java.awt.event.MouseWheelListener
    • onClicked

      public void onClicked​(IMouse.MouseClickedListener listener)
      Description copied from interface: IMouse
      Adds the specified mouse clicked listener to receive events when the mouse has been clicked.
      Specified by:
      onClicked in interface IMouse
      Parameters:
      listener - The listener to add.
      See Also:
      MouseListener.mouseClicked(MouseEvent), MouseEvent.MOUSE_CLICKED
    • removeMouseClickedListener

      public void removeMouseClickedListener​(IMouse.MouseClickedListener listener)
      Description copied from interface: IMouse
      Unregisters the specified mouse clicked listener.
      Specified by:
      removeMouseClickedListener in interface IMouse
      Parameters:
      listener - The listener to remove.
    • onDragged

      public void onDragged​(IMouse.MouseDraggedListener listener)
      Description copied from interface: IMouse
      Adds the specified mouse dragged listener to receive events when the mouse has been dragged.
      Specified by:
      onDragged in interface IMouse
      Parameters:
      listener - The listener to add.
      See Also:
      IMouse.MouseDraggedListener.mouseDragged(MouseEvent), MouseMotionListener.mouseDragged(MouseEvent), MouseEvent.MOUSE_DRAGGED
    • removeMouseDraggedListener

      public void removeMouseDraggedListener​(IMouse.MouseDraggedListener listener)
      Description copied from interface: IMouse
      Unregisters the specified mouse dragged listener.
      Specified by:
      removeMouseDraggedListener in interface IMouse
      Parameters:
      listener - The listener to remove.
    • onMoved

      public void onMoved​(IMouse.MouseMovedListener listener)
      Description copied from interface: IMouse
      Adds the specified mouse moved listener to receive events when the mouse has been moved.
      Specified by:
      onMoved in interface IMouse
      Parameters:
      listener - The listener to add.
      See Also:
      MouseMotionListener.mouseMoved(MouseEvent), MouseEvent.MOUSE_MOVED
    • removeMouseMovedListener

      public void removeMouseMovedListener​(IMouse.MouseMovedListener listener)
      Description copied from interface: IMouse
      Unregisters the specified mouse moved listener.
      Specified by:
      removeMouseMovedListener in interface IMouse
      Parameters:
      listener - The listener to remove.
    • onPressed

      public void onPressed​(IMouse.MousePressedListener listener)
      Description copied from interface: IMouse
      Adds the specified mouse pressed listener to receive events when the mouse has been pressed.
      Specified by:
      onPressed in interface IMouse
      Parameters:
      listener - The listener to add.
      See Also:
      MouseListener.mousePressed(MouseEvent), MouseEvent.MOUSE_PRESSED
    • removeMousePressedListener

      public void removeMousePressedListener​(IMouse.MousePressedListener listener)
      Description copied from interface: IMouse
      Unregisters the specified mouse pressed listener.
      Specified by:
      removeMousePressedListener in interface IMouse
      Parameters:
      listener - The listener to remove.
    • onPressing

      public void onPressing​(IMouse.MousePressingListener listener)
      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 interface IMouse
      Parameters:
      listener - The listener to add.
    • removeMousePressingListener

      public void removeMousePressingListener​(IMouse.MousePressingListener listener)
      Description copied from interface: IMouse
      Unregisters the specified mouse pressing listener.
      Specified by:
      removeMousePressingListener in interface IMouse
      Parameters:
      listener - The listener to remove.
    • onReleased

      public void onReleased​(IMouse.MouseReleasedListener listener)
      Description copied from interface: IMouse
      Adds the specified mouse released listener to receive events when the mouse has been released.
      Specified by:
      onReleased in interface IMouse
      Parameters:
      listener - The listener to add.
      See Also:
      MouseListener.mouseReleased(MouseEvent), MouseEvent.MOUSE_RELEASED
    • removeMouseReleasedListener

      public void removeMouseReleasedListener​(IMouse.MouseReleasedListener listener)
      Description copied from interface: IMouse
      Unregisters the specified mouse released listener.
      Specified by:
      removeMouseReleasedListener in interface IMouse
      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 interface IMouse
      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 interface IMouse
      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 interface IMouse
      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 interface IMouse
      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 interface IMouse
      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 interface IMouse
      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 registered MouseListener, MouseMotionListener or MouseWheelListener instances.
      Specified by:
      clearExplicitListeners in interface IMouse
      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 interface IMouse
      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 interface IMouse
      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 interface IMouse
      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()