UiAnimViewTrack.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #include "UiAnimViewNode.h"
  11. class CUiAnimViewAnimNode;
  12. // Represents a bundle of tracks
  13. class CUiAnimViewTrackBundle
  14. {
  15. public:
  16. CUiAnimViewTrackBundle()
  17. : m_bAllOfSameType(true)
  18. , m_bHasRotationTrack(false) {}
  19. unsigned int GetCount() const { return static_cast<unsigned int>(m_tracks.size()); }
  20. CUiAnimViewTrack* GetTrack(const unsigned int index) { return m_tracks[index]; }
  21. const CUiAnimViewTrack* GetTrack(const unsigned int index) const { return m_tracks[index]; }
  22. void AppendTrack(CUiAnimViewTrack* pTrack);
  23. void AppendTrackBundle(const CUiAnimViewTrackBundle& bundle);
  24. bool IsOneTrack() const;
  25. bool AreAllOfSameType() const { return m_bAllOfSameType; }
  26. bool HasRotationTrack() const { return m_bHasRotationTrack; }
  27. private:
  28. bool m_bAllOfSameType;
  29. bool m_bHasRotationTrack;
  30. std::vector<CUiAnimViewTrack*> m_tracks;
  31. };
  32. // Track Memento for Undo/Redo
  33. class CUiAnimViewTrackMemento
  34. {
  35. private:
  36. friend class CUiAnimViewTrack;
  37. XmlNodeRef m_serializedTrackState;
  38. };
  39. ////////////////////////////////////////////////////////////////////////////
  40. //
  41. // This class represents a IUiAnimTrack in UiAnimView and contains
  42. // the editor side code for changing it
  43. //
  44. // It does *not* have ownership of the IUiAnimTrack, therefore deleting it
  45. // will not destroy the UI Animation system track
  46. //
  47. ////////////////////////////////////////////////////////////////////////////
  48. class CUiAnimViewTrack
  49. : public CUiAnimViewNode
  50. , public IUiAnimViewKeyBundle
  51. {
  52. friend class CUiAnimViewKeyHandle;
  53. friend class CUiAnimViewKeyConstHandle;
  54. friend class CUiAnimViewKeyBundle;
  55. friend class CAbstractUndoTrackTransaction;
  56. public:
  57. CUiAnimViewTrack(IUiAnimTrack* pTrack, CUiAnimViewAnimNode* pTrackAnimNode, CUiAnimViewNode* pParentNode,
  58. bool bIsSubTrack = false, unsigned int subTrackIndex = 0);
  59. CUiAnimViewAnimNode* GetAnimNode() const;
  60. // Name getter
  61. AZStd::string GetName() const override;
  62. // CUiAnimViewNode
  63. virtual EUiAnimViewNodeType GetNodeType() const override { return eUiAVNT_Track; }
  64. // Check for compound/sub track
  65. bool IsCompoundTrack() const { return m_bIsCompoundTrack; }
  66. // Sub track index
  67. bool IsSubTrack() const { return m_bIsSubTrack; }
  68. unsigned int GetSubTrackIndex() const { return m_subTrackIndex; }
  69. // Snap time value to prev/next key in track
  70. virtual bool SnapTimeToPrevKey(float& time) const override;
  71. virtual bool SnapTimeToNextKey(float& time) const override;
  72. // Key getters
  73. virtual unsigned int GetKeyCount() const override { return m_pAnimTrack->GetNumKeys(); }
  74. virtual CUiAnimViewKeyHandle GetKey(unsigned int index) override;
  75. virtual CUiAnimViewKeyConstHandle GetKey(unsigned int index) const;
  76. virtual CUiAnimViewKeyHandle GetKeyByTime(const float time);
  77. virtual CUiAnimViewKeyHandle GetNearestKeyByTime(const float time);
  78. virtual CUiAnimViewKeyBundle GetSelectedKeys() override;
  79. virtual CUiAnimViewKeyBundle GetAllKeys() override;
  80. virtual CUiAnimViewKeyBundle GetKeysInTimeRange(const float t0, const float t1) override;
  81. // Key modifications
  82. virtual CUiAnimViewKeyHandle CreateKey(const float time);
  83. virtual void SlideKeys(const float time0, const float timeOffset);
  84. void OffsetKeyPosition(const AZ::Vector3& offset);
  85. // Value getters
  86. template <class Type>
  87. void GetValue(const float time, Type& value) const
  88. {
  89. assert (m_pAnimTrack);
  90. return m_pAnimTrack->GetValue(time, value);
  91. }
  92. void GetKeyValueRange(float& min, float& max) const;
  93. // Type getters
  94. CUiAnimParamType GetParameterType() const { return m_pAnimTrack->GetParameterType(); }
  95. EUiAnimValue GetValueType() const { return m_pAnimTrack->GetValueType(); }
  96. EUiAnimCurveType GetCurveType() const { return m_pAnimTrack->GetCurveType(); }
  97. const UiAnimParamData& GetParamData() const { return m_pAnimTrack->GetParamData(); }
  98. // Mask
  99. bool IsMasked(uint32 mask) const { return m_pAnimTrack->IsMasked(mask); }
  100. // Flag getter
  101. IUiAnimTrack::EUiAnimTrackFlags GetFlags() const;
  102. // Spline getter
  103. ISplineInterpolator* GetSpline() const { return m_pAnimTrack->GetSpline(); }
  104. // Color
  105. ColorB GetCustomColor() const;
  106. void SetCustomColor(ColorB color);
  107. bool HasCustomColor() const;
  108. void ClearCustomColor();
  109. // Memento
  110. virtual CUiAnimViewTrackMemento GetMemento() const;
  111. virtual void RestoreFromMemento(const CUiAnimViewTrackMemento& memento);
  112. // Disabled state
  113. virtual void SetDisabled(bool bDisabled) override;
  114. virtual bool IsDisabled() const override;
  115. // Muted state
  116. void SetMuted(bool bMuted);
  117. bool IsMuted() const;
  118. // Key selection
  119. virtual void SelectKeys(const bool bSelected) override;
  120. // Paste from XML representation with time offset
  121. void PasteKeys(XmlNodeRef xmlNode, const float timeOffset);
  122. // Key types
  123. virtual bool AreAllKeysOfSameType() const override { return true; }
  124. // Animation layer index
  125. void SetAnimationLayerIndex(const int index);
  126. int GetAnimationLayerIndex() const;
  127. private:
  128. CUiAnimViewKeyHandle GetPrevKey(const float time);
  129. CUiAnimViewKeyHandle GetNextKey(const float time);
  130. // Those are called from CUiAnimViewKeyHandle
  131. void SetKey(unsigned int keyIndex, IKey* pKey);
  132. void GetKey(unsigned int keyIndex, IKey* pKey) const;
  133. void SelectKey(unsigned int keyIndex, bool bSelect);
  134. bool IsKeySelected(unsigned int keyIndex) const;
  135. void SetKeyTime(const int index, const float time);
  136. float GetKeyTime(const int index) const;
  137. void RemoveKey(const int index);
  138. int CloneKey(const int index);
  139. CUiAnimViewKeyBundle GetKeys(bool bOnlySelected, float t0, float t1);
  140. CUiAnimViewKeyHandle GetSubTrackKeyHandle(unsigned int index) const;
  141. // Copy selected keys to XML representation for clipboard
  142. virtual void CopyKeysToClipboard(XmlNodeRef& xmlNode, const bool bOnlySelectedKeys, const bool bOnlyFromSelectedTracks) override;
  143. bool m_bIsCompoundTrack;
  144. bool m_bIsSubTrack;
  145. unsigned int m_subTrackIndex;
  146. AZStd::intrusive_ptr<IUiAnimTrack> m_pAnimTrack;
  147. CUiAnimViewAnimNode* m_pTrackAnimNode;
  148. };