1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-01-01 17:38:43 +01:00

Remove GetLink(ed) in TrackPanel resizing code

This commit is contained in:
Paul Licameli
2017-01-11 14:00:31 -05:00
parent d2a18f01e3
commit ecc869bdbe
3 changed files with 37 additions and 40 deletions

View File

@@ -26,6 +26,8 @@ Paul Licameli split from TrackPanel.cpp
HitTestPreview TrackPanelResizeHandle::HitPreview(bool bLinked) HitTestPreview TrackPanelResizeHandle::HitPreview(bool bLinked)
{ {
// TODO: more-than-two-channels-message
static wxCursor resizeCursor{ wxCURSOR_SIZENS }; static wxCursor resizeCursor{ wxCURSOR_SIZENS };
/// When in the resize area we can adjust size or relative size. /// When in the resize area we can adjust size or relative size.
@@ -59,40 +61,34 @@ UIHandle::Result TrackPanelResizeHandle::Click
} }
TrackPanelResizeHandle::TrackPanelResizeHandle TrackPanelResizeHandle::TrackPanelResizeHandle
( const std::shared_ptr<Track> &track, int y, const AudacityProject *pProject ) ( const std::shared_ptr<Track> &track, int y )
: mpTrack{ track } : mpTrack{ track }
, mMouseClickY( y ) , mMouseClickY( y )
{ {
auto tracks = pProject->GetTracks(); // TODO: more-than-two-channels
auto prev = * -- tracks->Find(track.get());
auto next = * ++ tracks->Find(track.get());
//STM: Determine whether we should rescale one or two tracks //STM: Determine whether we should rescale one or two tracks
if (prev && prev->GetLink() == track.get()) { auto channels = TrackList::Channels(track.get());
// mpTrack is the lower track auto last = *channels.rbegin();
mInitialTrackHeight = track->GetHeight(); mInitialTrackHeight = last->GetHeight();
mInitialActualHeight = track->GetActualHeight(); mInitialActualHeight = last->GetActualHeight();
mInitialMinimized = track->GetMinimized(); mInitialMinimized = last->GetMinimized();
mInitialUpperTrackHeight = prev->GetHeight();
mInitialUpperActualHeight = prev->GetActualHeight(); if (channels.size() > 1) {
mMode = IsResizingBelowLinkedTracks; auto first = *channels.begin();
mInitialUpperTrackHeight = first->GetHeight();
mInitialUpperActualHeight = first->GetActualHeight();
if (track.get() == *channels.rbegin())
// capturedTrack is the lowest track
mMode = IsResizingBelowLinkedTracks;
else
// capturedTrack is not the lowest track
mMode = IsResizingBetweenLinkedTracks;
} }
else if (next && track->GetLink() == next) { else
// mpTrack is the upper track
mInitialTrackHeight = next->GetHeight();
mInitialActualHeight = next->GetActualHeight();
mInitialMinimized = next->GetMinimized();
mInitialUpperTrackHeight = track->GetHeight();
mInitialUpperActualHeight = track->GetActualHeight();
mMode = IsResizingBetweenLinkedTracks;
}
else {
// DM: Save the initial mouse location and the initial height
mInitialTrackHeight = track->GetHeight();
mInitialActualHeight = track->GetActualHeight();
mInitialMinimized = track->GetMinimized();
mMode = IsResizing; mMode = IsResizing;
}
} }
UIHandle::Result TrackPanelResizeHandle::Drag UIHandle::Result TrackPanelResizeHandle::Drag
@@ -113,23 +109,24 @@ UIHandle::Result TrackPanelResizeHandle::Drag
// This used to be in HandleResizeClick(), but simply clicking // This used to be in HandleResizeClick(), but simply clicking
// on a resize border would switch the minimized state. // on a resize border would switch the minimized state.
if (pTrack->GetMinimized()) { if (pTrack->GetMinimized()) {
Track *link = pTrack->GetLink(); auto channels = TrackList::Channels( pTrack.get() );
for (auto channel : channels) {
channel->SetHeight(channel->GetHeight());
channel->SetMinimized(false);
}
pTrack->SetHeight(pTrack->GetHeight()); if (channels.size() > 1) {
pTrack->SetMinimized(false);
if (link) {
link->SetHeight(link->GetHeight());
link->SetMinimized(false);
// Initial values must be reset since they weren't based on the // Initial values must be reset since they weren't based on the
// minimized heights. // minimized heights.
mInitialUpperTrackHeight = link->GetHeight(); mInitialUpperTrackHeight = (*channels.begin())->GetHeight();
mInitialTrackHeight = pTrack->GetHeight(); mInitialTrackHeight = (*channels.rbegin())->GetHeight();
} }
} }
// Common pieces of code for MONO_WAVE_PAN and otherwise. // Common pieces of code for MONO_WAVE_PAN and otherwise.
auto doResizeBelow = [&] (Track *prev, bool WXUNUSED(vStereo)) { auto doResizeBelow = [&] (Track *prev, bool WXUNUSED(vStereo)) {
// TODO: more-than-two-channels
double proportion = static_cast < double >(mInitialTrackHeight) double proportion = static_cast < double >(mInitialTrackHeight)
/ (mInitialTrackHeight + mInitialUpperTrackHeight); / (mInitialTrackHeight + mInitialUpperTrackHeight);
@@ -150,6 +147,8 @@ UIHandle::Result TrackPanelResizeHandle::Drag
}; };
auto doResizeBetween = [&] (Track *next, bool WXUNUSED(vStereo)) { auto doResizeBetween = [&] (Track *next, bool WXUNUSED(vStereo)) {
// TODO: more-than-two-channels
int newUpperTrackHeight = mInitialUpperTrackHeight + delta; int newUpperTrackHeight = mInitialUpperTrackHeight + delta;
int newTrackHeight = mInitialTrackHeight - delta; int newTrackHeight = mInitialTrackHeight - delta;

View File

@@ -22,9 +22,7 @@ class TrackPanelResizeHandle final : public UIHandle
TrackPanelResizeHandle(const TrackPanelResizeHandle&) = delete; TrackPanelResizeHandle(const TrackPanelResizeHandle&) = delete;
public: public:
explicit TrackPanelResizeHandle explicit TrackPanelResizeHandle( const std::shared_ptr<Track> &pTrack, int y );
( const std::shared_ptr<Track> &pTrack, int y,
const AudacityProject *pProject );
TrackPanelResizeHandle &operator=(const TrackPanelResizeHandle&) = default; TrackPanelResizeHandle &operator=(const TrackPanelResizeHandle&) = default;

View File

@@ -28,7 +28,7 @@ std::vector<UIHandlePtr> TrackPanelResizerCell::HitTest
auto pTrack = mpTrack.lock(); auto pTrack = mpTrack.lock();
if (pTrack) { if (pTrack) {
auto result = std::make_shared<TrackPanelResizeHandle>( auto result = std::make_shared<TrackPanelResizeHandle>(
pTrack, st.state.m_y, pProject ); pTrack, st.state.m_y );
result = AssignUIHandlePtr(mResizeHandle, result); result = AssignUIHandlePtr(mResizeHandle, result);
results.push_back(result); results.push_back(result);
} }