1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-04 09:39:42 +02:00

GetTracksUsableArea() out of TrackPanel

This commit is contained in:
Paul Licameli 2019-06-08 08:25:16 -04:00
parent f87dfd43c1
commit d29d10d712
8 changed files with 26 additions and 60 deletions

View File

@ -535,20 +535,16 @@ namespace
wxCoord GetPlayHeadX( const AudacityProject *pProject )
{
const auto &tp = TrackPanel::Get( *pProject );
const auto &viewInfo = ViewInfo::Get( *pProject );
int width;
tp.GetTracksUsableArea(&width, NULL);
auto width = viewInfo.GetTracksUsableWidth();
return viewInfo.GetLeftOffset()
+ width * TracksPrefs::GetPinnedHeadPositionPreference();
}
double GetPlayHeadFraction( const AudacityProject *pProject, wxCoord xx )
{
const auto &tp = TrackPanel::Get( *pProject );
const auto &viewInfo = ViewInfo::Get( *pProject );
int width;
tp.GetTracksUsableArea(&width, NULL);
auto width = viewInfo.GetTracksUsableWidth();
auto fraction = (xx - viewInfo.GetLeftOffset()) / double(width);
return std::max(0.0, std::min(1.0, fraction));
}
@ -1711,10 +1707,8 @@ void AdornedRulerPanel::OnTogglePinnedState(wxCommandEvent & /*event*/)
void AdornedRulerPanel::UpdateQuickPlayPos(wxCoord &mousePosX, bool shiftDown)
{
// Keep Quick-Play within usable track area.
const auto &tp = TrackPanel::Get( *mProject );
const auto &viewInfo = ViewInfo::Get( *mProject );
int width;
tp.GetTracksUsableArea(&width, NULL);
auto width = viewInfo.GetTracksUsableWidth();
mousePosX = std::max(mousePosX, viewInfo.GetLeftOffset());
mousePosX = std::min(mousePosX, viewInfo.GetLeftOffset() + width - 1);

View File

@ -1144,8 +1144,8 @@ void ProjectWindow::FixScrollbars()
int totalHeight = TrackView::GetTotalHeight( tracks ) + 32;
int panelWidth, panelHeight;
trackPanel.GetTracksUsableArea(&panelWidth, &panelHeight);
auto panelWidth = viewInfo.GetTracksUsableWidth();
auto panelHeight = viewInfo.GetHeight();
// (From Debian...at least I think this is the change cooresponding
// to this comment)
@ -1469,8 +1469,7 @@ void ProjectWindow::DoScroll()
auto &viewInfo = ViewInfo::Get( project );
const double lowerBound = ScrollingLowerBoundTime();
int width;
trackPanel.GetTracksUsableArea(&width, NULL);
auto width = viewInfo.GetTracksUsableWidth();
viewInfo.SetBeforeScreenWidth(viewInfo.sbarH, width, lowerBound);
@ -1770,8 +1769,7 @@ void ProjectWindow::PlaybackScroller::OnTimer(wxCommandEvent &event)
auto &viewInfo = ViewInfo::Get( *mProject );
auto &trackPanel = TrackPanel::Get( *mProject );
const int posX = viewInfo.TimeToPosition(viewInfo.mRecentStreamTime);
int width;
trackPanel.GetTracksUsableArea(&width, NULL);
auto width = viewInfo.GetTracksUsableWidth();
int deltaX;
switch (mMode)
{
@ -1899,7 +1897,6 @@ double ProjectWindow::GetZoomOfToFit() const
auto &project = mProject;
auto &tracks = TrackList::Get( project );
auto &viewInfo = ViewInfo::Get( project );
auto &trackPanel = TrackPanel::Get( project );
const double end = tracks.GetEndTime();
const double start = viewInfo.bScrollBeyondZero
@ -1910,8 +1907,7 @@ double ProjectWindow::GetZoomOfToFit() const
if (len <= 0.0)
return viewInfo.GetZoom();
int w;
trackPanel.GetTracksUsableArea(&w, NULL);
auto w = viewInfo.GetTracksUsableWidth();
w -= 10;
return w/len;
}

View File

@ -345,25 +345,6 @@ void TrackPanel::UpdatePrefs()
Refresh();
}
wxSize TrackPanel::GetTracksUsableArea() const
{
auto size = GetSize();
return {
std::max( 0,
size.GetWidth() - ( mViewInfo->GetLeftOffset() + kRightMargin ) ),
size.GetHeight()
};
}
void TrackPanel::GetTracksUsableArea(int *width, int *height) const
{
auto size = GetTracksUsableArea();
if (width)
*width = size.GetWidth();
if (height)
*height = size.GetHeight();
}
/// Gets the pointer to the AudacityProject that
/// goes with this track panel.
AudacityProject * TrackPanel::GetProject() const
@ -519,8 +500,7 @@ void TrackPanel::OnProjectSettingsChange( wxCommandEvent &event )
double TrackPanel::GetScreenEndTime() const
{
int width;
GetTracksUsableArea(&width, NULL);
auto width = mViewInfo->GetTracksUsableWidth();
return mViewInfo->PositionToTime(width, 0, true);
}
@ -1302,8 +1282,7 @@ void TrackPanel::UpdateVRulerSize()
// Make sure selection edge is in view
void TrackPanel::ScrollIntoView(double pos)
{
int w;
GetTracksUsableArea( &w, NULL );
auto w = mViewInfo->GetTracksUsableWidth();
int pixel = mViewInfo->TimeToPosition(pos);
if (pixel < 0 || pixel >= w)
@ -1758,7 +1737,10 @@ unsigned TrackPanelCell::Char(wxKeyEvent &event, ViewInfo &, wxWindow *)
IsVisibleTrack::IsVisibleTrack(AudacityProject *project)
: mPanelRect {
wxPoint{ 0, ViewInfo::Get( *project ).vpos },
TrackPanel::Get( *project ).GetTracksUsableArea()
wxSize{
ViewInfo::Get( *project ).GetTracksUsableWidth(),
ViewInfo::Get( *project ).GetHeight()
}
}
{}

View File

@ -103,12 +103,6 @@ class AUDACITY_DLL_API TrackPanel final
void OnProjectSettingsChange(wxCommandEvent &event);
void OnTrackFocusChange( wxCommandEvent &event );
wxSize GetTracksUsableArea() const;
// Width and height, relative to upper left corner at (GetLeftOffset(), 0)
// Either argument may be NULL
void GetTracksUsableArea(int *width, int *height) const;
void OnUndoReset( wxCommandEvent &event );
void Refresh

View File

@ -101,6 +101,12 @@ public:
int GetLabelWidth() const { return GetVRulerOffset() + GetVRulerWidth(); }
int GetLeftOffset() const { return GetLabelWidth() + 1;}
int GetTracksUsableWidth() const
{
return
std::max( 0, GetWidth() - ( GetLeftOffset() + kRightMargin ) );
}
bool ZoomInAvailable() const;
bool ZoomOutAvailable() const;

View File

@ -53,7 +53,6 @@ AudacityProject::AttachedWindows::RegisteredFactory sLyricsWindowKey{
double GetZoomOfSelection( const AudacityProject &project )
{
auto &viewInfo = ViewInfo::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &window = ProjectWindow::Get( project );
const double lowerBound =
@ -74,8 +73,7 @@ double GetZoomOfSelection( const AudacityProject &project )
// Fixes might have resulted from commits
// 1b8f44d0537d987c59653b11ed75a842b48896ea and
// e7c7bb84a966c3b3cc4b3a9717d5f247f25e7296
int width;
trackPanel.GetTracksUsableArea(&width, NULL);
auto width = viewInfo.GetTracksUsableWidth();
return (width - 1) / denom;
}
@ -149,7 +147,7 @@ double GetZoomOfPreset( const AudacityProject &project, int preset )
namespace {
void DoZoomFitV(AudacityProject &project)
{
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project );
auto &tracks = TrackList::Get( project );
// Only nonminimized audio tracks will be resized
@ -161,8 +159,7 @@ void DoZoomFitV(AudacityProject &project)
return;
// Find total height to apportion
int height;
trackPanel.GetTracksUsableArea(NULL, &height);
auto height = viewInfo.GetHeight();
height -= 28;
// The height of minimized and non-audio tracks cannot be apportioned

View File

@ -150,8 +150,7 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
auto &trackPanel = TrackPanel::Get( *mProject );
const auto &viewInfo = ViewInfo::Get( *mProject );
int width;
trackPanel.GetTracksUsableArea(&width, nullptr);
auto width = viewInfo.GetTracksUsableWidth();
if (!ProjectAudioIO::Get( *mProject ).IsAudioActive()) {
mNewIndicatorX = -1;

View File

@ -611,8 +611,7 @@ void Scrubber::ContinueScrubbingPoll()
// toward the mouse position, then move the target time to a more
// extreme position to avoid catching-up and halting before the
// screen scrolls.
int width;
trackPanel.GetTracksUsableArea(&width, NULL);
auto width = viewInfo.GetTracksUsableWidth();
auto delta = xx - origin;
if (delta < 0)
delta -= width;
@ -1077,8 +1076,7 @@ void Scrubber::DoScrub(bool seek)
wxCoord xx = tp.ScreenToClient(::wxGetMouseState().GetPosition()).x;
// Limit x
int width;
tp.GetTracksUsableArea(&width, nullptr);
auto width = viewInfo.GetTracksUsableWidth();
const auto offset = viewInfo.GetLeftOffset();
xx = (std::max(offset, std::min(offset + width - 1, xx)));