CompoundSplineTrack.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #define MAX_SUBTRACKS 4
  10. #include <LyShine/Animation/IUiAnimation.h>
  11. #include <AzCore/std/smart_ptr/intrusive_ptr.h>
  12. #include <AzCore/std/containers/array.h>
  13. //////////////////////////////////////////////////////////////////////////
  14. class UiCompoundSplineTrack
  15. : public IUiAnimTrack
  16. {
  17. public:
  18. AZ_CLASS_ALLOCATOR(UiCompoundSplineTrack, AZ::SystemAllocator)
  19. AZ_RTTI(UiCompoundSplineTrack, "{91947B8B-65B7-451D-9D04-0C821C82014E}", IUiAnimTrack);
  20. UiCompoundSplineTrack(int nDims, EUiAnimValue inValueType, CUiAnimParamType subTrackParamTypes[MAX_SUBTRACKS]);
  21. UiCompoundSplineTrack();
  22. void add_ref() override { ++m_refCount; }
  23. void release() override
  24. {
  25. if (--m_refCount <= 0)
  26. {
  27. delete this;
  28. }
  29. }
  30. int GetSubTrackCount() const override { return m_nDimensions; };
  31. IUiAnimTrack* GetSubTrack(int nIndex) const override;
  32. AZStd::string GetSubTrackName(int nIndex) const override;
  33. void SetSubTrackName(int nIndex, const char* name) override;
  34. EUiAnimCurveType GetCurveType() override { return eUiAnimCurveType_BezierFloat; };
  35. EUiAnimValue GetValueType() override { return m_valueType; };
  36. const CUiAnimParamType& GetParameterType() const override { return m_nParamType; };
  37. void SetParameterType(CUiAnimParamType type) override { m_nParamType = type; }
  38. const UiAnimParamData& GetParamData() const override { return m_componentParamData; }
  39. void SetParamData(const UiAnimParamData& param) override { m_componentParamData = param; }
  40. int GetNumKeys() const override;
  41. void SetNumKeys([[maybe_unused]] int numKeys) override { assert(0); };
  42. bool HasKeys() const override;
  43. void RemoveKey(int num) override;
  44. void GetKeyInfo(int key, const char*& description, float& duration) override;
  45. int CreateKey([[maybe_unused]] float time) override { assert(0); return 0; };
  46. int CloneKey([[maybe_unused]] int fromKey) override { assert(0); return 0; };
  47. int CopyKey([[maybe_unused]] IUiAnimTrack* pFromTrack, [[maybe_unused]] int nFromKey) override { assert(0); return 0; };
  48. void GetKey([[maybe_unused]] int index, [[maybe_unused]] IKey* key) const override { assert(0); };
  49. float GetKeyTime(int index) const override;
  50. int FindKey([[maybe_unused]] float time) override { assert(0); return 0; };
  51. int GetKeyFlags([[maybe_unused]] int index) override { assert(0); return 0; };
  52. void SetKey([[maybe_unused]] int index, [[maybe_unused]] IKey* key) override { assert(0); };
  53. void SetKeyTime(int index, float time) override;
  54. void SetKeyFlags([[maybe_unused]] int index, [[maybe_unused]] int flags) override { assert(0); };
  55. void SortKeys() override { assert(0); };
  56. bool IsKeySelected(int key) const override;
  57. void SelectKey(int key, bool select) override;
  58. int GetFlags() override { return m_flags; };
  59. bool IsMasked([[maybe_unused]] const uint32 mask) const override { return false; }
  60. void SetFlags(int flags) override { m_flags = flags; };
  61. //////////////////////////////////////////////////////////////////////////
  62. // Get track value at specified time.
  63. // Interpolates keys if needed.
  64. //////////////////////////////////////////////////////////////////////////
  65. void GetValue(float time, float& value) override;
  66. void GetValue(float time, Vec3& value) override;
  67. void GetValue(float time, Vec4& value) override;
  68. void GetValue(float time, Quat& value) override;
  69. void GetValue(float time, AZ::Vector2& value) override;
  70. void GetValue(float time, AZ::Vector3& value) override;
  71. void GetValue(float time, AZ::Vector4& value) override;
  72. void GetValue(float time, AZ::Color& value) override;
  73. void GetValue([[maybe_unused]] float time, [[maybe_unused]] bool& value) override { assert(0); };
  74. //////////////////////////////////////////////////////////////////////////
  75. // Set track value at specified time.
  76. // Adds new keys if required.
  77. //////////////////////////////////////////////////////////////////////////
  78. void SetValue(float time, const float& value, bool bDefault = false) override;
  79. void SetValue(float time, const Vec3& value, bool bDefault = false) override;
  80. void SetValue(float time, const Vec4& value, bool bDefault = false) override;
  81. void SetValue(float time, const Quat& value, bool bDefault = false) override;
  82. void SetValue([[maybe_unused]] float time, [[maybe_unused]] const bool& value, [[maybe_unused]] bool bDefault = false) override { assert(0); };
  83. void SetValue(float time, const AZ::Vector2& value, bool bDefault = false) override;
  84. void SetValue(float time, const AZ::Vector3& value, bool bDefault = false) override;
  85. void SetValue(float time, const AZ::Vector4& value, bool bDefault = false) override;
  86. void SetValue(float time, const AZ::Color& value, bool bDefault = false) override;
  87. void OffsetKeyPosition(const Vec3& value) override;
  88. void SetTimeRange(const Range& timeRange) override;
  89. bool Serialize(IUiAnimationSystem* uiAnimationSystem, XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks = true) override;
  90. bool SerializeSelection(XmlNodeRef& xmlNode, bool bLoading, bool bCopySelected = false, float fTimeOffset = 0) override;
  91. int NextKeyByTime(int key) const override;
  92. void SetSubTrackName(const int i, const AZStd::string& name) { assert (i < MAX_SUBTRACKS); m_subTrackNames[i] = name; }
  93. #ifdef UI_ANIMATION_SYSTEM_SUPPORT_EDITING
  94. ColorB GetCustomColor() const override
  95. { return m_customColor; }
  96. void SetCustomColor(ColorB color) override
  97. {
  98. m_customColor = color;
  99. m_bCustomColorSet = true;
  100. }
  101. bool HasCustomColor() const override
  102. { return m_bCustomColorSet; }
  103. void ClearCustomColor() override
  104. { m_bCustomColorSet = false; }
  105. #endif
  106. void GetKeyValueRange(float& fMin, float& fMax) const override
  107. {
  108. if (GetSubTrackCount() > 0)
  109. {
  110. m_subTracks[0]->GetKeyValueRange(fMin, fMax);
  111. }
  112. };
  113. void SetKeyValueRange(float fMin, float fMax) override
  114. {
  115. for (int i = 0; i < m_nDimensions; ++i)
  116. {
  117. m_subTracks[i]->SetKeyValueRange(fMin, fMax);
  118. }
  119. };
  120. static void Reflect(AZ::SerializeContext* serializeContext);
  121. protected:
  122. int m_refCount;
  123. EUiAnimValue m_valueType;
  124. int m_nDimensions;
  125. AZStd::array<AZStd::intrusive_ptr<IUiAnimTrack>, MAX_SUBTRACKS> m_subTracks;
  126. int m_flags;
  127. CUiAnimParamType m_nParamType;
  128. AZStd::array<AZStd::string, MAX_SUBTRACKS> m_subTrackNames;
  129. UiAnimParamData m_componentParamData;
  130. #ifdef UI_ANIMATION_SYSTEM_SUPPORT_EDITING
  131. ColorB m_customColor;
  132. bool m_bCustomColorSet;
  133. #endif
  134. void PrepareNodeForSubTrackSerialization(XmlNodeRef& subTrackNode, XmlNodeRef& xmlNode, int i, bool bLoading);
  135. float PreferShortestRotPath(float degree, float degree0) const;
  136. int GetSubTrackIndex(int& key) const;
  137. };