Add InputChannel API to disable forwarding events to the underyling device

Signed-off-by: nvsickle <nvsickle@amazon.com>
This commit is contained in:
nvsickle
2021-06-16 12:01:56 -07:00
parent ab354f2e9b
commit 8e51a4763f
2 changed files with 30 additions and 1 deletions
@@ -327,7 +327,7 @@ namespace AzFramework
break;
}
if (m_state != State::Idle)
if (m_state != State::Idle && m_shouldDispatchEvents)
{
bool hasBeenConsumed = false;
InputChannelNotificationBus::Broadcast(&InputChannelNotifications::OnInputChannelEvent,
@@ -350,4 +350,22 @@ namespace AzFramework
// Directly return the channel to the 'Idle' state
m_state = State::Idle;
}
////////////////////////////////////////////////////////////////////////////////////////////////
void InputChannel::SetUpdateEventsEnabled(bool enabled)
{
if (m_shouldDispatchEvents != enabled)
{
m_shouldDispatchEvents = enabled;
const InputChannelRequests::BusIdType busId(m_inputChannelId, m_inputDevice.GetInputDeviceId().GetIndex());
if (enabled)
{
InputChannelRequestBus::Handler::BusConnect(busId);
}
else
{
InputChannelRequestBus::Handler::BusDisconnect(busId);
}
}
}
} // namespace AzFramework
@@ -218,12 +218,23 @@ namespace AzFramework
//! \ref AzFramework::InputChannelRequests::ResetState
void ResetState() override;
////////////////////////////////////////////////////////////////////////////////////////////
//! Sets whether or not the channel shall broadcast to the InputChannelNotificationBus when
//! its internal state is updated.
//! This can be disabled to allow for testing or synthetic events that aren't part of the
//! input system.
void SetUpdateEventsEnabled(bool enabled);
private:
////////////////////////////////////////////////////////////////////////////////////////////
// Variables
const InputChannelId m_inputChannelId; //!< Id of the input channel
const InputDevice& m_inputDevice; //!< Input device that owns the input channel
State m_state; //!< Current state of the input channel
//! If true, &InputChannelNotifications::OnInputChannelEvent will be fired when UpdateState
//! is called.
bool m_shouldDispatchEvents = true;
};
////////////////////////////////////////////////////////////////////////////////////////////////