EntityHelpers.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <AzToolsFramework/API/ToolsApplicationAPI.h>
  10. namespace EntityHelpers
  11. {
  12. using EntityIdList = AzToolsFramework::EntityIdList;
  13. using EntityToHierarchyItemMap = std::map< AZ::EntityId, HierarchyItem* >;
  14. AZ::Vector2 RoundXY(const AZ::Vector2& v);
  15. AZ::Vector3 RoundXY(const AZ::Vector3& v);
  16. AZ::Vector3 MakeVec3(const AZ::Vector2& v);
  17. float Snap(float value, float snapDistance);
  18. AZ::Vector2 Snap(const AZ::Vector2& v, float snapDistance);
  19. UiTransform2dInterface::Offsets Snap(const UiTransform2dInterface::Offsets& offs, const ViewportHelpers::ElementEdges& grabbedEdges, float snapDistance);
  20. void MoveElementToGlobalPosition(AZ::Entity* element, const QPoint& globalPos);
  21. //! Helper function to get parent element using Ebus.
  22. AZ::Entity* GetParentElement(const AZ::Entity* element);
  23. AZ::Entity* GetParentElement(const AZ::EntityId& elementId);
  24. AZ::Entity* GetEntity(AZ::EntityId id);
  25. void ComputeCanvasSpaceRectNoScaleRotate(AZ::EntityId elementId, UiTransform2dInterface::Offsets offsets, UiTransformInterface::Rect& rect);
  26. AZ::Vector2 ComputeCanvasSpacePivotNoScaleRotate(AZ::EntityId elementId, UiTransform2dInterface::Offsets offsets);
  27. AZStd::string GetHierarchicalElementName(AZ::EntityId entityId);
  28. //! Returns the common ancestor of element1 and element2 and also the children of that common ancestor
  29. //! that element1 and element2 are descended from
  30. AZ::Entity* GetCommonAncestor(AZ::Entity* element1, AZ::Entity* element2,
  31. AZ::Entity*& element1NextAncestor, AZ::Entity*& element2NextAncestor);
  32. //! returns true if element1 is before element2 in the element hierarchy
  33. bool CompareOrderInElementHierarchy(AZ::Entity* element1, AZ::Entity* element2);
  34. //! Move an element by a local pixel offset using the offsets
  35. void MoveByLocalDeltaUsingOffsets(AZ::EntityId entityId, AZ::Vector2 deltaInLocalSpace);
  36. //! Move an element by a local pixel offset using the offsets from a given starting offset
  37. void MoveByLocalDeltaUsingOffsets(AZ::EntityId entityId, const UiTransform2dInterface::Offsets& startingOffsets, AZ::Vector2 deltaInLocalSpace);
  38. //! Move an element by a local pixel offset using the anchors
  39. AZ::Vector2 MoveByLocalDeltaUsingAnchors(AZ::EntityId entityId, AZ::EntityId parentEntityId, AZ::Vector2 deltaInLocalSpace, bool restrictDirection);
  40. //! Move an element by a local pixel offset using the anchors from a given starting offset
  41. AZ::Vector2 MoveByLocalDeltaUsingAnchors(AZ::EntityId entityId, AZ::EntityId parentEntityId,
  42. const UiTransform2dInterface::Anchors& startingAnchors, AZ::Vector2 deltaInLocalSpace, bool restrictDirection);
  43. //! Given a delta in canvas space transform it to local space. Note: for a move you want to pass in the parent element
  44. AZ::Vector2 TransformDeltaFromCanvasToLocalSpace(AZ::EntityId entityId, AZ::Vector2 deltaInCanvasSpace);
  45. //! Given a delta in local space transform it to canvas space. Note: for a move you want to pass in the parent element
  46. AZ::Vector2 TransformDeltaFromLocalToCanvasSpace(AZ::EntityId entityId, AZ::Vector2 deltaInLocalSpace);
  47. //! Given a delta in viewport space transform it to canvas space.
  48. AZ::Vector2 TransformDeltaFromViewportToCanvasSpace(AZ::EntityId canvasEntityId, AZ::Vector2 deltaInViewportSpace);
  49. } // namespace EntityHelpers