@@ -142,8 +142,8 @@ void KeyFrameEditorFrame::setKeyFramedValue( KeyFrame* frame ) {
142
142
update ();
143
143
}
144
144
145
- std::set <Scalar> KeyFrameEditorFrame::getKeyFrames () const {
146
- return m_value->getTimeSchedule ();
145
+ std::vector <Scalar> KeyFrameEditorFrame::getKeyFrames () const {
146
+ return m_value->getTimes ();
147
147
}
148
148
149
149
void KeyFrameEditorFrame::onChangeCursor ( Scalar time, bool internal ) {
@@ -166,15 +166,17 @@ void KeyFrameEditorFrame::onUpdateKeyFrames( Scalar currentTime ) {
166
166
m_cursor = currentTime;
167
167
168
168
updateCursorSpin ();
169
- m_ui->m_nbKeyFrame ->setText ( QString::number ( m_value->getTimeSchedule ().size () ) );
169
+ m_ui->m_nbKeyFrame ->setText ( QString::number ( m_value->getTimes ().size () ) );
170
170
171
171
registerKeyFrames ();
172
172
update ();
173
173
}
174
174
175
175
void KeyFrameEditorFrame::onAddKeyFrame () {
176
- auto times = m_value->getTimeSchedule ();
177
- auto it = times.find ( m_cursor );
176
+ auto times = m_value->getTimes ();
177
+ auto it = std::find_if ( times.begin (), times.end (), [this ]( const auto & t ) {
178
+ return Ra::Core::Math::areApproxEqual ( t, m_cursor );
179
+ } );
178
180
if ( it != times.end () ) { return ; }
179
181
180
182
emit keyFrameAdded ( m_cursor );
@@ -183,11 +185,13 @@ void KeyFrameEditorFrame::onAddKeyFrame() {
183
185
}
184
186
185
187
void KeyFrameEditorFrame::onDeleteKeyFrame () {
186
- auto times = m_value->getTimeSchedule ();
187
- auto it = times.find ( m_cursor );
188
+ auto times = m_value->getTimes ();
189
+ auto it = std::find_if ( times.begin (), times.end (), [this ]( const auto & t ) {
190
+ return Ra::Core::Math::areApproxEqual ( t, m_cursor );
191
+ } );
188
192
if ( it == times.end () ) { return ; }
189
193
190
- emit keyFrameDeleted ( m_cursor );
194
+ emit keyFrameDeleted ( std::distance ( times. begin (), it ) );
191
195
192
196
onUpdateKeyFrames ( m_cursor );
193
197
}
@@ -196,21 +200,28 @@ void KeyFrameEditorFrame::onMoveKeyFrame( Scalar time0, Scalar time1 ) {
196
200
if ( Ra::Core::Math::areApproxEqual ( time0, time1 ) ) { return ; }
197
201
m_cursor = time1;
198
202
199
- emit keyFrameMoved ( time0, time1 );
203
+ auto times = m_value->getTimes ();
204
+ auto it = std::find_if ( times.begin (), times.end (), [time0]( const auto & t ) {
205
+ return Ra::Core::Math::areApproxEqual ( t, time0 );
206
+ } );
207
+
208
+ emit keyFrameMoved ( std::distance ( times.begin (), it ), time1 );
200
209
201
210
onUpdateKeyFrames ( m_cursor );
202
211
}
203
212
204
213
void KeyFrameEditorFrame::onMoveKeyFrames ( Scalar time, Scalar offset ) {
205
214
if ( Ra::Core::Math::areApproxEqual ( offset, 0_ra ) ) { return ; }
206
215
207
- auto times = m_value->getTimeSchedule ();
208
- auto it = times.find ( time );
216
+ auto times = m_value->getTimes ();
217
+ auto it = std::find_if ( times.begin (), times.end (), [time ]( const auto & t ) {
218
+ return Ra::Core::Math::areApproxEqual ( t, time );
219
+ } );
209
220
if ( it == times.end () ) { return ; }
210
221
211
222
Scalar left = ( offset > 0 ) ? ( time ) : ( time + offset );
212
223
213
- emit keyFramesMoved ( time , offset );
224
+ emit keyFramesMoved ( std::distance ( times. begin (), it ) , offset );
214
225
215
226
if ( m_cursor >= left )
216
227
{
@@ -227,7 +238,7 @@ void KeyFrameEditorFrame::deleteZone( Scalar time, Scalar time2 ) {
227
238
228
239
Scalar dist = right - left;
229
240
230
- auto times = m_value->getTimeSchedule ();
241
+ auto times = m_value->getTimes ();
231
242
auto it = times.begin ();
232
243
bool first = true ;
233
244
while ( it != times.end () )
@@ -240,7 +251,7 @@ void KeyFrameEditorFrame::deleteZone( Scalar time, Scalar time2 ) {
240
251
{
241
252
if ( first )
242
253
{
243
- emit keyFramesMoved ( keyFrame , -dist );
254
+ emit keyFramesMoved ( std::distance ( times. begin (), it ) , -dist );
244
255
first = false ;
245
256
}
246
257
}
@@ -256,7 +267,7 @@ void KeyFrameEditorFrame::deleteZone( Scalar time, Scalar time2 ) {
256
267
}
257
268
258
269
void KeyFrameEditorFrame::onSetCursorToPreviousKeyFrame () {
259
- auto times = m_value->getTimeSchedule ();
270
+ auto times = m_value->getTimes ();
260
271
auto it = times.rbegin ();
261
272
while ( it != times.rend () && *it >= m_cursor )
262
273
it++;
@@ -265,7 +276,7 @@ void KeyFrameEditorFrame::onSetCursorToPreviousKeyFrame() {
265
276
}
266
277
267
278
void KeyFrameEditorFrame::onSetCursorToNextKeyFrame () {
268
- auto times = m_value->getTimeSchedule ();
279
+ auto times = m_value->getTimes ();
269
280
auto it = times.begin ();
270
281
while ( it != times.end () && *it <= m_cursor )
271
282
it++;
@@ -454,7 +465,7 @@ void KeyFrameEditorFrame::paintEvent( QPaintEvent* ) {
454
465
const int sliderH = m_ui->scrollArea ->horizontalScrollBar ()->value ();
455
466
const int areaWidth = m_ui->scrollArea ->width ();
456
467
457
- const auto times = m_value->getTimeSchedule ();
468
+ const auto times = m_value->getTimes ();
458
469
if ( auto kf = dynamic_cast <KeyFramedValue<bool >*>( m_value ) )
459
470
{
460
471
if ( m_displayCurve[0 ] ) { drawFlat ( m_curveControlPoints[0 ], py, path[0 ] ); }
@@ -628,8 +639,10 @@ void KeyFrameEditorFrame::mousePressEvent( QMouseEvent* event ) {
628
639
// ------------------ RIGHT CLICK -------------------------------------
629
640
else if ( event->button () == Qt::RightButton )
630
641
{
631
- auto times = m_value->getTimeSchedule ();
632
- auto it = times.find ( m_cursor );
642
+ auto times = m_value->getTimes ();
643
+ auto it = std::find_if ( times.begin (), times.end (), [this ]( const auto & t ) {
644
+ return Ra::Core::Math::areApproxEqual ( t, m_cursor );
645
+ } );
633
646
// if already on KeyFrame, move current KeyFrame
634
647
// ------------------- CURSOR ON KEYFRAME -----------------------
635
648
if ( it != times.end () )
@@ -639,8 +652,10 @@ void KeyFrameEditorFrame::mousePressEvent( QMouseEvent* event ) {
639
652
if ( shiftDown )
640
653
{
641
654
// if no KeyFrame under mouse, move KeyFrame to newFrame
642
- if ( times.find ( nearest ) == times.end () &&
643
- ( std::abs ( m_cursor - nearest ) > 1e-5_ra ) )
655
+ auto it2 = std::find_if ( times.begin (), times.end (), [nearest]( const auto & t ) {
656
+ return Ra::Core::Math::areApproxEqual ( t, nearest );
657
+ } );
658
+ if ( it2 == times.end () && ( std::abs ( m_cursor - nearest ) > 1e-5_ra ) )
644
659
{ onMoveKeyFrame ( m_cursor, nearest ); }
645
660
}
646
661
// ---------- MULTIPLE MOVE -----------------------------------
@@ -660,15 +675,15 @@ void KeyFrameEditorFrame::mousePressEvent( QMouseEvent* event ) {
660
675
// --------------- MOVE RIGHT KEYFRAME TO THE LEFT -----------------
661
676
if ( shiftDown )
662
677
{
663
- auto itRight = times.lower_bound ( newFrame );
678
+ auto itRight = std::lower_bound ( times.begin (), times. end (), newFrame );
664
679
// if KeyFrames on the right, remove or insert time
665
680
if ( itRight != times.end () ) { onMoveKeyFrames ( *itRight, newFrame - *itRight ); }
666
681
}
667
682
// if not shiftdown, slide first left KeyFrame to the right
668
683
// ---------------- MOVE LEFT KEYFRAME TO THE RIGHT -----------
669
684
else
670
685
{
671
- auto itLeft = --times.lower_bound ( newFrame );
686
+ auto itLeft = --std::lower_bound ( times.begin (), times. end (), newFrame );
672
687
// if KeyFrames on the left, remove or insert time
673
688
if ( itLeft != times.end () ) { onMoveKeyFrames ( *itLeft, newFrame - *itLeft ); }
674
689
}
@@ -803,7 +818,7 @@ Scalar KeyFrameEditorFrame::nearestStep( Scalar time ) const {
803
818
804
819
Scalar newCursor = time ;
805
820
806
- auto times = m_value->getTimeSchedule ();
821
+ auto times = m_value->getTimes ();
807
822
for ( auto keyFrame : times )
808
823
{
809
824
dist = qAbs ( keyFrame - time );
@@ -888,7 +903,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
888
903
curve.clear ();
889
904
}
890
905
891
- auto times = m_value->getTimeSchedule ();
906
+ auto times = m_value->getTimes ();
892
907
m_ui->m_nbKeyFrame ->setText ( QString::number ( times.size () ) );
893
908
if ( auto kf = dynamic_cast <KeyFramedValue<bool >*>( m_value ) )
894
909
{
@@ -1065,8 +1080,11 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
1065
1080
1066
1081
void KeyFrameEditorFrame::updateCursorSpin () {
1067
1082
if ( m_ui == nullptr ) { return ; }
1068
- auto times = m_value->getTimeSchedule ();
1069
- if ( times.find ( m_cursor ) != times.end () )
1083
+ auto times = m_value->getTimes ();
1084
+ auto it = std::find_if ( times.begin (), times.end (), [this ]( const auto & t ) {
1085
+ return Ra::Core::Math::areApproxEqual ( t, m_cursor );
1086
+ } );
1087
+ if ( it != times.end () )
1070
1088
{
1071
1089
m_ui->m_currentTime_dsb ->setStyleSheet ( " background-color: yellow" );
1072
1090
m_ui->m_deleteKeyframe ->setEnabled ( true );
0 commit comments