Sequencer - Moving points (overrides support)

This commit is contained in:
Emmanuel BENOîT 2017-11-29 12:44:36 +01:00
parent 0106529e96
commit 78d15dd350

View file

@ -322,8 +322,8 @@ struct T_SyncViewImpl_
// Original and copy of curve being modified // Original and copy of curve being modified
E_ChangeType selUpdate{ E_ChangeType::NONE }; E_ChangeType selUpdate{ E_ChangeType::NONE };
T_Optional< T_SyncCurve > selUpdatingOriginal; T_AutoArray< T_SyncCurve , 16 > selUpdatingOriginals;
T_Optional< T_SyncCurve > selUpdatingCopy; T_AutoArray< T_SyncCurve , 16 > selUpdatingCopies;
// Sub-windows // Sub-windows
E_SubWindow sub{ SW_NONE }; E_SubWindow sub{ SW_NONE };
@ -505,8 +505,8 @@ void T_SyncViewImpl_::checkSelection( ) noexcept
// If we were doing something with the curve, get rid of that too // If we were doing something with the curve, get rid of that too
if ( selUpdate != E_ChangeType::NONE ) { if ( selUpdate != E_ChangeType::NONE ) {
selUpdate = E_ChangeType::NONE; selUpdate = E_ChangeType::NONE;
selUpdatingCopy.clear( ); selUpdatingCopies.clear( );
selUpdatingOriginal.clear( ); selUpdatingOriginals.clear( );
} }
} }
@ -743,15 +743,19 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
selSegment = dSeg.seg; selSegment = dSeg.seg;
selPoint = dPoint.index; selPoint = dPoint.index;
selPointDnD = io.MouseDown[ 0 ] && dPoint.index != 0; selPointDnD = io.MouseDown[ 0 ] && dPoint.index != 0;
if ( selPointDnD && !selId->isOverride ) { // XXX if ( selPointDnD ) {
assert( selUpdate == E_ChangeType::NONE ); assert( selUpdate == E_ChangeType::NONE );
selPointDnDStart = selPointDnDCur = mPixels; selPointDnDStart = selPointDnDCur = mPixels;
selUpdatingOriginal = *sync.getCurve( selId->id ); if ( selId->isOverride ) {
auto const& names{ sync.getOverride( selId->id )->inputNames( ) };
const auto ni{ names.size( ) };
for ( auto i = 0u ; i < ni ; i ++ ) {
selUpdatingOriginals.add( *sync.getCurve( names[ i ] ) );
}
} else {
selUpdatingOriginals.add( *sync.getCurve( selId->id ) );
}
selUpdate = E_ChangeType::POINT_DND; selUpdate = E_ChangeType::POINT_DND;
} else if ( selId->isOverride ) {
printf( "FIXME!\n" );
selPointDnD = false;
#warning blah
} }
sub = E_SubWindow::SW_POINT; sub = E_SubWindow::SW_POINT;
} }
@ -979,13 +983,13 @@ void T_SyncViewImpl_::sequencerTrack(
// If there's a curve, go through all segments // If there's a curve, go through all segments
const auto units{ Common::Sync( ).durationUnits( ) }; const auto units{ Common::Sync( ).durationUnits( ) };
const bool useCopy{ sCurve && curve && selUpdatingCopy }; const bool useCopy{ sCurve && curve && !selUpdatingCopies.empty( ) };
const auto nSeg{ curve const auto nSeg{ curve
? ( useCopy ? *selUpdatingCopy : *curve ).segments.size( ) ? ( useCopy ? selUpdatingCopies[ 0 ] : *curve ).segments.size( )
: 0u }; : 0u };
uint32_t segStart{ 0 }; uint32_t segStart{ 0 };
for ( auto i = 0u ; i < nSeg ; i ++ ) { for ( auto i = 0u ; i < nSeg ; i ++ ) {
auto const& seg{ ( useCopy ? *selUpdatingCopy : *curve ).segments[ i ] }; auto const& seg{ ( useCopy ? selUpdatingCopies[ 0 ] : *curve ).segments[ i ] };
const auto segDur{ [&](){ const auto segDur{ [&](){
auto t{ 0u }; auto t{ 0u };
for ( auto d : seg.durations ) { for ( auto d : seg.durations ) {
@ -1199,31 +1203,38 @@ bool T_SyncViewImpl_::handlePointDrag(
const float diff{ selPointDnDCur - selPointDnDStart }; const float diff{ selPointDnDCur - selPointDnDStart };
const int32_t diffUnits{ int32_t( round( diff * sync.durationUnits( ) / totalPixels ) ) }; const int32_t diffUnits{ int32_t( round( diff * sync.durationUnits( ) / totalPixels ) ) };
const bool moved{ fabsf( diff ) >= 2 && abs( diffUnits ) > 0 }; const bool moved{ fabsf( diff ) >= 2 && abs( diffUnits ) > 0 };
const auto ni{ selUpdatingCopies.size( ) };
// Update the point as necessary // Update the point as necessary
if ( moved ) { if ( moved ) {
selUpdatingCopy = selUpdatingOriginal; // XXX selUpdatingCopies = selUpdatingOriginals;
auto& seg{ selUpdatingCopy->segments[ *selSegment ] }; for ( auto i = 0u ; i < ni ; i ++ ) {
if ( *selPoint == seg.durations.size( ) ) { auto& copy{ selUpdatingCopies[ i ] };
// We're dragging the end point auto& seg{ copy.segments[ *selSegment ] };
// XXX make it work "normally" if ( *selPoint == seg.durations.size( ) ) {
seg.durations.last( ) = std::max( 1 , // We're dragging the end point
diffUnits + int32_t( seg.durations.last( ) ) ); // XXX make it work "normally"
} else { seg.durations.last( ) = std::max( 1 ,
// We're dragging some other point, move units diffUnits + int32_t( seg.durations.last( ) ) );
// from one side to the other } else {
assert( *selPoint > 0 ); // We're dragging some other point, move units
auto& d0{ seg.durations[ *selPoint - 1 ] }; // from one side to the other
auto& d1{ seg.durations[ *selPoint ] }; assert( *selPoint > 0 );
const int32_t mmNeg( 1 - d0 ) , mmPos( d1 - 1 ); auto& d0{ seg.durations[ *selPoint - 1 ] };
const int32_t diff{ diffUnits < mmNeg ? mmNeg auto& d1{ seg.durations[ *selPoint ] };
: ( diffUnits > mmPos ? mmPos : diffUnits ) }; const int32_t mmNeg( 1 - d0 ) , mmPos( d1 - 1 );
d0 += diff; const int32_t diff{ diffUnits < mmNeg ? mmNeg
d1 -= diff; : ( diffUnits > mmPos ? mmPos : diffUnits ) };
d0 += diff;
d1 -= diff;
}
sync.setCurve( copy );
} }
sync.setCurve( *selUpdatingCopy );
} else { } else {
selUpdatingCopy.clear( ); selUpdatingCopies.clear( );
for ( auto i = 0u ; i < ni ; i ++ ) {
sync.setCurve( selUpdatingOriginals[ i ] );
}
} }
if ( mouseDown ) { if ( mouseDown ) {
@ -1233,12 +1244,20 @@ bool T_SyncViewImpl_::handlePointDrag(
assert( selUpdate == E_ChangeType::POINT_DND ); assert( selUpdate == E_ChangeType::POINT_DND );
selUpdate = E_ChangeType::NONE; selUpdate = E_ChangeType::NONE;
selPointDnD = false; selPointDnD = false;
sync.setCurve( std::move( *selUpdatingOriginal ) );
selUpdatingOriginal.clear( );
if ( moved ) { if ( moved ) {
SyncEditor::ReplaceCurve( std::move( *selUpdatingCopy ) ); auto& undo{ dynamic_cast< T_UndoSyncChanges& >(
selUpdatingCopy.clear( ); Common::Undo( ).add< T_UndoSyncChanges >( ) ) };
for ( auto i = 0u ; i < ni ; i ++ ) {
undo.curveReplacement( std::move( selUpdatingOriginals[ i ] ) ,
std::move( selUpdatingCopies[ i ] ) );
}
} else {
for ( auto i = 0u ; i < ni ; i ++ ) {
sync.setCurve( std::move( selUpdatingOriginals[ i ] ) );
}
} }
selUpdatingOriginals.clear( );
selUpdatingCopies.clear( );
return false; return false;
} }
@ -1851,8 +1870,8 @@ void T_SyncViewImpl_::displayPointWindow( ) noexcept
auto const* const ovr{ selId->isOverride auto const* const ovr{ selId->isOverride
? sync.getOverride( selId->id ) ? sync.getOverride( selId->id )
: nullptr }; : nullptr };
auto const* const curve{ selUpdatingCopy auto const* const curve{ selUpdatingCopies.size( )
? selUpdatingCopy.target( ) ? &selUpdatingCopies[ 0 ]
: sync.getCurve( ovr ? ovr->inputNames( )[ 0 ] : selId->id ) }; : sync.getCurve( ovr ? ovr->inputNames( )[ 0 ] : selId->id ) };
auto const& segment{ curve->segments[ sid ] }; auto const& segment{ curve->segments[ sid ] };
@ -1959,19 +1978,20 @@ void T_SyncViewImpl_::displayPointWindow( ) noexcept
if ( changed ) { if ( changed ) {
if ( selUpdate == E_ChangeType::NONE ) { if ( selUpdate == E_ChangeType::NONE ) {
selUpdatingOriginal = *curve; selUpdatingOriginals.add( *curve );
selUpdatingCopy = *curve; selUpdatingCopies.add( *curve );
selUpdate = E_ChangeType::POINT_VALUE; selUpdate = E_ChangeType::POINT_VALUE;
} else { } else {
assert( selUpdate == E_ChangeType::POINT_VALUE ); assert( selUpdate == E_ChangeType::POINT_VALUE );
} }
selUpdatingCopy->segments[ sid ].values[ pid ] = value; selUpdatingCopies[ 0 ].segments[ sid ].values[ pid ] = value;
sync.setCurve( *selUpdatingCopy ); sync.setCurve( selUpdatingCopies[ 0 ] );
} else if ( selUpdate == E_ChangeType::POINT_VALUE ) { } else if ( selUpdate == E_ChangeType::POINT_VALUE ) {
selUpdate = E_ChangeType::NONE; selUpdate = E_ChangeType::NONE;
sync.setCurve( *selUpdatingOriginal ); sync.setCurve( selUpdatingOriginals[ 0 ] );
SyncEditor::ReplaceCurve( std::move( *selUpdatingCopy ) ); SyncEditor::ReplaceCurve( std::move( selUpdatingCopies[ 0 ] ) );
selUpdatingCopy.clear( ); selUpdatingCopies.clear( );
selUpdatingOriginals.clear( );
} }
End( ); End( );