1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#[cfg(feature = "no_std")]
use core::prelude::*;
use libc::{c_int, c_char, c_uchar, c_uint, c_void, int16_t, uint8_t};
use joystick::{SDL_Joystick, SDL_JoystickGUID};
use super::rwops::SDL_RWops;
use sdl::SDL_bool;

pub type SDL_GameController = c_void;

pub type SDL_GameControllerBindType = c_uint;
pub const SDL_CONTROLLER_BINDTYPE_NONE: SDL_GameControllerBindType = 0;
pub const SDL_CONTROLLER_BINDTYPE_BUTTON: SDL_GameControllerBindType = 1;
pub const SDL_CONTROLLER_BINDTYPE_AXIS: SDL_GameControllerBindType = 2;
pub const SDL_CONTROLLER_BINDTYPE_HAT: SDL_GameControllerBindType = 3;

#[allow(dead_code, non_snake_case)]
#[derive(Copy, Clone)]
#[repr(C)]
pub struct SDL_GameControllerButtonBind {
    bindType: SDL_GameControllerBindType,
    value: SDL_GameControllerButtonBindData,
}

#[allow(dead_code)]
#[derive(Copy, Clone)]
#[repr(C)]
pub struct SDL_GameControllerButtonBindData {
    data: [c_uchar; 8],
}

#[allow(dead_code)]
#[derive(Copy, Clone)]
pub struct SDL_GameControllerButtonBindDataHat {
    hat: c_int,
    hat_mask: c_int,
}

impl SDL_GameControllerButtonBindData {
    pub fn button(&mut self) -> *mut c_int {
        self.data.as_mut_ptr() as *mut _
    }
    pub fn axis(&mut self) -> *mut c_int {
        self.data.as_mut_ptr() as *mut _
    }
    pub fn hat(&mut self) -> *mut SDL_GameControllerButtonBindDataHat {
        self.data.as_mut_ptr() as *mut _
    }
}

pub type SDL_GameControllerAxis = c_int;
pub const SDL_CONTROLLER_AXIS_INVALID: SDL_GameControllerAxis = -1;
pub const SDL_CONTROLLER_AXIS_LEFTX: SDL_GameControllerAxis = 0;
pub const SDL_CONTROLLER_AXIS_LEFTY: SDL_GameControllerAxis = 1;
pub const SDL_CONTROLLER_AXIS_RIGHTX: SDL_GameControllerAxis = 2;
pub const SDL_CONTROLLER_AXIS_RIGHTY: SDL_GameControllerAxis = 3;
pub const SDL_CONTROLLER_AXIS_TRIGGERLEFT: SDL_GameControllerAxis = 4;
pub const SDL_CONTROLLER_AXIS_TRIGGERRIGHT: SDL_GameControllerAxis = 5;
pub const SDL_CONTROLLER_AXIS_MAX: SDL_GameControllerAxis = 6;

pub type SDL_GameControllerButton = c_int;
pub const SDL_CONTROLLER_BUTTON_INVALID: SDL_GameControllerButton = -1;
pub const SDL_CONTROLLER_BUTTON_A: SDL_GameControllerButton = 0;
pub const SDL_CONTROLLER_BUTTON_B: SDL_GameControllerButton = 1;
pub const SDL_CONTROLLER_BUTTON_X: SDL_GameControllerButton = 2;
pub const SDL_CONTROLLER_BUTTON_Y: SDL_GameControllerButton = 3;
pub const SDL_CONTROLLER_BUTTON_BACK: SDL_GameControllerButton = 4;
pub const SDL_CONTROLLER_BUTTON_GUIDE: SDL_GameControllerButton = 5;
pub const SDL_CONTROLLER_BUTTON_START: SDL_GameControllerButton = 6;
pub const SDL_CONTROLLER_BUTTON_LEFTSTICK: SDL_GameControllerButton = 7;
pub const SDL_CONTROLLER_BUTTON_RIGHTSTICK: SDL_GameControllerButton = 8;
pub const SDL_CONTROLLER_BUTTON_LEFTSHOULDER: SDL_GameControllerButton = 9;
pub const SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: SDL_GameControllerButton = 10;
pub const SDL_CONTROLLER_BUTTON_DPAD_UP: SDL_GameControllerButton = 11;
pub const SDL_CONTROLLER_BUTTON_DPAD_DOWN: SDL_GameControllerButton = 12;
pub const SDL_CONTROLLER_BUTTON_DPAD_LEFT: SDL_GameControllerButton = 13;
pub const SDL_CONTROLLER_BUTTON_DPAD_RIGHT: SDL_GameControllerButton = 14;
pub const SDL_CONTROLLER_BUTTON_MAX: SDL_GameControllerButton = 15;

extern "C" {
    pub fn SDL_GameControllerAddMapping(mappingString: *const c_char) -> c_int;
    pub fn SDL_GameControllerAddMappingsFromRW(rw: *mut SDL_RWops, freerw: c_int) -> c_int;
    pub fn SDL_GameControllerMappingForGUID(guid: SDL_JoystickGUID) ->
              *const c_char;
    pub fn SDL_GameControllerMapping(gamecontroller: *mut SDL_GameController)
              -> *const c_char;
    pub fn SDL_IsGameController(joystick_index: c_int) -> SDL_bool;
    pub fn SDL_GameControllerNameForIndex(joystick_index: c_int) ->
              *const c_char;
    pub fn SDL_GameControllerOpen(joystick_index: c_int) ->
              *mut SDL_GameController;
    pub fn SDL_GameControllerName(gamecontroller: *mut SDL_GameController) ->
              *const c_char;
    pub fn SDL_GameControllerGetAttached(gamecontroller:
                                                   *mut SDL_GameController) ->
              SDL_bool;
    pub fn SDL_GameControllerGetJoystick(gamecontroller:
                                                   *mut SDL_GameController) ->
              *mut SDL_Joystick;
    pub fn SDL_GameControllerEventState(state: c_int) -> c_int;
    pub fn SDL_GameControllerUpdate();
    pub fn SDL_GameControllerGetAxisFromString(pchString: *const c_char) ->
              SDL_GameControllerAxis;
    pub fn SDL_GameControllerGetStringForAxis(axis:
                                                        SDL_GameControllerAxis)
              -> *const c_char;
    pub fn SDL_GameControllerGetBindForAxis(gamecontroller:
                                                      *mut SDL_GameController,
                                                  axis: SDL_GameControllerAxis)
              -> SDL_GameControllerButtonBind;
    pub fn SDL_GameControllerGetAxis(gamecontroller: *mut SDL_GameController,
                                           axis: SDL_GameControllerAxis) ->
              int16_t;
    pub fn SDL_GameControllerGetButtonFromString(pchString: *const c_char) ->
              SDL_GameControllerButton;
    pub fn SDL_GameControllerGetStringForButton(button:
                                                      SDL_GameControllerButton)
              -> *const c_char;
    pub fn SDL_GameControllerGetBindForButton(gamecontroller:
                                                        *mut SDL_GameController,
                                                    button:
                                                      SDL_GameControllerButton)
              -> SDL_GameControllerButtonBind;
    pub fn SDL_GameControllerGetButton(gamecontroller:
                                                 *mut SDL_GameController,
                                             button: SDL_GameControllerButton)
              -> uint8_t;
    pub fn SDL_GameControllerClose(gamecontroller: *mut SDL_GameController);
}