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
// We're converting pixel positions to times,
// counting pixels from the left edge of the track.
auto &trackPanel = TrackPanel::Get( *pProject );
int trackLeftEdge = viewInfo.GetLeftOffset();
// Time corresponding to mouse position
@ -424,7 +423,7 @@ unsigned operator()
// Scrubbing? Expand or contract about the center, ignoring mouse position
if (scrubber.IsScrollScrubbing())
center_h = viewInfo.h +
(trackPanel.GetScreenEndTime() - viewInfo.h) / 2.0;
(viewInfo.GetScreenEndTime() - viewInfo.h) / 2.0;
// Zooming out? Focus on mouse.
else if( steps <= 0 )
center_h = mouse_h;
@ -1049,11 +1048,10 @@ double ProjectWindow::ScrollingLowerBoundTime() const
{
auto &project = mProject;
auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project );
if (!MayScrollBeyondZero())
return 0;
const double screen = trackPanel.GetScreenEndTime() - viewInfo.h;
const double screen = viewInfo.GetScreenEndTime() - viewInfo.h;
return std::min(tracks.GetStartTime(), -screen);
}
@ -1171,7 +1169,7 @@ void ProjectWindow::FixScrollbars()
std::max(LastTime, viewInfo.selectedRegion.t1());
const double screen =
trackPanel.GetScreenEndTime() - viewInfo.h;
viewInfo.GetScreenEndTime() - viewInfo.h;
const double halfScreen = screen / 2.0;
// If we can scroll beyond zero,
@ -1218,7 +1216,7 @@ void ProjectWindow::FixScrollbars()
bool oldhstate;
bool oldvstate;
bool newhstate =
(trackPanel.GetScreenEndTime() - viewInfo.h) < viewInfo.total;
(viewInfo.GetScreenEndTime() - viewInfo.h) < viewInfo.total;
bool newvstate = panelHeight < totalHeight;
#ifdef __WXGTK__
@ -1277,7 +1275,7 @@ void ProjectWindow::FixScrollbars()
panelHeight / viewInfo.scrollStep, TRUE);
if (refresh || (rescroll &&
(trackPanel.GetScreenEndTime() - viewInfo.h) < viewInfo.total)) {
(viewInfo.GetScreenEndTime() - viewInfo.h) < viewInfo.total)) {
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.
float t0 = viewInfo.selectedRegion.t0();
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;
// 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.
@ -1814,7 +1812,7 @@ void ProjectWindow::ZoomInByFactor( double ZoomFactor )
// when there's a selection that's currently at least
// partially on-screen
const double endTime = trackPanel.GetScreenEndTime();
const double endTime = viewInfo.GetScreenEndTime();
const double duration = endTime - viewInfo.h;
bool selectionIsOnscreen =
@ -1842,7 +1840,7 @@ void ProjectWindow::ZoomInByFactor( double ZoomFactor )
// Zoom in
ZoomBy(ZoomFactor);
const double newDuration =
trackPanel.GetScreenEndTime() - viewInfo.h;
viewInfo.GetScreenEndTime() - viewInfo.h;
// Recenter on selCenter
TP_ScrollWindow(selCenter - newDuration / 2);
@ -1855,7 +1853,7 @@ void ProjectWindow::ZoomInByFactor( double ZoomFactor )
ZoomBy(ZoomFactor);
const double newDuration =
trackPanel.GetScreenEndTime() - viewInfo.h;
viewInfo.GetScreenEndTime() - viewInfo.h;
double newh = origLeft + (origWidth - newDuration) / 2;
// MM: Commented this out because it was confusing users
@ -1877,15 +1875,14 @@ void ProjectWindow::ZoomInByFactor( double ZoomFactor )
void ProjectWindow::ZoomOutByFactor( double ZoomFactor )
{
auto &project = mProject;
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project );
//Zoom() may change these, so record original values:
const double origLeft = viewInfo.h;
const double origWidth = trackPanel.GetScreenEndTime() - origLeft;
const double origWidth = viewInfo.GetScreenEndTime() - origLeft;
ZoomBy(ZoomFactor);
const double newWidth = trackPanel.GetScreenEndTime() - viewInfo.h;
const double newWidth = viewInfo.GetScreenEndTime() - viewInfo.h;
const double newh = origLeft + (origWidth - newWidth) / 2;
// 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 )
{
event.Skip();
@ -665,12 +659,12 @@ void TrackPanel::ProcessUIHandleResult
void TrackPanel::HandlePageUpKey()
{
mListener->TP_ScrollWindow(2 * mViewInfo->h - GetScreenEndTime());
mListener->TP_ScrollWindow(2 * mViewInfo->h - mViewInfo->GetScreenEndTime());
}
void TrackPanel::HandlePageDownKey()
{
mListener->TP_ScrollWindow(GetScreenEndTime());
mListener->TP_ScrollWindow(mViewInfo->GetScreenEndTime());
}
bool TrackPanel::IsAudioActive()

View File

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

View File

@ -107,6 +107,14 @@ public:
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 ZoomOutAvailable() const;

View File

@ -240,7 +240,7 @@ void MoveWhenAudioInactive
const double t0 = viewInfo.selectedRegion.t0();
const double end = std::max(
tracks.GetEndTime(),
trackPanel.GetScreenEndTime());
viewInfo.GetScreenEndTime());
// Move the cursor
// Already in cursor mode?
@ -299,7 +299,7 @@ SelectionOperation operation)
const double t1 = viewInfo.selectedRegion.t1();
const double end = std::max(
tracks.GetEndTime(),
trackPanel.GetScreenEndTime());
viewInfo.GetScreenEndTime());
// Is it t0 or t1 moving?
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 end = std::max(
tracks.GetEndTime(),
trackPanel.GetScreenEndTime());
viewInfo.GetScreenEndTime());
double newT = viewInfo.OffsetTimeByPixels( bMoveT0 ? t0 : t1, pixels);
// constrain to be in the track/screen limits.

