Module: SDL2::Mouse

Defined in:
mouse.c,
mouse.c

Overview

This module has mouse input handling functions.

Defined Under Namespace

Classes: Cursor, State

Class Method Summary collapse

Class Method Details

.focused_windowSDL2::Window?

Get the window which has mouse focus.

Returns:

  • (SDL2::Window)

    the window which has mouse focus

  • (nil)

    if no window governed by SDL has mouse focus



154
155
156
157
158
159
160
161
# File 'mouse.c', line 154

static VALUE Mouse_s_focused_window(VALUE self)
{
    SDL_Window* window = SDL_GetMouseFocus();
    if (!window)
        return Qnil;
    else
        return find_window_by_id(SDL_GetWindowID(window));
}

.global_stateSDL2::Mouse::State

Note:

This module function is available since SDL 2.0.4.

Get the current mouse state in relation to the desktop.

The return value contains the x and y coordinates of the cursor relative to the desktop and the state of mouse buttons.

Returns:



83
84
85
86
# File 'mouse.c', line 83

static VALUE Mouse_s_global_state(VALUE self)
{
    return mouse_state(SDL_GetGlobalMouseState);
}

.relative_mode=(bool) ⇒ Boolean

Note:

This function will flush any pending mouse motion.

Set relative mouse mode.

While the mouse is in relative mode, the cursor is hidden, and the driver will try to report continuous motion in the current window. Only relative motion events will be delivered, the mouse position will not change.

Parameters:

  • bool (Boolean)

    true if you want to enable relative mouse mode

Returns:

  • (Boolean)

See Also:



128
129
130
131
132
# File 'mouse.c', line 128

static VALUE Mouse_s_set_relative_mode(VALUE self, VALUE enabled)
{
    HANDLE_ERROR(SDL_SetRelativeMouseMode(RTEST(enabled)));
    return enabled;
}

.relative_mode?Boolean

Return true if relative mouse mode is enabled.

Returns:

  • (Boolean)

See Also:



107
108
109
110
# File 'mouse.c', line 107

static VALUE Mouse_s_relative_mode_p(VALUE self)
{
    return INT2BOOL(SDL_GetRelativeMouseMode());
}

.relative_stateSDL2::Mouse::State

Get the relative state of the mouse.

The button state is same as state and x and y of the returned object are set to the mouse deltas since the last call to this method.

Returns:



143
144
145
146
# File 'mouse.c', line 143

static VALUE Mouse_s_relative_state(VALUE self)
{
    return mouse_state(SDL_GetRelativeMouseState);
}

.stateSDL2::Mouse::State

Get the current state of the mouse.

The return value contains the x and y coordinates of the cursor and the state of mouse buttons.

Returns:



97
98
99
100
# File 'mouse.c', line 97

static VALUE Mouse_s_state(VALUE self)
{
    return mouse_state(SDL_GetMouseState);
}