Sequencer - Unified drag'n'drop handling
Until now the various types of drag'n'drop were handled separately and could very possibly interfere with each other. This fixes the problem by using a single variable for the current type (if any) of drag'n'drop
This commit is contained in:
parent
eb7bd8bcbe
commit
99f6862138
2 changed files with 35 additions and 19 deletions
1
TODO
1
TODO
|
@ -30,7 +30,6 @@ Sync / inputs:
|
||||||
* Zoom level is mostly useless, fix it
|
* Zoom level is mostly useless, fix it
|
||||||
* Save/restore sets of tracks
|
* Save/restore sets of tracks
|
||||||
* Edition buttons in toolbar
|
* Edition buttons in toolbar
|
||||||
* Fix drag-and-drop
|
|
||||||
* Moving tracks
|
* Moving tracks
|
||||||
* Moving segments
|
* Moving segments
|
||||||
* Add curve display
|
* Add curve display
|
||||||
|
|
|
@ -330,6 +330,16 @@ struct T_SyncViewImpl_
|
||||||
POINT_VALUE ,
|
POINT_VALUE ,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Type of drag-and-drop operation in progress
|
||||||
|
enum class E_DNDType {
|
||||||
|
NONE , // No drag'n'drop
|
||||||
|
CLICK , // Clicked in an area that will not
|
||||||
|
// cause drag'n'drop to happen
|
||||||
|
TIME , // Time being adjusted
|
||||||
|
ZOOM , // Zoom region being selected
|
||||||
|
POINT , // Point being moved
|
||||||
|
};
|
||||||
|
|
||||||
// Make sure all displayed inputs/overrides still exist
|
// Make sure all displayed inputs/overrides still exist
|
||||||
void checkTracks( ) noexcept;
|
void checkTracks( ) noexcept;
|
||||||
// Make sure the currently selected track/segment/point is still valid
|
// Make sure the currently selected track/segment/point is still valid
|
||||||
|
@ -408,6 +418,7 @@ struct T_SyncViewImpl_
|
||||||
|
|
||||||
// Misc stuff
|
// Misc stuff
|
||||||
T_StringBuilder stringBuffer; // XXX damn this shit to fucking hell
|
T_StringBuilder stringBuffer; // XXX damn this shit to fucking hell
|
||||||
|
E_DNDType dnd{ E_DNDType::NONE };
|
||||||
|
|
||||||
// Computed metrics
|
// Computed metrics
|
||||||
bool checkLockMode{ false };
|
bool checkLockMode{ false };
|
||||||
|
@ -426,7 +437,6 @@ struct T_SyncViewImpl_
|
||||||
T_Array< T_TrackPointDisplay > dspPoints;
|
T_Array< T_TrackPointDisplay > dspPoints;
|
||||||
|
|
||||||
// Zoom area selection
|
// Zoom area selection
|
||||||
bool zoomInProgress{ false };
|
|
||||||
float firstZoomPixel;
|
float firstZoomPixel;
|
||||||
float curZoomPixel;
|
float curZoomPixel;
|
||||||
|
|
||||||
|
@ -434,7 +444,6 @@ struct T_SyncViewImpl_
|
||||||
T_Optional< T_SyncTrackId > selId{ };
|
T_Optional< T_SyncTrackId > selId{ };
|
||||||
T_Optional< uint32_t > selSegment;
|
T_Optional< uint32_t > selSegment;
|
||||||
T_Optional< uint32_t > selPoint;
|
T_Optional< uint32_t > selPoint;
|
||||||
bool selPointDnD{ false };
|
|
||||||
float selPointDnDStart , selPointDnDCur;
|
float selPointDnDStart , selPointDnDCur;
|
||||||
|
|
||||||
// Original and copy of curve being modified
|
// Original and copy of curve being modified
|
||||||
|
@ -829,8 +838,11 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( zoomInProgress && !io.MouseDown[ 1 ] ) {
|
if ( dnd == E_DNDType::ZOOM ) {
|
||||||
zoomInProgress = false;
|
if ( io.MouseDown[ 1 ] ) {
|
||||||
|
curZoomPixel = mPixels;
|
||||||
|
return;
|
||||||
|
}
|
||||||
checkLockMode = true;
|
checkLockMode = true;
|
||||||
const auto zMin{ std::min( firstZoomPixel , curZoomPixel ) } ,
|
const auto zMin{ std::min( firstZoomPixel , curZoomPixel ) } ,
|
||||||
zMax{ std::max( firstZoomPixel , curZoomPixel ) } ,
|
zMax{ std::max( firstZoomPixel , curZoomPixel ) } ,
|
||||||
|
@ -846,16 +858,17 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
|
||||||
zoomLevel = ( ppu - BarWidth ) / ( BarWidth - width / u ) + 1;
|
zoomLevel = ( ppu - BarWidth ) / ( BarWidth - width / u ) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( zoomInProgress && io.MouseDown[ 1 ] ) {
|
} else if ( dnd == E_DNDType::POINT && handlePointDrag( mPixels , io.MouseDown[ 0 ] ) ) {
|
||||||
curZoomPixel = mPixels;
|
return;
|
||||||
|
} else if ( dnd == E_DNDType::CLICK && ( io.MouseDown[ 0 ] || io.MouseDown[ 1 ] ) ) {
|
||||||
|
return;
|
||||||
|
} else if ( dnd == E_DNDType::TIME && io.MouseDown[ 0 ] ) {
|
||||||
|
sync.setTime( mTime );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( selPointDnD && handlePointDrag( mPixels , io.MouseDown[ 0 ] ) ) {
|
if ( dnd != E_DNDType::NONE && !( io.MouseDown[ 0 ] || io.MouseDown[ 1 ] ) ) {
|
||||||
return;
|
dnd = E_DNDType::NONE;
|
||||||
}
|
|
||||||
|
|
||||||
if ( !( io.MouseDown[ 0 ] || io.MouseDown[ 1 ] ) ) {
|
|
||||||
ClearActiveID( );
|
ClearActiveID( );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -864,10 +877,10 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
|
||||||
if ( mp.type == E_MousePosType::NONE ) {
|
if ( mp.type == E_MousePosType::NONE ) {
|
||||||
if ( io.MouseDown[ 0 ] ) {
|
if ( io.MouseDown[ 0 ] ) {
|
||||||
sync.setTime( mTime );
|
sync.setTime( mTime );
|
||||||
}
|
dnd = E_DNDType::TIME;
|
||||||
if ( io.MouseDown[ 1 ] ) {
|
} else if ( io.MouseDown[ 1 ] ) {
|
||||||
firstZoomPixel = mPixels;
|
firstZoomPixel = mPixels;
|
||||||
zoomInProgress = true;
|
dnd = E_DNDType::ZOOM;
|
||||||
curZoomPixel = mPixels;
|
curZoomPixel = mPixels;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -878,6 +891,7 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
|
||||||
selSegment = decltype( selSegment ){};
|
selSegment = decltype( selSegment ){};
|
||||||
selPoint = decltype( selPoint ){};
|
selPoint = decltype( selPoint ){};
|
||||||
sub = E_SubWindow::SW_TRACK;
|
sub = E_SubWindow::SW_TRACK;
|
||||||
|
dnd = E_DNDType::CLICK;
|
||||||
}
|
}
|
||||||
} else if ( mp.type == E_MousePosType::SEGMENT ) {
|
} else if ( mp.type == E_MousePosType::SEGMENT ) {
|
||||||
auto const& dSeg{ dspSegments[ mp.index ] };
|
auto const& dSeg{ dspSegments[ mp.index ] };
|
||||||
|
@ -887,6 +901,7 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
|
||||||
selSegment = dSeg.seg;
|
selSegment = dSeg.seg;
|
||||||
selPoint = decltype( selPoint ){};
|
selPoint = decltype( selPoint ){};
|
||||||
sub = E_SubWindow::SW_SEGMENT;
|
sub = E_SubWindow::SW_SEGMENT;
|
||||||
|
dnd = E_DNDType::CLICK;
|
||||||
}
|
}
|
||||||
} else if ( mp.type == E_MousePosType::POINT ) {
|
} else if ( mp.type == E_MousePosType::POINT ) {
|
||||||
auto const& dPoint{ dspPoints[ mp.index ] };
|
auto const& dPoint{ dspPoints[ mp.index ] };
|
||||||
|
@ -896,8 +911,8 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
|
||||||
selId = dTrack.id;
|
selId = dTrack.id;
|
||||||
selSegment = dSeg.seg;
|
selSegment = dSeg.seg;
|
||||||
selPoint = dPoint.index;
|
selPoint = dPoint.index;
|
||||||
selPointDnD = io.MouseDown[ 0 ] && dPoint.index != 0;
|
const bool pdnd{ io.MouseDown[ 0 ] && dPoint.index != 0 };
|
||||||
if ( selPointDnD ) {
|
if ( pdnd ) {
|
||||||
assert( selUpdate == E_ChangeType::NONE );
|
assert( selUpdate == E_ChangeType::NONE );
|
||||||
selPointDnDStart = selPointDnDCur = mPixels;
|
selPointDnDStart = selPointDnDCur = mPixels;
|
||||||
if ( selId->isOverride ) {
|
if ( selId->isOverride ) {
|
||||||
|
@ -910,6 +925,9 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
|
||||||
selUpdatingOriginals.add( *sync.getCurve( selId->id ) );
|
selUpdatingOriginals.add( *sync.getCurve( selId->id ) );
|
||||||
}
|
}
|
||||||
selUpdate = E_ChangeType::POINT_DND;
|
selUpdate = E_ChangeType::POINT_DND;
|
||||||
|
dnd = E_DNDType::POINT;
|
||||||
|
} else {
|
||||||
|
dnd = E_DNDType::CLICK;
|
||||||
}
|
}
|
||||||
sub = E_SubWindow::SW_POINT;
|
sub = E_SubWindow::SW_POINT;
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1031,7 @@ void T_SyncViewImpl_::sequencerBody(
|
||||||
|
|
||||||
dl->AddRectFilled( inner.Min , inner.Max , ColMain );
|
dl->AddRectFilled( inner.Min , inner.Max , ColMain );
|
||||||
dl->AddRect( bb.Min , bb.Max , ColFrame );
|
dl->AddRect( bb.Min , bb.Max , ColFrame );
|
||||||
if ( zoomInProgress ) {
|
if ( dnd == E_DNDType::ZOOM ) {
|
||||||
const float z0{ ImClamp( firstZoomPixel - startPixel + inner.Min.x , inner.Min.x , inner.Max.x ) } ,
|
const float z0{ ImClamp( firstZoomPixel - startPixel + inner.Min.x , inner.Min.x , inner.Max.x ) } ,
|
||||||
z1{ ImClamp( curZoomPixel - startPixel + bb.Min.x , inner.Min.x , inner.Max.x ) };
|
z1{ ImClamp( curZoomPixel - startPixel + bb.Min.x , inner.Min.x , inner.Max.x ) };
|
||||||
const float zMin{ std::min( z0 , z1 ) } , zMax{ std::max( z0 , z1 ) };
|
const float zMin{ std::min( z0 , z1 ) } , zMax{ std::max( z0 , z1 ) };
|
||||||
|
@ -1430,7 +1448,6 @@ 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;
|
|
||||||
if ( moved ) {
|
if ( moved ) {
|
||||||
auto& undo{ dynamic_cast< T_UndoSyncChanges& >(
|
auto& undo{ dynamic_cast< T_UndoSyncChanges& >(
|
||||||
Common::Undo( ).add< T_UndoSyncChanges >( ) ) };
|
Common::Undo( ).add< T_UndoSyncChanges >( ) ) };
|
||||||
|
|
Loading…
Reference in a new issue