92            if ((last_device_scan < 0) || (time > last_device_scan + device_scan_interval)) {
 
   93                last_device_scan = time;
 
   94                gamepad::scan_devices();
 
   95                std::vector<void*> new_device_handles;
 
   96                for (
const auto& di : gamepad::get_device_infos())
 
   97                    new_device_handles.push_back(di.device_handle);
 
   98                std::vector<gamepad::gamepad_state> new_states(new_device_handles.size());
 
   99                for (
void* dh : device_handles) {
 
  100                    auto iter = std::find(new_device_handles.begin(), new_device_handles.end(), dh);
 
  101                    if (iter == new_device_handles.end()) {
 
  102                        if ((event_flags&GPE_DEVICE) != 0)
 
  106                        size_t i = iter - new_device_handles.begin();
 
  107                        new_states[i] = last_states[i];
 
  110                for (
void* ndh : new_device_handles) {
 
  111                    auto iter = std::find(device_handles.begin(), device_handles.end(), ndh);
 
  112                    if (iter == device_handles.end()) {
 
  113                        if ((event_flags&GPE_DEVICE) != 0)
 
  117                last_states = new_states;
 
  118                device_handles = new_device_handles;
 
  120            gamepad::GamepadKeys key;
 
  121            gamepad::KeyAction action;
 
  124            for (
unsigned i = 0; i < device_handles.size(); ++i) {
 
  126                if (!get_state(device_handles[i], state))
 
  129                while (query_key_event(device_handles[i], key, action)) {
 
  130                    if ((event_flags&GPE_KEY) != 0) {
 
  132                        if (key >= gamepad::GPK_A && key <= gamepad::GPK_Y)
 
  133                            c = std::string(
"ABXY")[key - gamepad::GPK_A];
 
  139                if (state.
time_stamp != last_states[i].time_stamp) {
 
  141                    if ((event_flags&GPE_THROTTLE) != 0) {
 
  142                        for (
int ti = 0; ti < 2; ++ti) {
 
  144                            float dx = x - last_states[i].trigger_position[ti];
 
  153                    if ((event_flags&(GPE_STICK+GPE_STICK_KEY)) != 0) {
 
  154                        for (
int si = 0; si < 2; ++si) {
 
  155                            unsigned stick_flag = (si == 0 ? gamepad::GBF_LEFT_STICK : gamepad::GBF_RIGHT_STICK);
 
  156                            if ((state.
button_flags&stick_flag) != (last_states[i].button_flags&stick_flag)) {
 
  159                                if ((event_flags&GPE_STICK) != 0) {
 
  161                                    gamepad_stick_event gp_se(device_handles[i], state, action, x, y, 0, 0, i, 0, si, time);
 
  164                                if ((event_flags&GPE_STICK_KEY) != 0) {
 
  165                                    int qx = x > 0.5f ? 1 : (x < -0.5f ? -1 : 0);
 
  166                                    int qy = y > 0.5f ? 1 : (y < -0.5f ? -1 : 0);
 
  167                                    short key_index = si*9 + 3 * (qy+1) + qx+1;
 
  168                                    static gamepad::GamepadKeys key_lookup[18] = {
 
  169                                        gamepad::GPK_LEFT_STICK_DOWNLEFT,
 
  170                                        gamepad::GPK_LEFT_STICK_DOWN,
 
  171                                        gamepad::GPK_LEFT_STICK_DOWNRIGHT,
 
  172                                        gamepad::GPK_LEFT_STICK_LEFT,
 
  173                                        gamepad::GPK_LEFT_STICK_PRESS,
 
  174                                        gamepad::GPK_LEFT_STICK_RIGHT,
 
  175                                        gamepad::GPK_LEFT_STICK_UPLEFT,
 
  176                                        gamepad::GPK_LEFT_STICK_UP,
 
  177                                        gamepad::GPK_LEFT_STICK_UPRIGHT,
 
  178                                        gamepad::GPK_RIGHT_STICK_DOWNLEFT,
 
  179                                        gamepad::GPK_RIGHT_STICK_DOWN,
 
  180                                        gamepad::GPK_RIGHT_STICK_DOWNRIGHT,
 
  181                                        gamepad::GPK_RIGHT_STICK_LEFT,
 
  182                                        gamepad::GPK_RIGHT_STICK_PRESS,
 
  183                                        gamepad::GPK_RIGHT_STICK_RIGHT,
 
  184                                        gamepad::GPK_RIGHT_STICK_UPLEFT,
 
  185                                        gamepad::GPK_RIGHT_STICK_UP,
 
  186                                        gamepad::GPK_RIGHT_STICK_UPRIGHT
 
  190                                        key_lookup[key_index], action, 0, time);
 
  197                    if ((event_flags&GPE_STICK) != 0) {
 
  200                        float dx = x - last_states[i].left_stick_position[0];
 
  201                        float dy = y - last_states[i].left_stick_position[1];
 
  202                        if (dx != 0 || dy != 0) {
 
  204                            if ((state.
button_flags & gamepad::GBF_LEFT_STICK) != 0)
 
  208                                action, x, y, dx, dy, i, 0, 0, time);
 
  213                        dx = x - last_states[i].right_stick_position[0];
 
  214                        dy = y - last_states[i].right_stick_position[1];
 
  215                        if (dx != 0 || dy != 0) {
 
  217                            if ((state.
button_flags & gamepad::GBF_RIGHT_STICK) != 0)
 
  221                                action, x, y, dx, dy, i, 0, 1, time);
 
  225                    last_states[i] = state;