3
0

GesturesSystemComponent.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 "GesturesSystemComponent.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. ////////////////////////////////////////////////////////////////////////////////////////////////////
  12. namespace Gestures
  13. {
  14. ////////////////////////////////////////////////////////////////////////////////////////////////
  15. void GesturesSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  16. {
  17. provided.push_back(AZ_CRC("GestureInputService"));
  18. }
  19. ////////////////////////////////////////////////////////////////////////////////////////////////
  20. void GesturesSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  21. {
  22. incompatible.push_back(AZ_CRC("GestureInputService"));
  23. }
  24. ////////////////////////////////////////////////////////////////////////////////////////////////
  25. void GesturesSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  26. {
  27. required.push_back(AZ_CRC("InputSystemService", 0x5438d51a));
  28. }
  29. ////////////////////////////////////////////////////////////////////////////////////////////////
  30. void GesturesSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  31. {
  32. AZ_UNUSED(dependent);
  33. }
  34. ////////////////////////////////////////////////////////////////////////////////////////////////
  35. void GesturesSystemComponent::Reflect(AZ::ReflectContext* context)
  36. {
  37. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  38. {
  39. serialize->Class<GesturesSystemComponent, AZ::Component>()
  40. ->Version(0)
  41. ->Field("DoublePressConfig", &GesturesSystemComponent::m_doublePressConfig)
  42. ->Field("DragConfig", &GesturesSystemComponent::m_dragConfig)
  43. ->Field("HoldConfig", &GesturesSystemComponent::m_holdConfig)
  44. ->Field("PinchConfig", &GesturesSystemComponent::m_pinchConfig)
  45. ->Field("RotateConfig", &GesturesSystemComponent::m_rotateConfig)
  46. ->Field("SwipeConfig", &GesturesSystemComponent::m_swipeConfig)
  47. ->Field("CustomGestureConfigsByName", &GesturesSystemComponent::m_customGestureConfigsByName)
  48. ;
  49. if (AZ::EditContext* ec = serialize->GetEditContext())
  50. {
  51. ec->Class<GesturesSystemComponent>("Gestures", "Interprets raw mouse/touch input in order to detect common gestures like drag, hold, swipe, etc.")
  52. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  53. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  54. ->DataElement(0, &GesturesSystemComponent::m_doublePressConfig,
  55. "Double Press", "The config used to create the default double press gesture input channel.")
  56. ->DataElement(0, &GesturesSystemComponent::m_dragConfig,
  57. "Drag", "The config used to create the default drag gesture input channel.")
  58. ->DataElement(0, &GesturesSystemComponent::m_holdConfig,
  59. "Hold", "The config used to create the default hold gesture input channel.")
  60. ->DataElement(0, &GesturesSystemComponent::m_pinchConfig,
  61. "Pinch", "The config used to create the default pinch gesture input channel.")
  62. ->DataElement(0, &GesturesSystemComponent::m_rotateConfig,
  63. "Rotate", "The config used to create the default rotate gesture input channel.")
  64. ->DataElement(0, &GesturesSystemComponent::m_swipeConfig,
  65. "Swipe", "The config used to create the default swipe gesture input channel.")
  66. ->DataElement(0, &GesturesSystemComponent::m_customGestureConfigsByName,
  67. "Custom Gestures", "Custom gesture name/config pairs that will be used to create additional gesture input channels, in addition to the default gestures that are provided 'out of the box'.")
  68. ;
  69. }
  70. }
  71. InputDeviceGestures::Reflect(context);
  72. InputChannelGesture::Type::Reflect(context);
  73. InputChannelGestureClickOrTap::TypeAndConfig::Reflect(context);
  74. InputChannelGestureDrag::TypeAndConfig::Reflect(context);
  75. InputChannelGestureHold::TypeAndConfig::Reflect(context);
  76. InputChannelGesturePinch::TypeAndConfig::Reflect(context);
  77. InputChannelGestureRotate::TypeAndConfig::Reflect(context);
  78. InputChannelGestureSwipe::TypeAndConfig::Reflect(context);
  79. }
  80. ////////////////////////////////////////////////////////////////////////////////////////////////
  81. GesturesSystemComponent::GesturesSystemComponent()
  82. {
  83. m_doublePressConfig.minClicksOrTaps = 2;
  84. }
  85. ////////////////////////////////////////////////////////////////////////////////////////////////
  86. GesturesSystemComponent::~GesturesSystemComponent()
  87. {
  88. }
  89. ////////////////////////////////////////////////////////////////////////////////////////////////
  90. void GesturesSystemComponent::Init()
  91. {
  92. }
  93. ////////////////////////////////////////////////////////////////////////////////////////////////
  94. void GesturesSystemComponent::Activate()
  95. {
  96. // Insert all default gesture configs into a map
  97. InputDeviceGestures::ConfigsByNameMap configsByName;
  98. configsByName[InputDeviceGestures::Gesture::DoublePress.GetName()] = &m_doublePressConfig;
  99. configsByName[InputDeviceGestures::Gesture::Drag.GetName()] = &m_dragConfig;
  100. configsByName[InputDeviceGestures::Gesture::Hold.GetName()] = &m_holdConfig;
  101. configsByName[InputDeviceGestures::Gesture::Pinch.GetName()] = &m_pinchConfig;
  102. configsByName[InputDeviceGestures::Gesture::Rotate.GetName()] = &m_rotateConfig;
  103. configsByName[InputDeviceGestures::Gesture::Swipe.GetName()] = &m_swipeConfig;
  104. // Now insert any custom name/config pairs. If any of the names are the same as one of the
  105. // existing default gesture input channel ids, it will not be added to avoid any conflicts.
  106. configsByName.insert(m_customGestureConfigsByName.begin(), m_customGestureConfigsByName.end());
  107. // Create the gesture input device using the map of gesture input channels name/config pairs
  108. m_gesturesDevice.reset(aznew InputDeviceGestures(configsByName));
  109. }
  110. ////////////////////////////////////////////////////////////////////////////////////////////////
  111. void GesturesSystemComponent::Deactivate()
  112. {
  113. // Destroy the gesture input device
  114. m_gesturesDevice.reset(nullptr);
  115. }
  116. } // namespace Gestures