sfml3.rb

Module: SFML::Joystick

Defined in:
ext/window/joystick.c,
ext/window/joystick.c

Overview

Access to raw joystick/gamepad state, addressed by joystick number (0 up to Joystick::COUNT - 1).

Constant Summary collapse

COUNT =

Maximum number of joysticks supported.

INT2NUM(sfJoystickCount)
BUTTON_COUNT =

Maximum number of buttons supported on a single joystick.

INT2NUM(sfJoystickButtonCount)
AXIS_COUNT =

Maximum number of axes supported on a single joystick.

INT2NUM(sfJoystickAxisCount)

Class Method Summary collapse

Class Method Details

.axis_position(joystick, axis) ⇒ Float

Returns the current position of axis on joystick number joystick, between -100 and 100.

Returns:

  • (Float)

Returns:

  • (Float) —

    the current position of axis on joystick number joystick, between -100 and 100



66
67
68
69
# File 'ext/window/joystick.c', line 66

static VALUE Joystick_get_axis_position(VALUE module, VALUE rb_joystick, VALUE rb_axis) {
    return DBL2NUM(
        sfJoystick_getAxisPosition(NUM2UINT(rb_joystick), joystick_axis_from_rb(rb_axis)));
}

.button_count(joystick) ⇒ Integer

Returns the number of buttons on joystick number joystick.

Returns:

  • (Integer)

Returns:

  • (Integer) —

    number of buttons on joystick number joystick



28
29
30
# File 'ext/window/joystick.c', line 28

static VALUE Joystick_get_button_count(VALUE module, VALUE rb_joystick) {
    return UINT2NUM(sfJoystick_getButtonCount(NUM2UINT(rb_joystick)));
}

.button_pressed?(joystick, button) ⇒ Boolean

Returns true if button is currently pressed on joystick number joystick.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    whether button is currently pressed on joystick number joystick



53
54
55
# File 'ext/window/joystick.c', line 53

static VALUE Joystick_is_button_pressed(VALUE module, VALUE rb_joystick, VALUE rb_button) {
    return BOOL2RB(sfJoystick_isButtonPressed(NUM2UINT(rb_joystick), NUM2UINT(rb_button)));
}

.connected?(joystick) ⇒ Boolean

Returns true if joystick number joystick is currently connected.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    whether joystick number joystick is currently connected



17
18
19
# File 'ext/window/joystick.c', line 17

static VALUE Joystick_is_connected(VALUE module, VALUE rb_joystick) {
    return BOOL2RB(sfJoystick_isConnected(NUM2UINT(rb_joystick)));
}

.has_axis?(joystick, axis) ⇒ Boolean

Returns true if joystick number joystick has axis.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    whether joystick number joystick has axis (a Symbol like :x, :y, :pov_x, or an Integer)



40
41
42
# File 'ext/window/joystick.c', line 40

static VALUE Joystick_has_axis(VALUE module, VALUE rb_joystick, VALUE rb_axis) {
    return BOOL2RB(sfJoystick_hasAxis(NUM2UINT(rb_joystick), joystick_axis_from_rb(rb_axis)));
}

.identification(joystick) ⇒ Hash

Returns the :name, :vendor_id and :product_id of joystick number joystick.

Returns:

  • (Hash)

Returns:

  • (Hash) —

    :name, :vendor_id, :product_id, for joystick number joystick



80
81
82
83
84
85
86
87
88
89
90
# File 'ext/window/joystick.c', line 80

static VALUE Joystick_get_identification(VALUE module, VALUE rb_joystick) {
    sfJoystickIdentification identification = sfJoystick_getIdentification(NUM2UINT(rb_joystick));
    VALUE hash = rb_hash_new();

    rb_hash_aset(hash, ID2SYM(rb_intern("name")),
                 rb_str_new_cstr(identification.name != NULL ? identification.name : ""));
    rb_hash_aset(hash, ID2SYM(rb_intern("vendor_id")), UINT2NUM(identification.vendorId));
    rb_hash_aset(hash, ID2SYM(rb_intern("product_id")), UINT2NUM(identification.productId));

    return hash;
}

.update! ⇒ nil

Refreshes the connection state of all joysticks. Called implicitly by event polling; only needed if you query joystick state without polling events.

Returns:

  • (nil)

Returns:

  • (nil)


100
101
102
103
# File 'ext/window/joystick.c', line 100

static VALUE Joystick_update(VALUE module) {
    sfJoystick_update();
    return Qnil;
}