TrackViewNode.h 6.5 KB

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