rudl_mouse

Back to index

# Index

Mouse
Class and instance Methods
`Mouse.focused?`
`Mouse#focused?`
`Mouse.pos`
`Mouse#pos`
`Mouse.pressed?`
`Mouse#pressed?`
`Mouse.rel`
`Mouse#rel`
`Mouse.pos=( pos )`
`Mouse#pos=( pos )`
`Mouse.visible=( onOrOff )`
`Mouse#visible=( onOrOff )`
`Mouse.set_cursor( hotspot, xormasks, andmasks )`
`Mouse#get_cursor( hotspot, xormasks, andmasks )`
Events
MouseMotionEvent
`MouseMotionEvent.pos`
`MouseMotionEvent.rel`
`MouseMotionEvent.button`
MouseButtonUpEvent
`MouseButtonUpEvent.pos`
`MouseButtonUpEvent.button`
MouseButtonDownEvent
`MouseButtonDownEvent.pos`
`MouseButtonDownEvent.button`

# Mouse

The mouse class methods can also be used as instance methods once you instantiate the class. However, there is no need to do that, it's just for convenience.

## Class and instance Methods

`Mouse.focused?`
`Mouse#focused?`

Returns true when the application is receiving the mouse input focus.

`Mouse.pos`
`Mouse#pos`

Returns the current position of the mouse cursor. This is the absolute mouse position inside your game window.

`Mouse.pressed?`
`Mouse#pressed?`

This will return an array containing the pressed state of each mouse button.

`Mouse.rel`
`Mouse#rel`

Returns the total distance the mouse has moved since your last call to Mouse.rel. On the first call to get_rel the movement will always be 0,0. When the mouse is at the edges of the screen, the relative movement will be stopped. See Mouse.visible for a way to resolve this.

`Mouse.pos=( pos )`
`Mouse#pos=( pos )`

Moves the mouse cursor to the specified position. This will generate a MouseMotionEvent on the input queue.

`Mouse.visible=( onOrOff )`
`Mouse#visible=( onOrOff )`

Shows or hides the mouse cursor. This will return the previous visible state of the mouse cursor.

Note that when the cursor is hidden and the application has grabbed the input. SDL will force the mouse to stay in the center of the screen. Since the mouse is hidden it won't matter that it's not moving, but it will keep the mouse from the edges of the screen so the relative mouse position will always be true.

`Mouse.set_cursor( hotspot, xormasks, andmasks )`
`Mouse#get_cursor( hotspot, xormasks, andmasks )`

When the mouse cursor is visible, it will be displayed as a black and white bitmap using the given bitmask arrays. Hotspot is an array containing the cursor hotspot position. xormasks is an array of arrays of bytes containing the cursor xor data masks. Lastly is andmasks, an array of arrays of bytes containting the cursor bitmask data.

The example "mousecursor.rb" explains this much better.

# Events

## MouseMotionEvent

`MouseMotionEvent.pos`

An array [x, y] telling the position of the mouse.

`MouseMotionEvent.rel`

An array [dx, dy] telling how much the mouse moved.

`MouseMotionEvent.button`

An array of booleans, representing the states of the mousebuttons. Currently, three buttons are supported.

## MouseButtonUpEvent

`MouseButtonUpEvent.pos`

An array [x, y] telling the position of the mouse.

`MouseButtonUpEvent.button`

The number of the button that was released.

## MouseButtonDownEvent

`MouseButtonDownEvent.pos`

An array [x, y] telling the position of the mouse.

`MouseButtonDownEvent.button`

The number of the button that was pressed.

Back to index