Module: SDL2::Mouse

Defined in:
mouse.c,
mouse.c

Overview

This module have mouse input handling functions.

Defined Under Namespace

Classes: Cursor, State

Class Method Summary (collapse)

Class Method Details

+ (SDL2::Window?) focused_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));
}

+ (SDL2::Mouse::State) global_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);
}

+ (bool) relative_mode=(bool)

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:

  • (bool)

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;
}

+ (Boolean) relative_mode?

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());
}

+ (SDL2::Mouse::State) relative_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);
}

+ (SDL2::Mouse::State) 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);
}