Allow gamepad without mapped buttons to use scan code directly in android
This commit is contained in:
parent
5faa856b0e
commit
abfb9e535c
@ -223,6 +223,7 @@ public class SuperTuxKartActivity extends NativeActivity
|
|||||||
int scan_code = event.getScanCode();
|
int scan_code = event.getScanCode();
|
||||||
// KeyCharacterMap.COMBINING_ACCENT is not handled at the moment
|
// KeyCharacterMap.COMBINING_ACCENT is not handled at the moment
|
||||||
int unichar = event.getUnicodeChar(meta_state);
|
int unichar = event.getUnicodeChar(meta_state);
|
||||||
|
int repeat_count = event.getRepeatCount();
|
||||||
|
|
||||||
// Dispatch the different events depending on where they come from
|
// Dispatch the different events depending on where they come from
|
||||||
// Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
|
// Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
|
||||||
@ -236,7 +237,7 @@ public class SuperTuxKartActivity extends NativeActivity
|
|||||||
// Note that we process events with specific key codes here
|
// Note that we process events with specific key codes here
|
||||||
if (action == KeyEvent.ACTION_DOWN)
|
if (action == KeyEvent.ACTION_DOWN)
|
||||||
{
|
{
|
||||||
if (SDLControllerManager.onNativePadDown(device_id, key_code, meta_state, scan_code, unichar) == 0)
|
if (SDLControllerManager.onNativePadDown(device_id, key_code, meta_state, scan_code, unichar, repeat_count) == 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (action == KeyEvent.ACTION_UP)
|
else if (action == KeyEvent.ACTION_UP)
|
||||||
@ -246,7 +247,6 @@ public class SuperTuxKartActivity extends NativeActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int repeat_count = event.getRepeatCount();
|
|
||||||
// User pressed back button
|
// User pressed back button
|
||||||
if (key_code == KeyEvent.KEYCODE_BACK &&
|
if (key_code == KeyEvent.KEYCODE_BACK &&
|
||||||
action == KeyEvent.ACTION_DOWN)
|
action == KeyEvent.ACTION_DOWN)
|
||||||
|
@ -208,4 +208,17 @@ void SDLController::handleAxisInputSense(const SDL_Event& event)
|
|||||||
m_prev_axes[axis_idx]);
|
m_prev_axes[axis_idx]);
|
||||||
} // handleAxisInputSense
|
} // handleAxisInputSense
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
#ifdef ANDROID
|
||||||
|
void SDLController::handleDirectScanCode(const SDL_Event& event)
|
||||||
|
{
|
||||||
|
// Android STK has custom changes in SDL2 to allow gamepad with unknown
|
||||||
|
// button to use scan code directly
|
||||||
|
input_manager->dispatchInput(Input::IT_STICKBUTTON,
|
||||||
|
m_irr_event.JoystickEvent.Joystick, event.jbutton.button,
|
||||||
|
Input::AD_POSITIVE,
|
||||||
|
event.jbutton.state == SDL_PRESSED ? Input::MAX_VALUE : 0);
|
||||||
|
} // handleDirectScanCode
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -46,6 +46,9 @@ private:
|
|||||||
irr::SEvent m_irr_event;
|
irr::SEvent m_irr_event;
|
||||||
|
|
||||||
int16_t m_prev_axes[irr::SEvent::SJoystickEvent::NUMBER_OF_AXES];
|
int16_t m_prev_axes[irr::SEvent::SJoystickEvent::NUMBER_OF_AXES];
|
||||||
|
#ifdef ANDROID
|
||||||
|
void handleDirectScanCode(const SDL_Event& event);
|
||||||
|
#endif
|
||||||
public:
|
public:
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
SDLController(int device_id);
|
SDLController(int device_id);
|
||||||
@ -120,7 +123,12 @@ public:
|
|||||||
bool handleButton(const SDL_Event& event)
|
bool handleButton(const SDL_Event& event)
|
||||||
{
|
{
|
||||||
if (event.jbutton.button > m_buttons)
|
if (event.jbutton.button > m_buttons)
|
||||||
|
{
|
||||||
|
#ifdef ANDROID
|
||||||
|
handleDirectScanCode(event);
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
bool pressed = event.jbutton.state == SDL_PRESSED;
|
bool pressed = event.jbutton.state == SDL_PRESSED;
|
||||||
uint32_t value = 1 << event.jbutton.button;
|
uint32_t value = 1 << event.jbutton.button;
|
||||||
if (pressed)
|
if (pressed)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user