1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-17 16:50:26 +02:00

GetSceenEndTime out of TrackPanel

This commit is contained in:
Paul Licameli 2019-06-21 12:14:46 -04:00
parent d29d10d712
commit 868481b686
9 changed files with 33 additions and 42 deletions

View File

@ -413,7 +413,6 @@ unsigned operator()
// MM: Zoom in/out when used with Control key down // MM: Zoom in/out when used with Control key down
// We're converting pixel positions to times, // We're converting pixel positions to times,
// counting pixels from the left edge of the track. // counting pixels from the left edge of the track.
auto &trackPanel = TrackPanel::Get( *pProject );
int trackLeftEdge = viewInfo.GetLeftOffset(); int trackLeftEdge = viewInfo.GetLeftOffset();
// Time corresponding to mouse position // Time corresponding to mouse position
@ -424,7 +423,7 @@ unsigned operator()
// Scrubbing? Expand or contract about the center, ignoring mouse position // Scrubbing? Expand or contract about the center, ignoring mouse position
if (scrubber.IsScrollScrubbing()) if (scrubber.IsScrollScrubbing())
center_h = viewInfo.h + center_h = viewInfo.h +
(trackPanel.GetScreenEndTime() - viewInfo.h) / 2.0; (viewInfo.GetScreenEndTime() - viewInfo.h) / 2.0;
// Zooming out? Focus on mouse. // Zooming out? Focus on mouse.
else if( steps <= 0 ) else if( steps <= 0 )
center_h = mouse_h; center_h = mouse_h;
@ -1049,11 +1048,10 @@ double ProjectWindow::ScrollingLowerBoundTime() const
{ {
auto &project = mProject; auto &project = mProject;
auto &tracks = TrackList::Get( project ); auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project ); auto &viewInfo = ViewInfo::Get( project );
if (!MayScrollBeyondZero()) if (!MayScrollBeyondZero())
return 0; return 0;
const double screen = trackPanel.GetScreenEndTime() - viewInfo.h; const double screen = viewInfo.GetScreenEndTime() - viewInfo.h;
return std::min(tracks.GetStartTime(), -screen); return std::min(tracks.GetStartTime(), -screen);
} }
@ -1171,7 +1169,7 @@ void ProjectWindow::FixScrollbars()
std::max(LastTime, viewInfo.selectedRegion.t1()); std::max(LastTime, viewInfo.selectedRegion.t1());
const double screen = const double screen =
trackPanel.GetScreenEndTime() - viewInfo.h; viewInfo.GetScreenEndTime() - viewInfo.h;
const double halfScreen = screen / 2.0; const double halfScreen = screen / 2.0;
// If we can scroll beyond zero, // If we can scroll beyond zero,
@ -1218,7 +1216,7 @@ void ProjectWindow::FixScrollbars()
bool oldhstate; bool oldhstate;
bool oldvstate; bool oldvstate;
bool newhstate = bool newhstate =
(trackPanel.GetScreenEndTime() - viewInfo.h) < viewInfo.total; (viewInfo.GetScreenEndTime() - viewInfo.h) < viewInfo.total;
bool newvstate = panelHeight < totalHeight; bool newvstate = panelHeight < totalHeight;
#ifdef __WXGTK__ #ifdef __WXGTK__
@ -1277,7 +1275,7 @@ void ProjectWindow::FixScrollbars()
panelHeight / viewInfo.scrollStep, TRUE); panelHeight / viewInfo.scrollStep, TRUE);
if (refresh || (rescroll && if (refresh || (rescroll &&
(trackPanel.GetScreenEndTime() - viewInfo.h) < viewInfo.total)) { (viewInfo.GetScreenEndTime() - viewInfo.h) < viewInfo.total)) {
trackPanel.Refresh(false); trackPanel.Refresh(false);
} }
@ -1631,7 +1629,7 @@ void ProjectWindow::Zoom(double level)
// tOnLeft is the amount of time we would need before the selection left edge to center it. // tOnLeft is the amount of time we would need before the selection left edge to center it.
float t0 = viewInfo.selectedRegion.t0(); float t0 = viewInfo.selectedRegion.t0();
float t1 = viewInfo.selectedRegion.t1(); float t1 = viewInfo.selectedRegion.t1();
float tAvailable = TrackPanel::Get( project ).GetScreenEndTime() - viewInfo.h; float tAvailable = viewInfo.GetScreenEndTime() - viewInfo.h;
float tOnLeft = (tAvailable - t0 + t1)/2.0; float tOnLeft = (tAvailable - t0 + t1)/2.0;
// Bug 1292 (Enh) is effectively a request to do this scrolling of the selection into view. // Bug 1292 (Enh) is effectively a request to do this scrolling of the selection into view.
// If tOnLeft is positive, then we have room for the selection, so scroll to it. // If tOnLeft is positive, then we have room for the selection, so scroll to it.
@ -1814,7 +1812,7 @@ void ProjectWindow::ZoomInByFactor( double ZoomFactor )
// when there's a selection that's currently at least // when there's a selection that's currently at least
// partially on-screen // partially on-screen
const double endTime = trackPanel.GetScreenEndTime(); const double endTime = viewInfo.GetScreenEndTime();
const double duration = endTime - viewInfo.h; const double duration = endTime - viewInfo.h;
bool selectionIsOnscreen = bool selectionIsOnscreen =
@ -1842,7 +1840,7 @@ void ProjectWindow::ZoomInByFactor( double ZoomFactor )
// Zoom in // Zoom in
ZoomBy(ZoomFactor); ZoomBy(ZoomFactor);
const double newDuration = const double newDuration =
trackPanel.GetScreenEndTime() - viewInfo.h; viewInfo.GetScreenEndTime() - viewInfo.h;
// Recenter on selCenter // Recenter on selCenter
TP_ScrollWindow(selCenter - newDuration / 2); TP_ScrollWindow(selCenter - newDuration / 2);
@ -1855,7 +1853,7 @@ void ProjectWindow::ZoomInByFactor( double ZoomFactor )
ZoomBy(ZoomFactor); ZoomBy(ZoomFactor);
const double newDuration = const double newDuration =
trackPanel.GetScreenEndTime() - viewInfo.h; viewInfo.GetScreenEndTime() - viewInfo.h;
double newh = origLeft + (origWidth - newDuration) / 2; double newh = origLeft + (origWidth - newDuration) / 2;
// MM: Commented this out because it was confusing users // MM: Commented this out because it was confusing users
@ -1877,15 +1875,14 @@ void ProjectWindow::ZoomInByFactor( double ZoomFactor )
void ProjectWindow::ZoomOutByFactor( double ZoomFactor ) void ProjectWindow::ZoomOutByFactor( double ZoomFactor )
{ {
auto &project = mProject; auto &project = mProject;
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project ); auto &viewInfo = ViewInfo::Get( project );
//Zoom() may change these, so record original values: //Zoom() may change these, so record original values:
const double origLeft = viewInfo.h; const double origLeft = viewInfo.h;
const double origWidth = trackPanel.GetScreenEndTime() - origLeft; const double origWidth = viewInfo.GetScreenEndTime() - origLeft;
ZoomBy(ZoomFactor); ZoomBy(ZoomFactor);
const double newWidth = trackPanel.GetScreenEndTime() - viewInfo.h; const double newWidth = viewInfo.GetScreenEndTime() - viewInfo.h;
const double newh = origLeft + (origWidth - newWidth) / 2; const double newh = origLeft + (origWidth - newWidth) / 2;
// newh = (newh > 0) ? newh : 0; // newh = (newh > 0) ? newh : 0;

View File

@ -498,12 +498,6 @@ void TrackPanel::OnProjectSettingsChange( wxCommandEvent &event )
} }
} }
double TrackPanel::GetScreenEndTime() const
{
auto width = mViewInfo->GetTracksUsableWidth();
return mViewInfo->PositionToTime(width, 0, true);
}
void TrackPanel::OnUndoReset( wxCommandEvent &event ) void TrackPanel::OnUndoReset( wxCommandEvent &event )
{ {
event.Skip(); event.Skip();
@ -665,12 +659,12 @@ void TrackPanel::ProcessUIHandleResult
void TrackPanel::HandlePageUpKey() void TrackPanel::HandlePageUpKey()
{ {
mListener->TP_ScrollWindow(2 * mViewInfo->h - GetScreenEndTime()); mListener->TP_ScrollWindow(2 * mViewInfo->h - mViewInfo->GetScreenEndTime());
} }
void TrackPanel::HandlePageDownKey() void TrackPanel::HandlePageDownKey()
{ {
mListener->TP_ScrollWindow(GetScreenEndTime()); mListener->TP_ScrollWindow(mViewInfo->GetScreenEndTime());
} }
bool TrackPanel::IsAudioActive() bool TrackPanel::IsAudioActive()

View File

@ -134,10 +134,6 @@ class AUDACITY_DLL_API TrackPanel final
void UpdateTrackVRuler(const Track *t); void UpdateTrackVRuler(const Track *t);
void UpdateVRulerSize(); void UpdateVRulerSize();
// Returns the time corresponding to the pixel column one past the track area
// (ignoring any fisheye)
double GetScreenEndTime() const;
protected: protected:
bool IsAudioActive(); bool IsAudioActive();

View File

@ -107,6 +107,14 @@ public:
std::max( 0, GetWidth() - ( GetLeftOffset() + kRightMargin ) ); std::max( 0, GetWidth() - ( GetLeftOffset() + kRightMargin ) );
} }
// Returns the time corresponding to the pixel column one past the track area
// (ignoring any fisheye)
double GetScreenEndTime() const
{
auto width = GetTracksUsableWidth();
return PositionToTime(width, 0, true);
}
bool ZoomInAvailable() const; bool ZoomInAvailable() const;
bool ZoomOutAvailable() const; bool ZoomOutAvailable() const;

