2024-09-06 22:23:32 -03:00
|
|
|
#include "xna-dx/framework.hpp"
|
2024-06-03 21:55:09 -03:00
|
|
|
#include "xna/input/gamepad.hpp"
|
2024-04-17 20:21:17 -03:00
|
|
|
|
|
|
|
namespace xna {
|
2024-05-21 09:40:59 -03:00
|
|
|
void GamePad::Initialize() {
|
2024-06-22 16:24:11 -03:00
|
|
|
impl = unew<PlatformImplementation>();
|
2024-05-21 09:40:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
GamePadState GamePad::GetState(PlayerIndex index) {
|
|
|
|
if (!impl || !impl->_dxGamePad)
|
2024-04-24 10:11:53 -03:00
|
|
|
return GamePadState();
|
2024-04-17 20:21:17 -03:00
|
|
|
|
2024-05-21 09:40:59 -03:00
|
|
|
const auto state = impl->_dxGamePad->GetState(
|
2024-04-24 10:11:53 -03:00
|
|
|
static_cast<int>(index)
|
|
|
|
);
|
2024-05-21 09:40:59 -03:00
|
|
|
|
2024-08-01 14:32:23 -03:00
|
|
|
const auto buttons = GamePadButtons(
|
2024-05-21 09:40:59 -03:00
|
|
|
static_cast<ButtonState>(state.buttons.a),
|
|
|
|
static_cast<ButtonState>(state.buttons.b),
|
|
|
|
static_cast<ButtonState>(state.buttons.x),
|
|
|
|
static_cast<ButtonState>(state.buttons.y),
|
|
|
|
static_cast<ButtonState>(state.buttons.leftStick),
|
|
|
|
static_cast<ButtonState>(state.buttons.rightStick),
|
|
|
|
static_cast<ButtonState>(state.buttons.leftShoulder),
|
|
|
|
static_cast<ButtonState>(state.buttons.rightShoulder),
|
|
|
|
static_cast<ButtonState>(state.buttons.back),
|
|
|
|
static_cast<ButtonState>(state.buttons.start),
|
|
|
|
static_cast<ButtonState>(state.buttons.view));
|
2024-08-01 14:32:23 -03:00
|
|
|
|
|
|
|
const auto dpad = GamePadDPad(
|
|
|
|
static_cast<ButtonState>(state.dpad.up),
|
|
|
|
static_cast<ButtonState>(state.dpad.right),
|
|
|
|
static_cast<ButtonState>(state.dpad.down),
|
|
|
|
static_cast<ButtonState>(state.dpad.left));
|
|
|
|
|
|
|
|
const auto isConnected = state.connected;
|
|
|
|
|
|
|
|
const auto thumbSticks = GamePadThumbSticks(
|
|
|
|
Vector2(state.thumbSticks.leftX, state.thumbSticks.leftY),
|
|
|
|
Vector2(state.thumbSticks.rightX, state.thumbSticks.rightY));
|
|
|
|
const auto triggers = GamePadTriggers(state.triggers.left, state.triggers.right);
|
|
|
|
|
|
|
|
const auto pad = GamePadState(thumbSticks, triggers, buttons, dpad, isConnected);
|
2024-05-21 09:40:59 -03:00
|
|
|
return pad;
|
2024-04-24 10:11:53 -03:00
|
|
|
}
|
|
|
|
|
2024-05-21 09:40:59 -03:00
|
|
|
GamePadState GamePad::GetState(PlayerIndex index, GamePadDeadZone deadZone) {
|
|
|
|
if (!impl || !impl->_dxGamePad)
|
2024-04-24 10:11:53 -03:00
|
|
|
return GamePadState();
|
|
|
|
|
2024-05-21 09:40:59 -03:00
|
|
|
const auto state = impl->_dxGamePad->GetState(
|
2024-04-24 10:11:53 -03:00
|
|
|
static_cast<int>(index),
|
|
|
|
static_cast<DirectX::GamePad::DeadZone>(deadZone)
|
|
|
|
);
|
2024-08-01 14:32:23 -03:00
|
|
|
|
|
|
|
const auto buttons = GamePadButtons(
|
|
|
|
static_cast<ButtonState>(state.buttons.a),
|
|
|
|
static_cast<ButtonState>(state.buttons.b),
|
|
|
|
static_cast<ButtonState>(state.buttons.x),
|
|
|
|
static_cast<ButtonState>(state.buttons.y),
|
|
|
|
static_cast<ButtonState>(state.buttons.leftStick),
|
|
|
|
static_cast<ButtonState>(state.buttons.rightStick),
|
|
|
|
static_cast<ButtonState>(state.buttons.leftShoulder),
|
|
|
|
static_cast<ButtonState>(state.buttons.rightShoulder),
|
|
|
|
static_cast<ButtonState>(state.buttons.back),
|
|
|
|
static_cast<ButtonState>(state.buttons.start),
|
|
|
|
static_cast<ButtonState>(state.buttons.view));
|
2024-05-21 09:40:59 -03:00
|
|
|
|
2024-08-01 14:32:23 -03:00
|
|
|
const auto dpad = GamePadDPad(
|
2024-05-21 09:40:59 -03:00
|
|
|
static_cast<ButtonState>(state.dpad.up),
|
|
|
|
static_cast<ButtonState>(state.dpad.right),
|
|
|
|
static_cast<ButtonState>(state.dpad.down),
|
|
|
|
static_cast<ButtonState>(state.dpad.left));
|
|
|
|
|
2024-08-01 14:32:23 -03:00
|
|
|
const auto isConnected = state.connected;
|
|
|
|
|
|
|
|
const auto thumbSticks = GamePadThumbSticks(
|
2024-05-21 09:40:59 -03:00
|
|
|
Vector2(state.thumbSticks.leftX, state.thumbSticks.leftY),
|
|
|
|
Vector2(state.thumbSticks.rightX, state.thumbSticks.rightY));
|
2024-08-01 14:32:23 -03:00
|
|
|
const auto triggers = GamePadTriggers(state.triggers.left, state.triggers.right);
|
2024-05-21 09:40:59 -03:00
|
|
|
|
2024-08-01 14:32:23 -03:00
|
|
|
const auto pad = GamePadState(thumbSticks, triggers, buttons, dpad, isConnected);
|
2024-05-21 09:40:59 -03:00
|
|
|
return pad;
|
2024-04-24 10:11:53 -03:00
|
|
|
}
|
|
|
|
|
2024-05-21 09:40:59 -03:00
|
|
|
GamePadCapabilities GamePad::GetCapabilities(PlayerIndex index) {
|
|
|
|
if (!impl || !impl->_dxGamePad)
|
2024-04-24 10:11:53 -03:00
|
|
|
return GamePadCapabilities();
|
|
|
|
|
2024-05-21 09:40:59 -03:00
|
|
|
const auto capabilities = impl->_dxGamePad->GetCapabilities(static_cast<int>(index));
|
2024-08-01 14:32:23 -03:00
|
|
|
const auto gamePadType = static_cast<GamePadCapabilitiesType>(capabilities.gamepadType);
|
|
|
|
const auto cap = GamePadCapabilities(
|
|
|
|
capabilities.connected,
|
|
|
|
gamePadType);
|
|
|
|
|
2024-05-21 09:40:59 -03:00
|
|
|
return cap;
|
2024-04-24 10:11:53 -03:00
|
|
|
}
|
|
|
|
|
2024-05-21 09:40:59 -03:00
|
|
|
bool GamePad::SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger) {
|
|
|
|
if (!impl || !impl->_dxGamePad)
|
2024-04-24 10:11:53 -03:00
|
|
|
return false;
|
|
|
|
|
2024-05-21 09:40:59 -03:00
|
|
|
return impl->_dxGamePad->SetVibration(static_cast<int>(index), leftMotor, rightMotor, leftTrigger, rightTrigger);
|
2024-04-24 10:11:53 -03:00
|
|
|
}
|
2024-04-17 20:21:17 -03:00
|
|
|
}
|