bool JoystickInfo::PollButtons(u32 &pkey) { // MAKE sure to look for changes in the state!! for (int i = 0; i < GetNumButtons(); ++i) { int but = SDL_JoystickGetButton(GetJoy(), i); if (but != GetButtonState(i)) { // Pressure sensitive button are detected as both button (digital) and axes (analog). So better // drop the button to emulate the pressure sensiblity of the ds2 :) // Trick: detect the release of the button. It avoid all races condition between axes and buttons :) // If the button support pressure it will be detected as an axis when it is pressed. if (but) { SetButtonState(i, but); return false; } pkey = button_to_key(i); return true; } } return false; }
bool JoystickInfo::PollButtons(u32 &pkey) { // MAKE sure to look for changes in the state!! for (int i = 0; i < GetNumButtons(); ++i) { int but = SDL_JoystickGetButton(GetJoy(), i); if (but != GetButtonState(i)) { if (!but) // released, we don't really want this { continue; } // Pressure sensitive button are detected as both button (digital) and axes (analog). So better // drop the button to emulate the pressure sensiblity of the ds2 :) -- Gregory u32 pkey_dummy; if (PollAxes(pkey_dummy)) return false; pkey = button_to_key(i); return true; } } return false; }
void Dialog::JoystickEvent(wxTimerEvent &event) { #ifdef SDL_BUILD u32 key; int map; std::map<u32, int>::iterator it; std::map<u32, int>::iterator it2; SDL_JoystickEventState(SDL_ENABLE); SDL_Event events; while (SDL_PollEvent(&events)) { switch (events.type) { case SDL_KEYDOWN: case SDL_KEYUP: break; case SDL_JOYAXISMOTION: if (events.jaxis.which < GAMEPAD_NUMBER) { key = axis_to_key(false, (events.jaxis.value < 0), events.jaxis.axis); it = m_map_images[events.jaxis.which].find(key); if (it != m_map_images[events.jaxis.which].end()) { map = m_map_images[events.jaxis.which][key]; if (events.jaxis.value == 0) { if (map >= PAD_L_UP && map <= PAD_L_LEFT) m_pan_tabs[events.jaxis.which]->HideImg(img_left_cursor); else if (map >= PAD_R_UP && map <= PAD_R_LEFT) m_pan_tabs[events.jaxis.which]->HideImg(img_right_cursor); else if (map < PAD_L_UP) m_pan_tabs[events.jaxis.which]->HideImg(map); } else { if (map >= PAD_L_UP && map <= PAD_L_LEFT) { m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value); m_pan_tabs[events.jaxis.which]->ShowImg(img_left_cursor); } else if (map >= PAD_R_UP && map <= PAD_R_LEFT) { m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value); m_pan_tabs[events.jaxis.which]->ShowImg(img_right_cursor); } else if (map < PAD_L_UP) { // if this is not a joystick m_pan_tabs[events.jaxis.which]->ShowImg(map); } } break; } // Hack Dualshock 4 (L2, R2) key = axis_to_key(false, (events.jaxis.value > 0), events.jaxis.axis); it2 = m_map_images[events.jaxis.which].find(key); if (it2 != m_map_images[events.jaxis.which].end()) { map = m_map_images[events.jaxis.which][key]; if (map < PAD_L_UP) { // if this is not a joystick m_pan_tabs[events.jaxis.which]->HideImg(map); } break; } } break; case SDL_JOYBUTTONDOWN: if (events.jbutton.which < GAMEPAD_NUMBER) { key = button_to_key(events.jbutton.button); it = m_map_images[events.jbutton.which].find(key); if (it != m_map_images[events.jbutton.which].end()) { map = m_map_images[events.jbutton.which][key]; m_pan_tabs[events.jbutton.which]->ShowImg(map); } } break; case SDL_JOYBUTTONUP: if (events.jbutton.which < GAMEPAD_NUMBER) { key = button_to_key(events.jbutton.button); it = m_map_images[events.jbutton.which].find(key); if (it != m_map_images[events.jbutton.which].end()) { map = m_map_images[events.jbutton.which][key]; m_pan_tabs[events.jbutton.which]->HideImg(map); } } break; case SDL_JOYHATMOTION: if (events.jhat.which < GAMEPAD_NUMBER) { switch (events.jhat.value) { case SDL_HAT_UP: key = hat_to_key(events.jhat.value, events.jhat.hat); it = m_map_images[events.jhat.which].find(key); if (it != m_map_images[events.jhat.which].end()) { m_pan_tabs[events.jhat.which]->ShowImg(img_dp_up); } break; case SDL_HAT_DOWN: key = hat_to_key(events.jhat.value, events.jhat.hat); it = m_map_images[events.jhat.which].find(key); if (it != m_map_images[events.jhat.which].end()) { m_pan_tabs[events.jhat.which]->ShowImg(img_dp_bottom); } break; case SDL_HAT_RIGHT: key = hat_to_key(events.jhat.value, events.jhat.hat); it = m_map_images[events.jhat.which].find(key); if (it != m_map_images[events.jhat.which].end()) { m_pan_tabs[events.jhat.which]->ShowImg(img_dp_right); } break; case SDL_HAT_LEFT: key = hat_to_key(events.jhat.value, events.jhat.hat); it = m_map_images[events.jhat.which].find(key); if (it != m_map_images[events.jhat.which].end()) { m_pan_tabs[events.jhat.which]->ShowImg(img_dp_left); } break; case SDL_HAT_CENTERED: m_pan_tabs[events.jhat.which]->HideImg(img_dp_up); m_pan_tabs[events.jhat.which]->HideImg(img_dp_bottom); m_pan_tabs[events.jhat.which]->HideImg(img_dp_right); m_pan_tabs[events.jhat.which]->HideImg(img_dp_left); } } break; default: break; } } #endif // SDL_BUILD }