2DBezierKeyUIControls.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. // Editor
  10. #include "KeyUIControls.h"
  11. #include "TrackViewKeyPropertiesDlg.h"
  12. #include "Controls/ReflectedPropertyControl/ReflectedPropertyItem.h"
  13. //////////////////////////////////////////////////////////////////////////
  14. bool C2DBezierKeyUIControls::OnKeySelectionChange(const CTrackViewKeyBundle& selectedKeys)
  15. {
  16. if (!selectedKeys.AreAllKeysOfSameType())
  17. {
  18. return false;
  19. }
  20. bool bAssigned = false;
  21. if (selectedKeys.GetKeyCount() == 1)
  22. {
  23. const CTrackViewKeyHandle& keyHandle = selectedKeys.GetKey(0);
  24. float fMin = 0.0f;
  25. float fMax = 0.0f;
  26. const CTrackViewTrack* pTrack = keyHandle.GetTrack();
  27. pTrack->GetKeyValueRange(fMin, fMax);
  28. if (fMin != fMax)
  29. {
  30. float curMin, curMax, step;
  31. bool curMinHardLimit, curMaxHardLimit;
  32. // need to call GetLimits to retrieve/maintain *HardLimit boolean values
  33. mv_value.GetVar()->GetLimits(curMin, curMax, step, curMinHardLimit, curMaxHardLimit);
  34. step = ReflectedPropertyItem::ComputeSliderStep(fMin, fMax);
  35. mv_value.GetVar()->SetLimits(fMin, fMax, step, curMinHardLimit, curMaxHardLimit);
  36. }
  37. else
  38. {
  39. mv_value.GetVar()->ClearLimits();
  40. }
  41. EAnimCurveType trType = keyHandle.GetTrack()->GetCurveType();
  42. if (trType == eAnimCurveType_BezierFloat)
  43. {
  44. I2DBezierKey bezierKey;
  45. keyHandle.GetKey(&bezierKey);
  46. m_skipOnUIChange = true;
  47. SyncValue(mv_value, bezierKey.value.y, true);
  48. m_skipOnUIChange = false;
  49. bAssigned = true;
  50. }
  51. }
  52. return bAssigned;
  53. }
  54. // Called when UI variable changes.
  55. void C2DBezierKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  56. {
  57. CTrackViewSequence* sequence = GetIEditor()->GetAnimation()->GetSequence();
  58. if (!sequence || !selectedKeys.AreAllKeysOfSameType() || m_skipOnUIChange)
  59. {
  60. return;
  61. }
  62. for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
  63. {
  64. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  65. EAnimCurveType trType = keyHandle.GetTrack()->GetCurveType();
  66. if (trType == eAnimCurveType_BezierFloat)
  67. {
  68. I2DBezierKey bezierKey;
  69. keyHandle.GetKey(&bezierKey);
  70. SyncValue(mv_value, bezierKey.value.y, false, pVar);
  71. bool isDuringUndo = false;
  72. AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(isDuringUndo, &AzToolsFramework::ToolsApplicationRequests::Bus::Events::IsDuringUndoRedo);
  73. if (isDuringUndo)
  74. {
  75. keyHandle.SetKey(&bezierKey);
  76. }
  77. else
  78. {
  79. AzToolsFramework::ScopedUndoBatch undoBatch("Set Key Value");
  80. keyHandle.SetKey(&bezierKey);
  81. undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
  82. }
  83. }
  84. }
  85. }