TrackViewNode.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. #include "EditorDefs.h"
  9. #include "TrackViewNode.h"
  10. // CryCommon
  11. #include <CryCommon/Maestro/Types/AnimNodeType.h>
  12. // AzCore
  13. #include <AzCore/std/sort.h>
  14. // Editor
  15. #include "TrackView/TrackViewTrack.h"
  16. #include "TrackView/TrackViewSequence.h"
  17. ////////////////////////////////////////////////////////////////////////////
  18. void CTrackViewKeyConstHandle::GetKey(IKey* pKey) const
  19. {
  20. m_pTrack->GetKey(m_keyIndex, pKey);
  21. }
  22. ////////////////////////////////////////////////////////////////////////////
  23. float CTrackViewKeyConstHandle::GetTime() const
  24. {
  25. return m_pTrack->GetKeyTime(m_keyIndex);
  26. }
  27. ////////////////////////////////////////////////////////////////////////////
  28. void CTrackViewKeyHandle::SetKey(IKey* pKey)
  29. {
  30. assert(m_bIsValid);
  31. m_pTrack->SetKey(m_keyIndex, pKey);
  32. }
  33. ////////////////////////////////////////////////////////////////////////////
  34. void CTrackViewKeyHandle::GetKey(IKey* pKey) const
  35. {
  36. assert(m_bIsValid);
  37. m_pTrack->GetKey(m_keyIndex, pKey);
  38. }
  39. ////////////////////////////////////////////////////////////////////////////
  40. void CTrackViewKeyHandle::Select(bool bSelect)
  41. {
  42. assert(m_bIsValid);
  43. m_pTrack->SelectKey(m_keyIndex, bSelect);
  44. }
  45. ////////////////////////////////////////////////////////////////////////////
  46. bool CTrackViewKeyHandle::IsSelected() const
  47. {
  48. assert(m_bIsValid);
  49. return m_pTrack->IsKeySelected(m_keyIndex);
  50. }
  51. ////////////////////////////////////////////////////////////////////////////
  52. void CTrackViewKeyHandle::SetTime(float time, bool notifyListeners)
  53. {
  54. AZ_Assert(m_bIsValid, "Expected a valid key handle.");
  55. // Flag the current key, because the key handle may become invalid
  56. // after the time is set and it is potentially sorted into a different
  57. // index.
  58. m_pTrack->SetSortMarkerKey(m_keyIndex, true);
  59. // set the new time, this may cause a sort that reorders the keys, making
  60. // m_keyIndex incorrect.
  61. m_pTrack->SetKeyTime(m_keyIndex, time, notifyListeners);
  62. // If the key at this index changed because of the key sort by time.
  63. // We need to search through the keys now and find the marker.
  64. if (!m_pTrack->IsSortMarkerKey(m_keyIndex))
  65. {
  66. CTrackViewKeyBundle allKeys = m_pTrack->GetAllKeys();
  67. for (unsigned int x = 0; x < allKeys.GetKeyCount(); x++)
  68. {
  69. unsigned int curIndex = allKeys.GetKey(x).GetIndex();
  70. if (m_pTrack->IsSortMarkerKey(curIndex))
  71. {
  72. m_keyIndex = curIndex;
  73. break;
  74. }
  75. }
  76. }
  77. // clear the sort marker
  78. m_pTrack->SetSortMarkerKey(m_keyIndex, false);
  79. }
  80. ////////////////////////////////////////////////////////////////////////////
  81. float CTrackViewKeyHandle::GetTime() const
  82. {
  83. assert(m_bIsValid);
  84. return m_pTrack->GetKeyTime(m_keyIndex);
  85. }
  86. ////////////////////////////////////////////////////////////////////////////
  87. float CTrackViewKeyHandle::GetDuration() const
  88. {
  89. assert(m_bIsValid);
  90. const char* desc = nullptr;
  91. float duration = 0;
  92. m_pTrack->m_pAnimTrack->GetKeyInfo(m_keyIndex, desc, duration);
  93. return duration;
  94. }
  95. ////////////////////////////////////////////////////////////////////////////
  96. const char* CTrackViewKeyHandle::GetDescription() const
  97. {
  98. assert(m_bIsValid);
  99. const char* desc = "";
  100. float duration = 0;
  101. m_pTrack->m_pAnimTrack->GetKeyInfo(m_keyIndex, desc, duration);
  102. return desc;
  103. }
  104. ////////////////////////////////////////////////////////////////////////////
  105. void CTrackViewKeyHandle::Offset(float offset, bool notifyListeners)
  106. {
  107. AZ_Assert(m_bIsValid, "Expected key handle to be in a valid state.");
  108. float newTime = m_pTrack->GetKeyTime(m_keyIndex) + offset;
  109. m_pTrack->SetKeyTime(m_keyIndex, newTime, notifyListeners);
  110. }
  111. ////////////////////////////////////////////////////////////////////////////
  112. void CTrackViewKeyHandle::Delete()
  113. {
  114. assert(m_bIsValid);
  115. m_pTrack->RemoveKey(m_keyIndex);
  116. m_bIsValid = false;
  117. }
  118. ////////////////////////////////////////////////////////////////////////////
  119. CTrackViewKeyHandle CTrackViewKeyHandle::Clone()
  120. {
  121. assert(m_bIsValid);
  122. unsigned int newKeyIndex = m_pTrack->CloneKey(m_keyIndex);
  123. return CTrackViewKeyHandle(m_pTrack, newKeyIndex);
  124. }
  125. ////////////////////////////////////////////////////////////////////////////
  126. CTrackViewKeyHandle CTrackViewKeyHandle::GetNextKey()
  127. {
  128. return m_pTrack->GetNextKey(GetTime());
  129. }
  130. ////////////////////////////////////////////////////////////////////////////
  131. CTrackViewKeyHandle CTrackViewKeyHandle::GetPrevKey()
  132. {
  133. return m_pTrack->GetPrevKey(GetTime());
  134. }
  135. ////////////////////////////////////////////////////////////////////////////
  136. CTrackViewKeyHandle CTrackViewKeyHandle::GetAboveKey() const
  137. {
  138. // Search for track above that has keys
  139. for (CTrackViewNode* pCurrentNode = m_pTrack->GetAboveNode(); pCurrentNode; pCurrentNode = pCurrentNode->GetAboveNode())
  140. {
  141. if (pCurrentNode->GetNodeType() == eTVNT_Track)
  142. {
  143. CTrackViewTrack* pCurrentTrack = static_cast<CTrackViewTrack*>(pCurrentNode);
  144. const unsigned int keyCount = pCurrentTrack->GetKeyCount();
  145. if (keyCount > 0)
  146. {
  147. // Return key with nearest time to this key
  148. return pCurrentTrack->GetNearestKeyByTime(GetTime());
  149. }
  150. }
  151. }
  152. return CTrackViewKeyHandle();
  153. }
  154. ////////////////////////////////////////////////////////////////////////////
  155. CTrackViewKeyHandle CTrackViewKeyHandle::GetBelowKey() const
  156. {
  157. // Search for track below that has keys
  158. for (CTrackViewNode* pCurrentNode = m_pTrack->GetBelowNode(); pCurrentNode; pCurrentNode = pCurrentNode->GetBelowNode())
  159. {
  160. if (pCurrentNode->GetNodeType() == eTVNT_Track)
  161. {
  162. CTrackViewTrack* pCurrentTrack = static_cast<CTrackViewTrack*>(pCurrentNode);
  163. const unsigned int keyCount = pCurrentTrack->GetKeyCount();
  164. if (keyCount > 0)
  165. {
  166. // Return key with nearest time to this key
  167. return pCurrentTrack->GetNearestKeyByTime(GetTime());
  168. }
  169. }
  170. }
  171. return CTrackViewKeyHandle();
  172. }
  173. ////////////////////////////////////////////////////////////////////////////
  174. bool CTrackViewKeyHandle::operator==(const CTrackViewKeyHandle& keyHandle) const
  175. {
  176. return m_pTrack == keyHandle.m_pTrack && m_keyIndex == keyHandle.m_keyIndex;
  177. }
  178. ////////////////////////////////////////////////////////////////////////////
  179. bool CTrackViewKeyHandle::operator!=(const CTrackViewKeyHandle& keyHandle) const
  180. {
  181. return !(*this == keyHandle);
  182. }
  183. ////////////////////////////////////////////////////////////////////////////
  184. void CTrackViewKeyBundle::AppendKey(const CTrackViewKeyHandle& keyHandle)
  185. {
  186. // Check if newly added key has different type than existing ones
  187. if (m_bAllOfSameType && m_keys.size() > 0)
  188. {
  189. const CTrackViewKeyHandle& lastKey = m_keys.back();
  190. const CTrackViewTrack* pMyTrack = keyHandle.GetTrack();
  191. const CTrackViewTrack* pOtherTrack = lastKey.GetTrack();
  192. // Check if keys are from sub tracks, always compare types of parent track
  193. if (pMyTrack->IsSubTrack())
  194. {
  195. pMyTrack = static_cast<const CTrackViewTrack*>(pMyTrack->GetParentNode());
  196. }
  197. if (pOtherTrack->IsSubTrack())
  198. {
  199. pOtherTrack = static_cast<const CTrackViewTrack*>(pOtherTrack->GetParentNode());
  200. }
  201. // Do comparison
  202. if (pMyTrack->GetParameterType() != pOtherTrack->GetParameterType()
  203. || pMyTrack->GetCurveType() != pOtherTrack->GetCurveType()
  204. || pMyTrack->GetValueType() != pOtherTrack->GetValueType())
  205. {
  206. m_bAllOfSameType = false;
  207. }
  208. }
  209. m_keys.push_back(keyHandle);
  210. }
  211. ////////////////////////////////////////////////////////////////////////////
  212. void CTrackViewKeyBundle::AppendKeyBundle(const CTrackViewKeyBundle& bundle)
  213. {
  214. for (auto iter = bundle.m_keys.begin(); iter != bundle.m_keys.end(); ++iter)
  215. {
  216. AppendKey(*iter);
  217. }
  218. }
  219. ////////////////////////////////////////////////////////////////////////////
  220. void CTrackViewKeyBundle::SelectKeys(const bool bSelected)
  221. {
  222. const unsigned int numKeys = GetKeyCount();
  223. for (unsigned int i = 0; i < numKeys; ++i)
  224. {
  225. GetKey(i).Select(bSelected);
  226. }
  227. }
  228. //////////////////////////////////////////////////////////////////////////
  229. CTrackViewKeyHandle CTrackViewKeyBundle::GetSingleSelectedKey()
  230. {
  231. const unsigned int keyCount = GetKeyCount();
  232. if (keyCount == 1)
  233. {
  234. return m_keys[0];
  235. }
  236. else if (keyCount > 1 && keyCount <= 4)
  237. {
  238. // All keys must have same time & same parent track
  239. CTrackViewNode* pFirstParent = m_keys[0].GetTrack()->GetParentNode();
  240. const float firstTime = m_keys[0].GetTime();
  241. // Parent must be a track
  242. if (pFirstParent->GetNodeType() != eTVNT_Track)
  243. {
  244. return CTrackViewKeyHandle();
  245. }
  246. // Check other keys for equality
  247. for (unsigned int i = 0; i < keyCount; ++i)
  248. {
  249. if (m_keys[i].GetTrack()->GetParentNode() != pFirstParent || m_keys[i].GetTime() != firstTime)
  250. {
  251. return CTrackViewKeyHandle();
  252. }
  253. }
  254. return static_cast<CTrackViewTrack*>(pFirstParent)->GetKeyByTime(firstTime);
  255. }
  256. return CTrackViewKeyHandle();
  257. }
  258. //////////////////////////////////////////////////////////////////////////
  259. CTrackViewNode::CTrackViewNode(CTrackViewNode* pParent)
  260. : m_pParentNode(pParent)
  261. , m_bSelected(false)
  262. , m_bHidden(false)
  263. {
  264. }
  265. //////////////////////////////////////////////////////////////////////////
  266. bool CTrackViewNode::HasObsoleteTrack() const
  267. {
  268. return HasObsoleteTrackRec(this);
  269. }
  270. //////////////////////////////////////////////////////////////////////////
  271. bool CTrackViewNode::HasObsoleteTrackRec(const CTrackViewNode* pCurrentNode) const
  272. {
  273. if (pCurrentNode->GetNodeType() == eTVNT_Track)
  274. {
  275. const CTrackViewTrack* pTrack = static_cast<const CTrackViewTrack*>(pCurrentNode);
  276. EAnimCurveType trackType = pTrack->GetCurveType();
  277. if (trackType == eAnimCurveType_TCBFloat || trackType == eAnimCurveType_TCBQuat || trackType == eAnimCurveType_TCBVector)
  278. {
  279. return true;
  280. }
  281. }
  282. for (unsigned int i = 0; i < pCurrentNode->GetChildCount(); ++i)
  283. {
  284. CTrackViewNode* pNode = pCurrentNode->GetChild(i);
  285. if (HasObsoleteTrackRec(pNode))
  286. {
  287. return true;
  288. }
  289. }
  290. return false;
  291. }
  292. //////////////////////////////////////////////////////////////////////////
  293. void CTrackViewNode::ClearSelection()
  294. {
  295. CTrackViewSequenceNotificationContext context(GetSequence());
  296. SetSelected(false);
  297. const unsigned int numChilds = GetChildCount();
  298. for (unsigned int childIndex = 0; childIndex < numChilds; ++childIndex)
  299. {
  300. GetChild(childIndex)->ClearSelection();
  301. }
  302. }
  303. //////////////////////////////////////////////////////////////////////////
  304. CTrackViewNode* CTrackViewNode::GetAboveNode() const
  305. {
  306. CTrackViewNode* pParent = GetParentNode();
  307. if (!pParent)
  308. {
  309. // The root does not have an above node
  310. return nullptr;
  311. }
  312. CTrackViewNode* pPrevSibling = GetPrevSibling();
  313. if (!pPrevSibling)
  314. {
  315. // First sibling -> parent is above node
  316. return pParent;
  317. }
  318. // Find last node in sibling tree
  319. CTrackViewNode* pCurrentNode = pPrevSibling;
  320. while (pCurrentNode && pCurrentNode->GetChildCount() > 0 && pCurrentNode->GetExpanded())
  321. {
  322. pCurrentNode = pCurrentNode->GetChild(pCurrentNode->GetChildCount() - 1);
  323. }
  324. return pCurrentNode;
  325. }
  326. //////////////////////////////////////////////////////////////////////////
  327. CTrackViewNode* CTrackViewNode::GetBelowNode() const
  328. {
  329. const unsigned int childCount = GetChildCount();
  330. if (childCount > 0 && GetExpanded())
  331. {
  332. return GetChild(0);
  333. }
  334. CTrackViewNode* pParent = GetParentNode();
  335. if (!pParent)
  336. {
  337. // Root without children
  338. return nullptr;
  339. }
  340. // If there is a next sibling return it
  341. CTrackViewNode* pNextSibling = GetNextSibling();
  342. if (pNextSibling)
  343. {
  344. return pNextSibling;
  345. }
  346. // Otherwise we need to go up the tree and check
  347. // the parent nodes for next siblings
  348. CTrackViewNode* pCurrentNode = pParent;
  349. while (pCurrentNode)
  350. {
  351. CTrackViewNode* pNextParentSibling = pCurrentNode->GetNextSibling();
  352. if (pNextParentSibling)
  353. {
  354. return pNextParentSibling;
  355. }
  356. pCurrentNode = pCurrentNode->GetParentNode();
  357. }
  358. return nullptr;
  359. }
  360. //////////////////////////////////////////////////////////////////////////
  361. CTrackViewNode* CTrackViewNode::GetPrevSibling() const
  362. {
  363. CTrackViewNode* pParent = GetParentNode();
  364. if (!pParent)
  365. {
  366. // The root does not have siblings
  367. return nullptr;
  368. }
  369. // Search for prev sibling
  370. unsigned int siblingCount = pParent->GetChildCount();
  371. assert(siblingCount > 0);
  372. for (unsigned int i = 1; i < siblingCount; ++i)
  373. {
  374. CTrackViewNode* pSibling = pParent->GetChild(i);
  375. if (pSibling == this)
  376. {
  377. return pParent->GetChild(i - 1);
  378. }
  379. }
  380. return nullptr;
  381. }
  382. //////////////////////////////////////////////////////////////////////////
  383. CTrackViewNode* CTrackViewNode::GetNextSibling() const
  384. {
  385. CTrackViewNode* pParent = GetParentNode();
  386. if (!pParent)
  387. {
  388. // The root does not have siblings
  389. return nullptr;
  390. }
  391. // Search for next sibling
  392. unsigned int siblingCount = pParent->GetChildCount();
  393. assert(siblingCount > 0);
  394. for (unsigned int i = 0; i < siblingCount - 1; ++i)
  395. {
  396. CTrackViewNode* pSibling = pParent->GetChild(i);
  397. if (pSibling == this)
  398. {
  399. return pParent->GetChild(i + 1);
  400. }
  401. }
  402. return nullptr;
  403. }
  404. //////////////////////////////////////////////////////////////////////////
  405. void CTrackViewNode::SetSelected(bool bSelected)
  406. {
  407. if (bSelected != m_bSelected)
  408. {
  409. m_bSelected = bSelected;
  410. if (m_bSelected)
  411. {
  412. GetSequence()->OnNodeChanged(this, ITrackViewSequenceListener::eNodeChangeType_Selected);
  413. }
  414. else
  415. {
  416. GetSequence()->OnNodeChanged(this, ITrackViewSequenceListener::eNodeChangeType_Deselected);
  417. }
  418. GetSequence()->OnNodeSelectionChanged();
  419. }
  420. }
  421. //////////////////////////////////////////////////////////////////////////
  422. CTrackViewSequence* CTrackViewNode::GetSequence()
  423. {
  424. for (CTrackViewNode* pCurrentNode = this; pCurrentNode; pCurrentNode = pCurrentNode->GetParentNode())
  425. {
  426. if (pCurrentNode->GetNodeType() == eTVNT_Sequence)
  427. {
  428. return static_cast<CTrackViewSequence*>(pCurrentNode);
  429. }
  430. }
  431. // Every node belongs to a sequence
  432. assert(false);
  433. return nullptr;
  434. }
  435. //////////////////////////////////////////////////////////////////////////
  436. const CTrackViewSequence* CTrackViewNode::GetSequenceConst() const
  437. {
  438. for (const CTrackViewNode* pCurrentNode = this; pCurrentNode; pCurrentNode = pCurrentNode->GetParentNode())
  439. {
  440. if (pCurrentNode->GetNodeType() == eTVNT_Sequence)
  441. {
  442. return static_cast<const CTrackViewSequence*>(pCurrentNode);
  443. }
  444. }
  445. AZ_Assert(false, "Every node belongs to a sequence");
  446. return nullptr;
  447. }
  448. //////////////////////////////////////////////////////////////////////////
  449. void CTrackViewNode::AddNode(CTrackViewNode* pNode)
  450. {
  451. assert (pNode->GetNodeType() != eTVNT_Sequence);
  452. m_childNodes.push_back(std::unique_ptr<CTrackViewNode>(pNode));
  453. SortNodes();
  454. pNode->m_pParentNode = this;
  455. GetSequence()->OnNodeChanged(pNode, ITrackViewSequenceListener::eNodeChangeType_Added);
  456. }
  457. //////////////////////////////////////////////////////////////////////////
  458. void CTrackViewNode::SortNodes()
  459. {
  460. // Sort with operator<
  461. AZStd::stable_sort(m_childNodes.begin(), m_childNodes.end(),
  462. [&](const std::unique_ptr<CTrackViewNode>& a, const std::unique_ptr<CTrackViewNode>& b) -> bool
  463. {
  464. const CTrackViewNode* pA = a.get();
  465. const CTrackViewNode* pB = b.get();
  466. return *pA < *pB;
  467. }
  468. );
  469. }
  470. namespace
  471. {
  472. static int GetNodeOrder(AnimNodeType nodeType)
  473. {
  474. AZ_Assert(nodeType < AnimNodeType::Num, "Expected nodeType to be less than AnimNodeType::Num");
  475. // note: this array gets over-allocated and is sparsely populated because the eAnimNodeType enums are not sequential in IMovieSystem.h
  476. // I wonder if the original authors intended this? Not a big deal, just some trivial memory wastage.
  477. static int nodeOrder[static_cast<int>(AnimNodeType::Num)];
  478. nodeOrder[static_cast<int>(AnimNodeType::Invalid)] = 0;
  479. nodeOrder[static_cast<int>(AnimNodeType::Director)] = 1;
  480. nodeOrder[static_cast<int>(AnimNodeType::Alembic)] = 4;
  481. nodeOrder[static_cast<int>(AnimNodeType::CVar)] = 6;
  482. nodeOrder[static_cast<int>(AnimNodeType::ScriptVar)] = 7;
  483. nodeOrder[static_cast<int>(AnimNodeType::Event)] = 9;
  484. nodeOrder[static_cast<int>(AnimNodeType::Layer)] = 10;
  485. nodeOrder[static_cast<int>(AnimNodeType::Comment)] = 11;
  486. nodeOrder[static_cast<int>(AnimNodeType::RadialBlur)] = 12;
  487. nodeOrder[static_cast<int>(AnimNodeType::ColorCorrection)] = 13;
  488. nodeOrder[static_cast<int>(AnimNodeType::DepthOfField)] = 14;
  489. nodeOrder[static_cast<int>(AnimNodeType::ScreenFader)] = 15;
  490. nodeOrder[static_cast<int>(AnimNodeType::Light)] = 16;
  491. nodeOrder[static_cast<int>(AnimNodeType::ShadowSetup)] = 17;
  492. nodeOrder[static_cast<int>(AnimNodeType::Group)] = 18;
  493. return nodeOrder[static_cast<int>(nodeType)];
  494. }
  495. }
  496. bool CTrackViewNode::operator<(const CTrackViewNode& otherNode) const
  497. {
  498. // Order nodes before tracks
  499. if (GetNodeType() < otherNode.GetNodeType())
  500. {
  501. return true;
  502. }
  503. else if (GetNodeType() > otherNode.GetNodeType())
  504. {
  505. return false;
  506. }
  507. // Same node type
  508. switch (GetNodeType())
  509. {
  510. case eTVNT_AnimNode:
  511. {
  512. const CTrackViewAnimNode& thisAnimNode = static_cast<const CTrackViewAnimNode&>(*this);
  513. const CTrackViewAnimNode& otherAnimNode = static_cast<const CTrackViewAnimNode&>(otherNode);
  514. const int thisTypeOrder = GetNodeOrder(thisAnimNode.GetType());
  515. const int otherTypeOrder = GetNodeOrder(otherAnimNode.GetType());
  516. if (thisTypeOrder == otherTypeOrder)
  517. {
  518. // Same node type, sort by name
  519. return thisAnimNode.GetName() < otherAnimNode.GetName();
  520. }
  521. return thisTypeOrder < otherTypeOrder;
  522. }
  523. case eTVNT_Track:
  524. const CTrackViewTrack& thisTrack = static_cast<const CTrackViewTrack&>(*this);
  525. const CTrackViewTrack& otherTrack = static_cast<const CTrackViewTrack&>(otherNode);
  526. if (thisTrack.GetParameterType() == otherTrack.GetParameterType())
  527. {
  528. // Same parameter type, sort by name
  529. return thisTrack.GetName() < otherTrack.GetName();
  530. }
  531. return thisTrack.GetParameterType() < otherTrack.GetParameterType();
  532. }
  533. return false;
  534. }
  535. //////////////////////////////////////////////////////////////////////////
  536. void CTrackViewNode::SetHidden(bool bHidden)
  537. {
  538. bool bWasHidden = m_bHidden;
  539. m_bHidden = bHidden;
  540. if (bHidden && !bWasHidden)
  541. {
  542. GetSequence()->OnNodeChanged(this, ITrackViewSequenceListener::eNodeChangeType_Hidden);
  543. }
  544. else if (!bHidden && bWasHidden)
  545. {
  546. GetSequence()->OnNodeChanged(this, ITrackViewSequenceListener::eNodeChangeType_Unhidden);
  547. }
  548. }
  549. //////////////////////////////////////////////////////////////////////////
  550. bool CTrackViewNode::IsHidden() const
  551. {
  552. return m_bHidden;
  553. }
  554. //////////////////////////////////////////////////////////////////////////
  555. CTrackViewNode* CTrackViewNode::GetFirstSelectedNode()
  556. {
  557. if (IsSelected())
  558. {
  559. return this;
  560. }
  561. const unsigned int numChilds = GetChildCount();
  562. for (unsigned int childIndex = 0; childIndex < numChilds; ++childIndex)
  563. {
  564. CTrackViewNode* pSelectedNode = GetChild(childIndex)->GetFirstSelectedNode();
  565. if (pSelectedNode)
  566. {
  567. return pSelectedNode;
  568. }
  569. }
  570. return nullptr;
  571. }
  572. //////////////////////////////////////////////////////////////////////////
  573. CTrackViewAnimNode* CTrackViewNode::GetDirector()
  574. {
  575. for (CTrackViewNode* pCurrentNode = GetParentNode(); pCurrentNode; pCurrentNode = pCurrentNode->GetParentNode())
  576. {
  577. if (pCurrentNode->GetNodeType() == eTVNT_AnimNode)
  578. {
  579. CTrackViewAnimNode* pParentAnimNode = static_cast<CTrackViewAnimNode*>(pCurrentNode);
  580. if (pParentAnimNode->GetType() == AnimNodeType::Director)
  581. {
  582. return pParentAnimNode;
  583. }
  584. }
  585. else if (pCurrentNode->GetNodeType() == eTVNT_Sequence)
  586. {
  587. return static_cast<CTrackViewAnimNode*>(pCurrentNode);
  588. }
  589. }
  590. return nullptr;
  591. }