View File

@ -240,7 +240,7 @@ void MoveWhenAudioInactive
const double t0 = viewInfo.selectedRegion.t0(); const double t0 = viewInfo.selectedRegion.t0();
const double end = std::max( const double end = std::max(
tracks.GetEndTime(), tracks.GetEndTime(),
trackPanel.GetScreenEndTime()); viewInfo.GetScreenEndTime());
// Move the cursor // Move the cursor
// Already in cursor mode? // Already in cursor mode?
@ -299,7 +299,7 @@ SelectionOperation operation)
const double t1 = viewInfo.selectedRegion.t1(); const double t1 = viewInfo.selectedRegion.t1();
const double end = std::max( const double end = std::max(
tracks.GetEndTime(), tracks.GetEndTime(),
trackPanel.GetScreenEndTime()); viewInfo.GetScreenEndTime());
// Is it t0 or t1 moving? // Is it t0 or t1 moving?
bool bMoveT0 = (operation == SELECTION_CONTRACT && seekStep > 0) || bool bMoveT0 = (operation == SELECTION_CONTRACT && seekStep > 0) ||
@ -421,7 +421,7 @@ void DoBoundaryMove(AudacityProject &project, int step, SeekInfo &info)
const double t1 = viewInfo.selectedRegion.t1(); const double t1 = viewInfo.selectedRegion.t1();
const double end = std::max( const double end = std::max(
tracks.GetEndTime(), tracks.GetEndTime(),
trackPanel.GetScreenEndTime()); viewInfo.GetScreenEndTime());
double newT = viewInfo.OffsetTimeByPixels( bMoveT0 ? t0 : t1, pixels); double newT = viewInfo.OffsetTimeByPixels( bMoveT0 ? t0 : t1, pixels);
// constrain to be in the track/screen limits. // constrain to be in the track/screen limits.

