123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include "EditorDefs.h"
- // Editor
- #include "KeyUIControls.h"
- #include "TrackViewKeyPropertiesDlg.h"
- #include "Controls/ReflectedPropertyControl/ReflectedPropertyItem.h"
- //////////////////////////////////////////////////////////////////////////
- bool C2DBezierKeyUIControls::OnKeySelectionChange(const CTrackViewKeyBundle& selectedKeys)
- {
- if (!selectedKeys.AreAllKeysOfSameType())
- {
- return false;
- }
- bool bAssigned = false;
- if (selectedKeys.GetKeyCount() == 1)
- {
- const CTrackViewKeyHandle& keyHandle = selectedKeys.GetKey(0);
- float fMin = 0.0f;
- float fMax = 0.0f;
- const CTrackViewTrack* pTrack = keyHandle.GetTrack();
- pTrack->GetKeyValueRange(fMin, fMax);
- if (fMin != fMax)
- {
- float curMin, curMax, step;
- bool curMinHardLimit, curMaxHardLimit;
- // need to call GetLimits to retrieve/maintain *HardLimit boolean values
- mv_value.GetVar()->GetLimits(curMin, curMax, step, curMinHardLimit, curMaxHardLimit);
- step = ReflectedPropertyItem::ComputeSliderStep(fMin, fMax);
- mv_value.GetVar()->SetLimits(fMin, fMax, step, curMinHardLimit, curMaxHardLimit);
- }
- else
- {
- mv_value.GetVar()->ClearLimits();
- }
- EAnimCurveType trType = keyHandle.GetTrack()->GetCurveType();
- if (trType == eAnimCurveType_BezierFloat)
- {
- I2DBezierKey bezierKey;
- keyHandle.GetKey(&bezierKey);
- m_skipOnUIChange = true;
- SyncValue(mv_value, bezierKey.value.y, true);
- m_skipOnUIChange = false;
- bAssigned = true;
- }
- }
- return bAssigned;
- }
- // Called when UI variable changes.
- void C2DBezierKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
- {
- CTrackViewSequence* sequence = GetIEditor()->GetAnimation()->GetSequence();
- if (!sequence || !selectedKeys.AreAllKeysOfSameType() || m_skipOnUIChange)
- {
- return;
- }
- for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
- {
- CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
- EAnimCurveType trType = keyHandle.GetTrack()->GetCurveType();
- if (trType == eAnimCurveType_BezierFloat)
- {
- I2DBezierKey bezierKey;
- keyHandle.GetKey(&bezierKey);
- SyncValue(mv_value, bezierKey.value.y, false, pVar);
- bool isDuringUndo = false;
- AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(isDuringUndo, &AzToolsFramework::ToolsApplicationRequests::Bus::Events::IsDuringUndoRedo);
- if (isDuringUndo)
- {
- keyHandle.SetKey(&bezierKey);
- }
- else
- {
- AzToolsFramework::ScopedUndoBatch undoBatch("Set Key Value");
- keyHandle.SetKey(&bezierKey);
- undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
- }
- }
- }
- }
|