View File

@ -227,7 +227,7 @@ void OnZoomToggle(const CommandContext &context)
auto &window = ProjectWindow::Get( project );
// 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.
double Zoom1 = GetZoomOfPreset( project, TracksPrefs::Zoom1Choice() );
@ -305,14 +305,13 @@ void OnGoSelStart(const CommandContext &context)
auto &project = context.project;
auto &viewInfo = ViewInfo::Get( project );
auto &selectedRegion = viewInfo.selectedRegion;
auto &trackPanel = TrackPanel::Get( project );
auto &window = ProjectWindow::Get( project );
if (selectedRegion.isPoint())
return;
window.TP_ScrollWindow(
selectedRegion.t0() - ((trackPanel.GetScreenEndTime() - viewInfo.h) / 2));
selectedRegion.t0() - ((viewInfo.GetScreenEndTime() - viewInfo.h) / 2));
}
void OnGoSelEnd(const CommandContext &context)
@ -320,14 +319,13 @@ void OnGoSelEnd(const CommandContext &context)
auto &project = context.project;
auto &viewInfo = ViewInfo::Get( project );
auto &selectedRegion = viewInfo.selectedRegion;
auto &trackPanel = TrackPanel::Get( project );
auto &window = ProjectWindow::Get( project );
if (selectedRegion.isPoint())
return;
window.TP_ScrollWindow(
selectedRegion.t1() - ((trackPanel.GetScreenEndTime() - viewInfo.h) / 2));
selectedRegion.t1() - ((viewInfo.GetScreenEndTime() - viewInfo.h) / 2));
}
void OnHistory(const CommandContext &context)

View File

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

View File

@ -148,7 +148,6 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
ruler.AddOverlay( mPartner );
}
auto &trackPanel = TrackPanel::Get( *mProject );
const auto &viewInfo = ViewInfo::Get( *mProject );
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
// left or right
auto &trackPanel = TrackPanel::Get( *mProject );
const auto tolerance = pinned ? 1.5 * kTimerInterval / 1000.0 : 0;
bool onScreen = playPos >= 0.0 &&
between_incexc(viewInfo.h - tolerance,
playPos,
trackPanel.GetScreenEndTime() + tolerance);
viewInfo.GetScreenEndTime() + tolerance);
// This displays the audio time, too...
window.TP_DisplaySelection();
@ -213,7 +211,7 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
onScreen = playPos >= 0.0 &&
between_incexc(viewInfo.h,
playPos,
trackPanel.GetScreenEndTime());
viewInfo.GetScreenEndTime());
}
}

View File

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