TrackViewKeyPropertiesDlg.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #if !defined(Q_MOC_RUN)
  10. #include "TrackViewDopeSheetBase.h"
  11. #include "TrackViewNode.h"
  12. #include "TrackViewSequence.h"
  13. #include <QDockWidget>
  14. #include <QScopedPointer>
  15. #include "Util/Variable.h"
  16. #endif
  17. #include <AzCore/std/containers/vector.h>
  18. namespace Ui {
  19. class CTrackViewTrackPropsDlg;
  20. class CTrackViewKeyPropertiesDlg;
  21. }
  22. class ReflectedPropertyControl;
  23. class CTrackViewKeyPropertiesDlg;
  24. //////////////////////////////////////////////////////////////////////////
  25. class CTrackViewKeyUIControls
  26. : public QObject
  27. , public _i_reference_target_t
  28. {
  29. Q_OBJECT
  30. public:
  31. CTrackViewKeyUIControls()
  32. {
  33. m_pVarBlock = new CVarBlock;
  34. m_onSetCallback = AZStd::bind(&CTrackViewKeyUIControls::OnInternalVariableChange, this, AZStd::placeholders::_1);
  35. };
  36. void SetKeyPropertiesDlg(CTrackViewKeyPropertiesDlg* pDlg) { m_pKeyPropertiesDlg = pDlg; }
  37. // Return internal variable block.
  38. CVarBlock* GetVarBlock() const { return m_pVarBlock; }
  39. //////////////////////////////////////////////////////////////////////////
  40. // Callbacks that must be implemented in derived class
  41. //////////////////////////////////////////////////////////////////////////
  42. // Returns true if specified animation track type is supported by this UI.
  43. virtual bool SupportTrackType(const CAnimParamType& paramType, EAnimCurveType trackType, AnimValueType valueType) const = 0;
  44. // Called when UI variable changes.
  45. virtual void OnCreateVars() = 0;
  46. // Called when user changes selected keys.
  47. // Return true if control update UI values
  48. virtual bool OnKeySelectionChange(const CTrackViewKeyBundle& keys) = 0;
  49. // Called when UI variable changes.
  50. virtual void OnUIChange(IVariable* pVar, CTrackViewKeyBundle& keys) = 0;
  51. // Get priority of key UI control, so that specializations can have precedence
  52. virtual unsigned int GetPriority() const = 0;
  53. protected:
  54. //////////////////////////////////////////////////////////////////////////
  55. // Helper functions.
  56. //////////////////////////////////////////////////////////////////////////
  57. template <class T>
  58. void SyncValue(CSmartVariable<T>& var, T& value, bool bCopyToUI, IVariable* pSrcVar = nullptr)
  59. {
  60. if (bCopyToUI)
  61. {
  62. var = value;
  63. }
  64. else
  65. {
  66. if (!pSrcVar || pSrcVar == var.GetVar())
  67. {
  68. value = var;
  69. }
  70. }
  71. }
  72. void AddVariable(CVariableBase& varArray, CVariableBase& var, const char* varName, unsigned char dataType = IVariable::DT_SIMPLE)
  73. {
  74. if (varName)
  75. {
  76. var.SetName(varName);
  77. }
  78. var.SetDataType(dataType);
  79. var.AddOnSetCallback(&m_onSetCallback);
  80. varArray.AddVariable(&var);
  81. m_registeredVariables.push_back(&var);
  82. }
  83. //////////////////////////////////////////////////////////////////////////
  84. void AddVariable(CVariableBase& var, const char* varName, unsigned char dataType = IVariable::DT_SIMPLE)
  85. {
  86. if (varName)
  87. {
  88. var.SetName(varName);
  89. }
  90. var.SetDataType(dataType);
  91. var.AddOnSetCallback(&m_onSetCallback);
  92. m_pVarBlock->AddVariable(&var);
  93. m_registeredVariables.push_back(&var);
  94. }
  95. void OnInternalVariableChange(IVariable* pVar);
  96. protected:
  97. _smart_ptr<CVarBlock> m_pVarBlock;
  98. AZStd::vector<_smart_ptr<IVariable> > m_registeredVariables;
  99. CTrackViewKeyPropertiesDlg* m_pKeyPropertiesDlg;
  100. IVariable::OnSetCallback m_onSetCallback;
  101. };
  102. //////////////////////////////////////////////////////////////////////////
  103. class CTrackViewTrackPropsDlg
  104. : public QWidget
  105. {
  106. Q_OBJECT
  107. public:
  108. CTrackViewTrackPropsDlg(QWidget* parent = 0);
  109. ~CTrackViewTrackPropsDlg();
  110. void OnSequenceChanged();
  111. bool OnKeySelectionChange(const CTrackViewKeyBundle& keys);
  112. protected slots:
  113. void OnUpdateTime();
  114. protected:
  115. CTrackViewKeyHandle m_keyHandle;
  116. QScopedPointer<Ui::CTrackViewTrackPropsDlg> ui;
  117. };
  118. //////////////////////////////////////////////////////////////////////////
  119. class TrackViewKeys;
  120. class CTrackViewKeyPropertiesDlg
  121. : public QWidget
  122. , public ITrackViewSequenceListener
  123. {
  124. public:
  125. CTrackViewKeyPropertiesDlg(QWidget* hParentWnd);
  126. void SetKeysCtrl(CTrackViewDopeSheetBase* pKeysCtrl)
  127. {
  128. m_keysCtrl = pKeysCtrl;
  129. if (m_keysCtrl)
  130. {
  131. m_keysCtrl->SetKeyPropertiesDlg(this);
  132. }
  133. }
  134. void OnSequenceChanged(CTrackViewSequence* sequence);
  135. void PopulateVariables();
  136. void PopulateVariables(ReflectedPropertyControl* propCtrl);
  137. // ITrackViewSequenceListener
  138. void OnKeysChanged(CTrackViewSequence* pSequence) override;
  139. void OnKeySelectionChanged(CTrackViewSequence* pSequence) override;
  140. protected:
  141. //////////////////////////////////////////////////////////////////////////
  142. void OnVarChange(IVariable* pVar);
  143. void CreateAllVars();
  144. void AddVars(CTrackViewKeyUIControls* pUI);
  145. void ReloadValues();
  146. protected:
  147. AZStd::vector< _smart_ptr<CTrackViewKeyUIControls> > m_keyControls;
  148. _smart_ptr<CVarBlock> m_pVarBlock;
  149. ReflectedPropertyControl* m_wndProps;
  150. CTrackViewTrackPropsDlg* m_wndTrackProps;
  151. CTrackViewDopeSheetBase* m_keysCtrl;
  152. CTrackViewTrack* m_pLastTrackSelected;
  153. CTrackViewSequence* m_sequence;
  154. };