UiAnimViewKeyPropertiesDlg.h 5.5 KB

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