TrackViewNode.h 6.6 KB

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