View File

@ -227,7 +227,7 @@ void OnZoomToggle(const CommandContext &context)
auto &window = ProjectWindow::Get( project ); auto &window = ProjectWindow::Get( project );
// const double origLeft = viewInfo.h; // const double origLeft = viewInfo.h;
// const double origWidth = GetScreenEndTime() - origLeft; // const double origWidth = viewInfo.GetScreenEndTime() - origLeft;
// Choose the zoom that is most different to the current zoom. // Choose the zoom that is most different to the current zoom.
double Zoom1 = GetZoomOfPreset( project, TracksPrefs::Zoom1Choice() ); double Zoom1 = GetZoomOfPreset( project, TracksPrefs::Zoom1Choice() );
@ -305,14 +305,13 @@ void OnGoSelStart(const CommandContext &context)
auto &project = context.project; auto &project = context.project;
auto &viewInfo = ViewInfo::Get( project ); auto &viewInfo = ViewInfo::Get( project );
auto &selectedRegion = viewInfo.selectedRegion; auto &selectedRegion = viewInfo.selectedRegion;
auto &trackPanel = TrackPanel::Get( project );
auto &window = ProjectWindow::Get( project ); auto &window = ProjectWindow::Get( project );
if (selectedRegion.isPoint()) if (selectedRegion.isPoint())
return; return;
window.TP_ScrollWindow( window.TP_ScrollWindow(
selectedRegion.t0() - ((trackPanel.GetScreenEndTime() - viewInfo.h) / 2)); selectedRegion.t0() - ((viewInfo.GetScreenEndTime() - viewInfo.h) / 2));
} }
void OnGoSelEnd(const CommandContext &context) void OnGoSelEnd(const CommandContext &context)
@ -320,14 +319,13 @@ void OnGoSelEnd(const CommandContext &context)
auto &project = context.project; auto &project = context.project;
auto &viewInfo = ViewInfo::Get( project ); auto &viewInfo = ViewInfo::Get( project );
auto &selectedRegion = viewInfo.selectedRegion; auto &selectedRegion = viewInfo.selectedRegion;
auto &trackPanel = TrackPanel::Get( project );
auto &window = ProjectWindow::Get( project ); auto &window = ProjectWindow::Get( project );
if (selectedRegion.isPoint()) if (selectedRegion.isPoint())
return; return;
window.TP_ScrollWindow( window.TP_ScrollWindow(
selectedRegion.t1() - ((trackPanel.GetScreenEndTime() - viewInfo.h) / 2)); selectedRegion.t1() - ((viewInfo.GetScreenEndTime() - viewInfo.h) / 2));
} }
void OnHistory(const CommandContext &context) void OnHistory(const CommandContext &context)

