InputChannelGestureClickOrTap.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "InputChannelGestureClickOrTap.h"
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////
  10. namespace Gestures
  11. {
  12. using namespace AzFramework;
  13. ////////////////////////////////////////////////////////////////////////////////////////////////
  14. void InputChannelGestureClickOrTap::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>("Click Or Tap", "Gesture recognizer for clicks or taps.")
  24. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  25. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  26. ;
  27. }
  28. }
  29. RecognizerClickOrTap::Config::Reflect(context);
  30. }
  31. ////////////////////////////////////////////////////////////////////////////////////////////////
  32. InputChannelGesture* InputChannelGestureClickOrTap::TypeAndConfig::CreateInputChannel(
  33. const AzFramework::InputChannelId& channelId,
  34. const AzFramework::InputDevice& inputDevice)
  35. {
  36. return aznew InputChannelGestureClickOrTap(channelId, inputDevice, *this);
  37. }
  38. ////////////////////////////////////////////////////////////////////////////////////////////////
  39. InputChannelGestureClickOrTap::InputChannelGestureClickOrTap(const InputChannelId& inputChannelId,
  40. const InputDevice& inputDevice,
  41. const Config& config)
  42. : InputChannelGesture(inputChannelId, inputDevice)
  43. , RecognizerClickOrTap(config)
  44. {
  45. RecognizerClickOrTap::Enable();
  46. }
  47. ////////////////////////////////////////////////////////////////////////////////////////////////
  48. InputChannelGestureClickOrTap::~InputChannelGestureClickOrTap()
  49. {
  50. RecognizerClickOrTap::Disable();
  51. }
  52. ////////////////////////////////////////////////////////////////////////////////////////////////
  53. float InputChannelGestureClickOrTap::GetValue() const
  54. {
  55. return InputChannel::IsActive() ? GetConfig().minClicksOrTaps : 0.0f;
  56. }
  57. ////////////////////////////////////////////////////////////////////////////////////////////////
  58. const InputChannel::CustomData* InputChannelGestureClickOrTap::GetCustomData() const
  59. {
  60. return this;
  61. }
  62. ////////////////////////////////////////////////////////////////////////////////////////////////
  63. void InputChannelGestureClickOrTap::OnDiscreteGestureRecognized()
  64. {
  65. // Discrete gestures simply dispatch one-off 'fire and forget' events.
  66. UpdateNormalizedPositionAndDeltaFromScreenPosition(GetEndPosition());
  67. InputChannel::UpdateState(true);
  68. InputChannel::UpdateState(false);
  69. }
  70. } // namespace Gestures