UiAnimViewNode.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 <LyShine/Animation/IUiAnimation.h>
  10. class CUiAnimViewTrack;
  11. class CUiAnimViewSequence;
  12. class CUiAnimViewAnimNode;
  13. class CUiAnimViewKeyConstHandle
  14. {
  15. public:
  16. CUiAnimViewKeyConstHandle()
  17. : m_keyIndex(0)
  18. , m_pTrack(nullptr) {}
  19. CUiAnimViewKeyConstHandle(const CUiAnimViewTrack* pTrack, unsigned int keyIndex)
  20. : m_keyIndex(keyIndex)
  21. , m_pTrack(pTrack) {}
  22. void GetKey(IKey* pKey) const;
  23. float GetTime() const;
  24. const CUiAnimViewTrack* GetTrack() const { return m_pTrack; }
  25. private:
  26. unsigned int m_keyIndex;
  27. const CUiAnimViewTrack* m_pTrack;
  28. };
  29. // Represents one UI Animation system key
  30. class CUiAnimViewKeyHandle
  31. {
  32. public:
  33. CUiAnimViewKeyHandle()
  34. : m_bIsValid(false)
  35. , m_keyIndex(0)
  36. , m_pTrack(nullptr) {}
  37. CUiAnimViewKeyHandle(CUiAnimViewTrack* pTrack, unsigned int keyIndex)
  38. : m_bIsValid(true)
  39. , m_keyIndex(keyIndex)
  40. , m_pTrack(pTrack) {}
  41. void SetKey(IKey* pKey);
  42. void GetKey(IKey* pKey) const;
  43. CUiAnimViewTrack* GetTrack() { return m_pTrack; }
  44. const CUiAnimViewTrack* GetTrack() const { return m_pTrack; }
  45. bool IsValid() const { return m_bIsValid; }
  46. unsigned int GetIndex() const { return m_keyIndex; }
  47. void Select(bool bSelect);
  48. bool IsSelected() const;
  49. void SetTime(float time);
  50. float GetTime() const;
  51. float GetDuration() const;
  52. const char* GetDescription() const;
  53. void Offset(float offset);
  54. bool operator==(const CUiAnimViewKeyHandle& keyHandle) const;
  55. bool operator!=(const CUiAnimViewKeyHandle& keyHandle) const;
  56. // Deletes key. Note that handle will be invalid afterwards
  57. void Delete();
  58. CUiAnimViewKeyHandle Clone();
  59. // Get next/prev/above/below key in expanded node tree
  60. // Note: Key is assumed to be already visible
  61. CUiAnimViewKeyHandle GetNextKey();
  62. CUiAnimViewKeyHandle GetPrevKey();
  63. CUiAnimViewKeyHandle GetAboveKey() const;
  64. CUiAnimViewKeyHandle GetBelowKey() const;
  65. private:
  66. bool m_bIsValid;
  67. unsigned int m_keyIndex;
  68. CUiAnimViewTrack* m_pTrack;
  69. };
  70. // Abstract base class that defines common
  71. // operations for key bundles and tracks
  72. class IUiAnimViewKeyBundle
  73. {
  74. public:
  75. virtual bool AreAllKeysOfSameType() const = 0;
  76. virtual unsigned int GetKeyCount() const = 0;
  77. virtual CUiAnimViewKeyHandle GetKey(unsigned int index) = 0;
  78. virtual void SelectKeys(const bool bSelected) = 0;
  79. };
  80. // Represents a bundle of keys
  81. class CUiAnimViewKeyBundle
  82. : public IUiAnimViewKeyBundle
  83. {
  84. friend class CUiAnimViewTrack;
  85. friend class CUiAnimViewAnimNode;
  86. friend class CUiAnimViewEventNode;
  87. public:
  88. CUiAnimViewKeyBundle()
  89. : m_bAllOfSameType(true) {}
  90. virtual ~CUiAnimViewKeyBundle() = default;
  91. virtual bool AreAllKeysOfSameType() const override { return m_bAllOfSameType; }
  92. virtual unsigned int GetKeyCount() const override { return static_cast<unsigned int>(m_keys.size()); }
  93. virtual CUiAnimViewKeyHandle GetKey(unsigned int index) override { return m_keys[index]; }
  94. virtual void SelectKeys(const bool bSelected) override;
  95. CUiAnimViewKeyHandle GetSingleSelectedKey();
  96. private:
  97. void AppendKey(const CUiAnimViewKeyHandle& keyHandle);
  98. void AppendKeyBundle(const CUiAnimViewKeyBundle& bundle);
  99. bool m_bAllOfSameType;
  100. std::vector<CUiAnimViewKeyHandle> m_keys;
  101. };
  102. // Types of nodes that derive from CUiAnimViewNode
  103. enum EUiAnimViewNodeType
  104. {
  105. eUiAVNT_Sequence,
  106. eUiAVNT_AnimNode,
  107. eUiAVNT_Track
  108. };
  109. ////////////////////////////////////////////////////////////////////////////
  110. //
  111. // This is the base class for all sequences, nodes and tracks in UiAnimView,
  112. // which provides a interface for common operations
  113. //
  114. ////////////////////////////////////////////////////////////////////////////
  115. class CUiAnimViewNode
  116. {
  117. friend class CAbstractUndoTrackTransaction;
  118. public:
  119. CUiAnimViewNode(CUiAnimViewNode* pParent);
  120. virtual ~CUiAnimViewNode() {}
  121. // Name
  122. virtual AZStd::string GetName() const = 0;
  123. virtual bool SetName([[maybe_unused]] const char* pName) { return false; };
  124. virtual bool CanBeRenamed() const { return false; }
  125. // UI Animation system node type
  126. virtual EUiAnimViewNodeType GetNodeType() const = 0;
  127. // Get the sequence of this node
  128. CUiAnimViewSequence* GetSequence();
  129. // Get parent
  130. CUiAnimViewNode* GetParentNode() const { return m_pParentNode; }
  131. // Children
  132. unsigned int GetChildCount() const { return static_cast<unsigned int>(m_childNodes.size()); }
  133. CUiAnimViewNode* GetChild(unsigned int index) const { return m_childNodes[index].get(); }
  134. // Snap time value to prev/next key in sequence
  135. virtual bool SnapTimeToPrevKey(float& time) const = 0;
  136. virtual bool SnapTimeToNextKey(float& time) const = 0;
  137. // Selection state
  138. virtual void SetSelected(bool bSelected);
  139. virtual bool IsSelected() const { return m_bSelected; }
  140. // Clear selection of this node and all sub nodes
  141. void ClearSelection();
  142. // Expanded state
  143. virtual void SetExpanded(bool bExpanded);
  144. virtual bool IsExpanded() const { return m_bExpanded; }
  145. // Disabled state
  146. virtual void SetDisabled([[maybe_unused]] bool bDisabled) {}
  147. virtual bool IsDisabled() const { return false; }
  148. // Hidden state
  149. void SetHidden(bool bHidden);
  150. bool IsHidden() const;
  151. // Key getters
  152. virtual CUiAnimViewKeyBundle GetSelectedKeys() = 0;
  153. virtual CUiAnimViewKeyBundle GetAllKeys() = 0;
  154. virtual CUiAnimViewKeyBundle GetKeysInTimeRange(const float t0, const float t1) = 0;
  155. // Check if node itself is obsolete, or any child is an obsolete track
  156. bool HasObsoleteTrack() const;
  157. // Get above/below nodes in pCurrentNode node tree
  158. CUiAnimViewNode* GetAboveNode() const;
  159. CUiAnimViewNode* GetBelowNode() const;
  160. // Get previous or next sibling of this node
  161. CUiAnimViewNode* GetPrevSibling() const;
  162. CUiAnimViewNode* GetNextSibling() const;
  163. // Check if it's a group node
  164. virtual bool IsGroupNode() const { return false; }
  165. // Copy selected keys to XML representation for clipboard
  166. virtual void CopyKeysToClipboard(XmlNodeRef& xmlNode, const bool bOnlySelectedKeys, const bool bOnlyFromSelectedTracks) = 0;
  167. // Sorting
  168. bool operator<(const CUiAnimViewNode& pOtherNode) const;
  169. // Get first selected node in tree
  170. CUiAnimViewNode* GetFirstSelectedNode();
  171. // Get director of this node
  172. CUiAnimViewAnimNode* GetDirector();
  173. protected:
  174. void AddNode(CUiAnimViewNode* pNode);
  175. void SortNodes();
  176. bool HasObsoleteTrackRec(const CUiAnimViewNode* pCurrentNode) const;
  177. CUiAnimViewNode* m_pParentNode;
  178. std::vector<std::unique_ptr<CUiAnimViewNode> > m_childNodes;
  179. bool m_bSelected;
  180. bool m_bExpanded;
  181. bool m_bHidden;
  182. };