View File

@ -90,15 +90,15 @@ void EditCursorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
const auto &viewInfo = ViewInfo::Get( *mProject ); const auto &viewInfo = ViewInfo::Get( *mProject );
auto &trackPanel = TrackPanel::Get( *mProject );
const bool const bool
onScreen = between_incexc(viewInfo.h, onScreen = between_incexc(viewInfo.h,
mCursorTime, mCursorTime,
trackPanel.GetScreenEndTime()); viewInfo.GetScreenEndTime());
if (!onScreen) if (!onScreen)
return; return;
auto &trackPanel = TrackPanel::Get( *mProject );
if (auto tp = dynamic_cast<TrackPanel*>(&panel)) { if (auto tp = dynamic_cast<TrackPanel*>(&panel)) {
wxASSERT(mIsMaster); wxASSERT(mIsMaster);
AColor::CursorColor(&dc); AColor::CursorColor(&dc);

View File

@ -148,7 +148,6 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
ruler.AddOverlay( mPartner ); ruler.AddOverlay( mPartner );
} }
auto &trackPanel = TrackPanel::Get( *mProject );
const auto &viewInfo = ViewInfo::Get( *mProject ); const auto &viewInfo = ViewInfo::Get( *mProject );
auto width = viewInfo.GetTracksUsableWidth(); auto width = viewInfo.GetTracksUsableWidth();
@ -176,12 +175,11 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
// Use a small tolerance to avoid flicker of play head pinned all the way // Use a small tolerance to avoid flicker of play head pinned all the way
// left or right // left or right
auto &trackPanel = TrackPanel::Get( *mProject );
const auto tolerance = pinned ? 1.5 * kTimerInterval / 1000.0 : 0; const auto tolerance = pinned ? 1.5 * kTimerInterval / 1000.0 : 0;
bool onScreen = playPos >= 0.0 && bool onScreen = playPos >= 0.0 &&
between_incexc(viewInfo.h - tolerance, between_incexc(viewInfo.h - tolerance,
playPos, playPos,
trackPanel.GetScreenEndTime() + tolerance); viewInfo.GetScreenEndTime() + tolerance);
// This displays the audio time, too... // This displays the audio time, too...
window.TP_DisplaySelection(); window.TP_DisplaySelection();
@ -213,7 +211,7 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
onScreen = playPos >= 0.0 && onScreen = playPos >= 0.0 &&
between_incexc(viewInfo.h, between_incexc(viewInfo.h,
playPos, playPos,
trackPanel.GetScreenEndTime()); viewInfo.GetScreenEndTime());
} }
} }

View File

@ -374,7 +374,7 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
auto delta = time0 - time1; auto delta = time0 - time1;
time0 = std::max(0.0, std::min(maxTime, time0 = std::max(0.0, std::min(maxTime,
viewInfo.h + viewInfo.h +
(mProject->GetScreenEndTime() - viewInfo.h) (viewInfo.GetScreenEndTime() - viewInfo.h)
* TracksPrefs::GetPinnedHeadPositionPreference() * TracksPrefs::GetPinnedHeadPositionPreference()
)); ));
time1 = time0 + delta; time1 = time0 + delta;
@ -820,7 +820,7 @@ double Scrubber::FindScrubSpeed(bool seeking, double time) const
{ {
auto &viewInfo = ViewInfo::Get( *mProject ); auto &viewInfo = ViewInfo::Get( *mProject );
const double screen = const double screen =
TrackPanel::Get( *mProject ).GetScreenEndTime() - viewInfo.h; viewInfo.GetScreenEndTime() - viewInfo.h;
return (seeking ? FindSeekSpeed : FindScrubbingSpeed) return (seeking ? FindSeekSpeed : FindScrubbingSpeed)
(viewInfo, mMaxSpeed, screen, time); (viewInfo, mMaxSpeed, screen, time);
} }