| 58 | } |
| 59 | |
| 60 | [[nodiscard]] std::optional<sf::priv::JoystickCaps> getCapabilitiesFromJni(const sf::priv::JniInputDevice& inputDevice) |
| 61 | { |
| 62 | auto motionRanges = inputDevice.getMotionRanges(); |
| 63 | if (!motionRanges) |
| 64 | { |
| 65 | sf::err() << "Gamepad was found, but its capabilities couldn't be read, skipping" << std::endl; |
| 66 | return std::nullopt; |
| 67 | } |
| 68 | |
| 69 | sf::priv::JoystickCaps capabilities = {sf::Joystick::ButtonCount, {false}}; |
| 70 | |
| 71 | for (ssize_t axisIdx = 0; axisIdx < motionRanges->getSize(); ++axisIdx) |
| 72 | { |
| 73 | auto motionRange = (*motionRanges)[axisIdx]; |
| 74 | if (!motionRange) |
| 75 | { |
| 76 | sf::err() << "Gamepad was found, but its capabilities couldn't be read, skipping" << std::endl; |
| 77 | return std::nullopt; |
| 78 | } |
| 79 | |
| 80 | if (const auto axis = androidAxisToSf(motionRange->getAxis())) |
| 81 | capabilities.axes[*axis] = true; |
| 82 | } |
| 83 | |
| 84 | return capabilities; |
| 85 | } |
| 86 | } // namespace |
| 87 | |
| 88 | namespace sf::priv |
no test coverage detected