InputChannelGestureHold.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "InputChannelGestureHold.h"
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////
  10. namespace Gestures
  11. {
  12. using namespace AzFramework;
  13. ////////////////////////////////////////////////////////////////////////////////////////////////
  14. void InputChannelGestureHold::TypeAndConfig::Reflect(AZ::ReflectContext* context)
  15. {
  16. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  17. {
  18. serialize->Class<TypeAndConfig, Type, Config>()
  19. ->Version(0)
  20. ;
  21. if (AZ::EditContext* ec = serialize->GetEditContext())
  22. {
  23. ec->Class<TypeAndConfig>("Hold", "Gesture recognizer for holds.")
  24. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  25. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  26. ;
  27. }
  28. }
  29. RecognizerHold::Config::Reflect(context);
  30. }
  31. ////////////////////////////////////////////////////////////////////////////////////////////////
  32. InputChannelGesture* InputChannelGestureHold::TypeAndConfig::CreateInputChannel(
  33. const AzFramework::InputChannelId& channelId,
  34. const AzFramework::InputDevice& inputDevice)
  35. {
  36. return aznew InputChannelGestureHold(channelId, inputDevice, *this);
  37. }
  38. ////////////////////////////////////////////////////////////////////////////////////////////////
  39. InputChannelGestureHold::InputChannelGestureHold(const InputChannelId& inputChannelId,
  40. const InputDevice& inputDevice,
  41. const Config& config)
  42. : InputChannelGesture(inputChannelId, inputDevice)
  43. , RecognizerHold(config)
  44. {
  45. RecognizerHold::Enable();
  46. }
  47. ////////////////////////////////////////////////////////////////////////////////////////////////
  48. InputChannelGestureHold::~InputChannelGestureHold()
  49. {
  50. RecognizerHold::Disable();
  51. }
  52. ////////////////////////////////////////////////////////////////////////////////////////////////
  53. float InputChannelGestureHold::GetValue() const
  54. {
  55. return InputChannel::IsActive() ? GetDuration() : 0.0f;
  56. }
  57. ////////////////////////////////////////////////////////////////////////////////////////////////
  58. const InputChannel::CustomData* InputChannelGestureHold::GetCustomData() const
  59. {
  60. return this;
  61. }
  62. ////////////////////////////////////////////////////////////////////////////////////////////////
  63. void InputChannelGestureHold::OnContinuousGestureInitiated()
  64. {
  65. UpdateNormalizedPositionAndDeltaFromScreenPosition(GetCurrentPosition());
  66. InputChannel::UpdateState(true);
  67. }
  68. ////////////////////////////////////////////////////////////////////////////////////////////////
  69. void InputChannelGestureHold::OnContinuousGestureUpdated()
  70. {
  71. UpdateNormalizedPositionAndDeltaFromScreenPosition(GetCurrentPosition());
  72. InputChannel::UpdateState(true);
  73. }
  74. ////////////////////////////////////////////////////////////////////////////////////////////////
  75. void InputChannelGestureHold::OnContinuousGestureEnded()
  76. {
  77. UpdateNormalizedPositionAndDeltaFromScreenPosition(GetCurrentPosition());
  78. InputChannel::UpdateState(false);
  79. }
  80. } // namespace Gestures