Package org.lwjgl.input
Class Mouse
- java.lang.Object
-
- org.lwjgl.input.Mouse
-
public class Mouse extends Object
A raw Mouse interface. This can be used to poll the current state of the mouse buttons, and determine the mouse movement delta since the last poll. n buttons supported, n being a native limit. A scrolly wheel is also supported, if one such is available. Movement is reported as delta from last position or as an absolute position. If the window has been created the absolute position will be clamped to 0 - width | height.- Version:
- $Revision$ $Id$
- Author:
- cix_foo
, elias_naur , Brian Matzon
-
-
Field Summary
Fields Modifier and Type Field Description static intEVENT_SIZEInternal use - event size in bytes
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcreate()"Create" the mouse.static voiddestroy()"Destroy" the mouse.static intgetButtonCount()static intgetButtonIndex(String buttonName)Get's a button's index.static StringgetButtonName(int button)Gets a button's namestatic intgetDWheel()static intgetDX()static intgetDY()static intgetEventButton()static booleangetEventButtonState()Get the current events button state.static intgetEventDWheel()static intgetEventDX()static intgetEventDY()static longgetEventNanoseconds()Gets the time in nanoseconds of the current event.static intgetEventX()static intgetEventY()static CursorgetNativeCursor()Gets the currently bound native cursor, if any.static intgetX()Retrieves the absolute position.static intgetY()Retrieves the absolute position.static booleanhasWheel()static booleanisButtonDown(int button)See if a particular mouse button is down.static booleanisClipMouseCoordinatesToWindow()static booleanisCreated()static booleanisGrabbed()static booleanisInsideWindow()Retrieves whether or not the mouse cursor is within the bounds of the window.static booleannext()Gets the next mouse event.static voidpoll()Polls the mouse for its current state.static voidsetClipMouseCoordinatesToWindow(boolean clip)static voidsetCursorPosition(int new_x, int new_y)Set the position of the cursor.static voidsetGrabbed(boolean grab)Sets whether or not the mouse has grabbed the cursor (and thus hidden).static CursorsetNativeCursor(Cursor cursor)Binds a native cursor.static voidupdateCursor()Updates the cursor, so that animation can be changed if needed.
-
-
-
Field Detail
-
EVENT_SIZE
public static final int EVENT_SIZE
Internal use - event size in bytes- See Also:
- Constant Field Values
-
-
Method Detail
-
getNativeCursor
public static Cursor getNativeCursor()
Gets the currently bound native cursor, if any.- Returns:
- the currently bound native cursor, if any.
-
setNativeCursor
public static Cursor setNativeCursor(Cursor cursor) throws LWJGLException
Binds a native cursor. If the cursor argument is null, any currently bound native cursor is disabled, and the cursor reverts to the default operating system supplied cursor. NOTE: The native cursor is not constrained to the window, but relative events will not be generated if the cursor is outside.- Parameters:
cursor- the native cursor object to bind. May be null.- Returns:
- The previous Cursor object set, or null.
- Throws:
LWJGLException- if the cursor could not be set for any reason
-
isClipMouseCoordinatesToWindow
public static boolean isClipMouseCoordinatesToWindow()
-
setClipMouseCoordinatesToWindow
public static void setClipMouseCoordinatesToWindow(boolean clip)
-
setCursorPosition
public static void setCursorPosition(int new_x, int new_y)Set the position of the cursor. If the cursor is not grabbed, the native cursor is moved to the new position.- Parameters:
new_x- The x coordinate of the new cursor position in OpenGL coordinates relative to the window origin.new_y- The y coordinate of the new cursor position in OpenGL coordinates relative to the window origin.
-
create
public static void create() throws LWJGLException"Create" the mouse. The display must first have been created. Initially, the mouse is not grabbed and the delta values are reported with respect to the center of the display.- Throws:
LWJGLException- if the mouse could not be created for any reason
-
isCreated
public static boolean isCreated()
- Returns:
- true if the mouse has been created
-
destroy
public static void destroy()
"Destroy" the mouse.
-
poll
public static void poll()
Polls the mouse for its current state. Access the polled values using the getmethods. By using this method, it is possible to "miss" mouse click events if you don't poll fast enough. To use buffered values, you have to call nextfor each event you want to read. You can query which button caused the event by usinggetEventButton. To get the state of that button, for that event, usegetEventButtonState. NOTE: This method does not query the operating system for new events. To do that, Display.processMessages() (or Display.update()) must be called first.- See Also:
next(),getEventButton(),getEventButtonState(),isButtonDown(int button),getX(),getY(),getDX(),getDY(),getDWheel()
-
isButtonDown
public static boolean isButtonDown(int button)
See if a particular mouse button is down.- Parameters:
button- The index of the button you wish to test (0..getButtonCount-1)- Returns:
- true if the specified button is down
-
getButtonName
public static String getButtonName(int button)
Gets a button's name- Parameters:
button- The button- Returns:
- a String with the button's human readable name in it or null if the button is unnamed
-
getButtonIndex
public static int getButtonIndex(String buttonName)
Get's a button's index. If the button is unrecognised then -1 is returned.- Parameters:
buttonName- The button name
-
next
public static boolean next()
Gets the next mouse event. You can query which button caused the event by usinggetEventButton()(if any). To get the state of that key, for that event, usegetEventButtonState. To get the current mouse delta values usegetEventDX()andgetEventDY().- Returns:
- true if a mouse event was read, false otherwise
- See Also:
getEventButton(),getEventButtonState()
-
getEventButton
public static int getEventButton()
- Returns:
- Current events button. Returns -1 if no button state was changed
-
getEventButtonState
public static boolean getEventButtonState()
Get the current events button state.- Returns:
- Current events button state.
-
getEventDX
public static int getEventDX()
- Returns:
- Current events delta x.
-
getEventDY
public static int getEventDY()
- Returns:
- Current events delta y.
-
getEventX
public static int getEventX()
- Returns:
- Current events absolute x.
-
getEventY
public static int getEventY()
- Returns:
- Current events absolute y.
-
getEventDWheel
public static int getEventDWheel()
- Returns:
- Current events delta z
-
getEventNanoseconds
public static long getEventNanoseconds()
Gets the time in nanoseconds of the current event. Only useful for relative comparisons with other Mouse events, as the absolute time has no defined origin.- Returns:
- The time in nanoseconds of the current event
-
getX
public static int getX()
Retrieves the absolute position. It will be clamped to 0...width-1.- Returns:
- Absolute x axis position of mouse
-
getY
public static int getY()
Retrieves the absolute position. It will be clamped to 0...height-1.- Returns:
- Absolute y axis position of mouse
-
getDX
public static int getDX()
- Returns:
- Movement on the x axis since last time getDX() was called.
-
getDY
public static int getDY()
- Returns:
- Movement on the y axis since last time getDY() was called.
-
getDWheel
public static int getDWheel()
- Returns:
- Movement of the wheel since last time getDWheel() was called
-
getButtonCount
public static int getButtonCount()
- Returns:
- Number of buttons on this mouse
-
hasWheel
public static boolean hasWheel()
- Returns:
- Whether or not this mouse has wheel support
-
isGrabbed
public static boolean isGrabbed()
- Returns:
- whether or not the mouse has grabbed the cursor
-
setGrabbed
public static void setGrabbed(boolean grab)
Sets whether or not the mouse has grabbed the cursor (and thus hidden). If grab is false, the getX() and getY() will return delta movement in pixels clamped to the display dimensions, from the center of the display.- Parameters:
grab- whether the mouse should be grabbed
-
updateCursor
public static void updateCursor()
Updates the cursor, so that animation can be changed if needed. This method is called automatically by the window on its update, and shouldn't be called otherwise
-
isInsideWindow
public static boolean isInsideWindow()
Retrieves whether or not the mouse cursor is within the bounds of the window. If the mouse cursor was moved outside the display during a drag, then the result of calling this method will be true until the button is released.- Returns:
- true if mouse is inside display, false otherwise.
-
-