Class: SDL2::Mouse::State
- Inherits:
-
Object
- Object
- SDL2::Mouse::State
- Defined in:
- mouse.c,
mouse.c
Overview
This class represents mouse stetes.
You can get a mouse state with state.
Instance Attribute Summary (collapse)
-
- (Integer) button_bits
button bits.
-
- (Integer) x
the x coordinate of the mouse cursor.
-
- (Integer) y
the y coordinate of the mouse cursor.
Instance Method Summary (collapse)
-
- (String) inspect
Inspection string.
-
- (Boolean) pressed?(index)
Return true a mouse button is pressed.
Instance Attribute Details
- (Integer) button_bits
button bits
- (Integer) x
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.
- (Integer) y
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.
Instance Method Details
- (String) inspect
Returns inspection string
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File '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));
}
|
- (Boolean) pressed?(index)
230 231 232 233 234 235 236 |
# File '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));
}
|