Class: SDL2::Mouse::State

Inherits:
Object
  • Object
show all
Defined in:
ext/sdl2_ext/mouse.c,
ext/sdl2_ext/mouse.c

Overview

This class represents mouse stetes.

You can get a mouse state with state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#button_bitsInteger (readonly)

button bits

Returns:

  • (Integer)

See Also:

#xInteger (readonly)

the x coordinate of the mouse cursor.

For SDL2::Mouse.state, this attribute means the x coordinate relative to the window. For SDL2::Mouse.relative_state, this attribute means the x coordinate relative to the previous call of SDL2::Mouse.relative_state.

Returns:

  • (Integer)

#yInteger (readonly)

the y coordinate of the mouse cursor

For SDL2::Mouse.state, this attribute means the y coordinate relative to the window. For SDL2::Mouse.relative_state, this attribute means the y coordinate relative to the previous call of SDL2::Mouse.relative_state.

Returns:

  • (Integer)

Instance Method Details

#inspectString

Returns inspection string.

Returns:

  • (String)

    inspection string



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'ext/sdl2_ext/mouse.c', line 239

static VALUE State_inspect(VALUE self)
{
    int i;
    Uint32 buttons = NUM2UINT(rb_iv_get(self, "@button_bits"));
    VALUE pressed = rb_ary_new();
    VALUE string_for_pressed;
    for (i=1; i<=32; ++i) 
        if (buttons & SDL_BUTTON(i)) 
            rb_ary_push(pressed, rb_sprintf("%d", i));
    
    string_for_pressed = rb_ary_join(pressed, rb_str_new2(" "));
    return rb_sprintf("<%s:%p x=%d y=%d pressed=[%s]>",
                      rb_obj_classname(self), (void*)self,
                      NUM2INT(rb_iv_get(self, "@x")), NUM2INT(rb_iv_get(self, "@y")),
                      StringValueCStr(string_for_pressed));
}

#pressed?(index) ⇒ Boolean

Return true a mouse button is pressed.

Parameters:

  • index (Integer)

    the index of a mouse button, start at index 0

Returns:

  • (Boolean)


230
231
232
233
234
235
236
# File 'ext/sdl2_ext/mouse.c', line 230

static VALUE State_pressed_p(VALUE self, VALUE index)
{
    int idx = NUM2INT(index);
    if (idx < 0 || idx >= 32)
        rb_raise(rb_eArgError, "button index out of range (%d for 1..32)", idx);
    return INT2BOOL(NUM2UINT(rb_iv_get(self, "@button_bits")) & SDL_BUTTON(idx));
}