GeometryComponent.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/Math/Vector2.h>
  11. #include <GraphCanvas/Components/EntitySaveDataBus.h>
  12. #include <GraphCanvas/Components/GeometryBus.h>
  13. #include <GraphCanvas/Components/SceneBus.h>
  14. #include <GraphCanvas/Components/VisualBus.h>
  15. #include <GraphCanvas/Types/EntitySaveData.h>
  16. namespace GraphCanvas
  17. {
  18. //! A component that gives a visual coordinates.
  19. class GeometryComponent
  20. : public AZ::Component
  21. , public GeometryRequestBus::Handler
  22. , public VisualNotificationBus::Handler
  23. , public SceneMemberNotificationBus::Handler
  24. , public EntitySaveDataRequestBus::Handler
  25. {
  26. public:
  27. static const float IS_CLOSE_TOLERANCE;
  28. AZ_COMPONENT(GeometryComponent, "{DFD3FDE1-9856-41C9-AEF1-DD5B647A2B92}");
  29. static void Reflect(AZ::ReflectContext*);
  30. GeometryComponent();
  31. virtual ~GeometryComponent();
  32. // AZ::Component
  33. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  34. {
  35. provided.push_back(AZ_CRC("GraphCanvas_GeometryService", 0x80981600));
  36. }
  37. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  38. {
  39. (void)dependent;
  40. }
  41. static void GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  42. {
  43. }
  44. ////
  45. // AZ::Component
  46. void Init() override;
  47. void Activate() override;
  48. void Deactivate() override;
  49. ////
  50. // SceneMemberNotificationBus
  51. void OnSceneSet(const AZ::EntityId& scene) override;
  52. ////
  53. // GeometryRequestBus
  54. AZ::Vector2 GetPosition() const override;
  55. void SetPosition(const AZ::Vector2& position) override;
  56. void SignalBoundsChanged() override;
  57. void SetIsPositionAnimating(bool animating) override;
  58. void SetAnimationTarget(const AZ::Vector2& targetPoint) override;
  59. ////
  60. // VisualNotificationBus
  61. void OnItemChange(const AZ::EntityId& entityId, QGraphicsItem::GraphicsItemChange, const QVariant&) override;
  62. ////
  63. // EntitySaveDataRequestBus
  64. void WriteSaveData(EntitySaveDataContainer& saveDataContainer) const override;
  65. void ReadSaveData(const EntitySaveDataContainer& saveDataContainer) override;
  66. ////
  67. private:
  68. void ForceSetPosition(const AZ::Vector2& forcedPosition);
  69. bool IsAnimating() const;
  70. GeometrySaveData m_saveData;
  71. bool m_animating;
  72. AZ::Vector2 m_animatingPosition;
  73. };
  74. }