Class: SDL2::GameController

Inherits:
Object
  • Object
show all
Defined in:
gamecontroller.c

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) add_mapping



28
29
30
31
32
# File 'gamecontroller.c', line 28

static VALUE GameController_s_add_mapping(VALUE self, VALUE string)
{
    int ret = HANDLE_ERROR(SDL_GameControllerAddMapping(StringValueCStr(string)));
    return INT2NUM(ret);
}

+ (Object) axis_from_name



54
55
56
57
58
59
60
61
62
# File 'gamecontroller.c', line 54

static VALUE GameController_s_axis_from_name(VALUE self, VALUE name)
{
    int axis = SDL_GameControllerGetAxisFromString(StringValueCStr(name));
    if (axis < 0) {
        SDL_SetError("Unknown axis name \"%s\"", StringValueCStr(name));
        SDL_ERROR();
    } 
    return INT2FIX(axis);
}

+ (Object) axis_name_of



34
35
36
37
38
39
40
41
42
# File 'gamecontroller.c', line 34

static VALUE GameController_s_axis_name_of(VALUE self, VALUE axis)
{
    const char* name = SDL_GameControllerGetStringForAxis(NUM2INT(axis));
    if (!name) {
        SDL_SetError("Unknown axis %d", NUM2INT(axis));
        SDL_ERROR();
    }
    return utf8str_new_cstr(name);
}

+ (Object) button_from_name



64
65
66
67
68
69
70
71
72
# File 'gamecontroller.c', line 64

static VALUE GameController_s_button_from_name(VALUE self, VALUE name)
{
    int button = SDL_GameControllerGetButtonFromString(StringValueCStr(name));
    if (button < 0) {
        SDL_SetError("Unknown button name \"%s\"", StringValueCStr(name));
        SDL_ERROR();
    }
    return INT2FIX(button);
}

+ (Object) button_name_of



44
45
46
47
48
49
50
51
52
# File 'gamecontroller.c', line 44

static VALUE GameController_s_button_name_of(VALUE self, VALUE button)
{
    const char* name = SDL_GameControllerGetStringForButton(NUM2INT(button));
    if (!name) {
        SDL_SetError("Unknown axis %d", NUM2INT(button));
        SDL_ERROR();
    }
    return utf8str_new_cstr(name);
}

+ (Object) device_names



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'gamecontroller.c', line 74

static VALUE GameController_s_device_names(VALUE self)
{
    int num_joysticks = SDL_NumJoysticks();
    int i;
    VALUE device_names = rb_ary_new2(num_joysticks);
    for (i=0; i<num_joysticks; ++i) {
        const char* name = SDL_GameControllerNameForIndex(i);
        if (name)
            rb_ary_push(device_names, utf8str_new_cstr(name));
        else
            rb_ary_push(device_names, Qnil);
    }
    return device_names;
}

+ (Object) mapping_for



89
90
91
92
93
# File 'gamecontroller.c', line 89

static VALUE GameController_s_mapping_for(VALUE self, VALUE guid_string)
{
    SDL_JoystickGUID guid = SDL_JoystickGetGUIDFromString(StringValueCStr(guid_string));
    return utf8str_new_cstr(SDL_GameControllerMappingForGUID(guid));
}

+ (Object) open



95
96
97
98
99
100
101
# File 'gamecontroller.c', line 95

static VALUE GameController_s_open(VALUE self, VALUE index)
{
    SDL_GameController* controller = SDL_GameControllerOpen(NUM2INT(index));
    if (!controller)
        SDL_ERROR();
    return GameController_new(controller);
}

Instance Method Details

- (Boolean) attached?

Returns:

  • (Boolean)


108
109
110
111
# File 'gamecontroller.c', line 108

static VALUE GameController_attached_p(VALUE self)
{
    return INT2BOOL(SDL_GameControllerGetAttached(Get_SDL_GameController(self)));
}

- (Object) axis



127
128
129
130
131
# File 'gamecontroller.c', line 127

static VALUE GameController_axis(VALUE self, VALUE axis)
{
    return INT2FIX(SDL_GameControllerGetAxis(Get_SDL_GameController(self),
                                             NUM2INT(axis)));
}

- (Boolean) button_pressed?

Returns:

  • (Boolean)


133
134
135
136
137
# File 'gamecontroller.c', line 133

static VALUE GameController_button_pressed_p(VALUE self, VALUE button)
{
    return INT2BOOL(SDL_GameControllerGetButton(Get_SDL_GameController(self),
                                                NUM2INT(button)));
}

- (Object) destroy



113
114
115
116
117
118
119
120
# File 'gamecontroller.c', line 113

static VALUE GameController_destroy(VALUE self)
{
    GameController* g = Get_GameController(self);
    if (g->controller)
        SDL_GameControllerClose(g->controller);
    g->controller = NULL;
    return Qnil;
}

- (Boolean) destroy?

Returns:

  • (Boolean)

- (Object) mapping



122
123
124
125
# File 'gamecontroller.c', line 122

static VALUE GameController_mapping(VALUE self)
{
    return utf8str_new_cstr(SDL_GameControllerMapping(Get_SDL_GameController(self)));
}

- (Object) name



103
104
105
106
# File 'gamecontroller.c', line 103

static VALUE GameController_name(VALUE self)
{
    return utf8str_new_cstr(SDL_GameControllerName(Get_SDL_GameController(self)));
}