Files
o3de/Gems/Gestures/Code/Source/InputChannelGesturePinch.cpp
T
2021-06-23 10:55:22 -07:00

95 lines
3.6 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "Gestures_precompiled.h"
#include "InputChannelGesturePinch.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Gestures
{
using namespace AzFramework;
////////////////////////////////////////////////////////////////////////////////////////////////
void InputChannelGesturePinch::TypeAndConfig::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<TypeAndConfig, Type, Config>()
->Version(0)
;
if (AZ::EditContext* ec = serialize->GetEditContext())
{
ec->Class<TypeAndConfig>("Pinch", "Gesture recognizer for pinches.")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
;
}
}
RecognizerPinch::Config::Reflect(context);
}
////////////////////////////////////////////////////////////////////////////////////////////////
InputChannelGesture* InputChannelGesturePinch::TypeAndConfig::CreateInputChannel(
const AzFramework::InputChannelId& channelId,
const AzFramework::InputDevice& inputDevice)
{
return aznew InputChannelGesturePinch(channelId, inputDevice, *this);
}
////////////////////////////////////////////////////////////////////////////////////////////////
InputChannelGesturePinch::InputChannelGesturePinch(const InputChannelId& inputChannelId,
const InputDevice& inputDevice,
const Config& config)
: InputChannelGesture(inputChannelId, inputDevice)
, RecognizerPinch(config)
{
RecognizerPinch::Enable();
}
////////////////////////////////////////////////////////////////////////////////////////////////
InputChannelGesturePinch::~InputChannelGesturePinch()
{
RecognizerPinch::Disable();
}
////////////////////////////////////////////////////////////////////////////////////////////////
float InputChannelGesturePinch::GetValue() const
{
return InputChannel::IsActive() ? GetPinchRatio() : 0.0f;
}
////////////////////////////////////////////////////////////////////////////////////////////////
const InputChannel::CustomData* InputChannelGesturePinch::GetCustomData() const
{
return this;
}
////////////////////////////////////////////////////////////////////////////////////////////////
void InputChannelGesturePinch::OnContinuousGestureInitiated()
{
UpdateNormalizedPositionAndDeltaFromScreenPosition(GetCurrentMidpoint());
InputChannel::UpdateState(true);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void InputChannelGesturePinch::OnContinuousGestureUpdated()
{
UpdateNormalizedPositionAndDeltaFromScreenPosition(GetCurrentMidpoint());
InputChannel::UpdateState(true);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void InputChannelGesturePinch::OnContinuousGestureEnded()
{
UpdateNormalizedPositionAndDeltaFromScreenPosition(GetCurrentMidpoint());
InputChannel::UpdateState(false);
}
} // namespace Gestures