1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-18 17:10:55 +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 ) wxCoord GetPlayHeadX( const AudacityProject *pProject )
{ {
const auto &tp = TrackPanel::Get( *pProject );
const auto &viewInfo = ViewInfo::Get( *pProject ); const auto &viewInfo = ViewInfo::Get( *pProject );
int width; auto width = viewInfo.GetTracksUsableWidth();
tp.GetTracksUsableArea(&width, NULL);
return viewInfo.GetLeftOffset() return viewInfo.GetLeftOffset()
+ width * TracksPrefs::GetPinnedHeadPositionPreference(); + width * TracksPrefs::GetPinnedHeadPositionPreference();
} }
double GetPlayHeadFraction( const AudacityProject *pProject, wxCoord xx ) double GetPlayHeadFraction( const AudacityProject *pProject, wxCoord xx )
{ {
const auto &tp = TrackPanel::Get( *pProject );
const auto &viewInfo = ViewInfo::Get( *pProject ); const auto &viewInfo = ViewInfo::Get( *pProject );
int width; auto width = viewInfo.GetTracksUsableWidth();
tp.GetTracksUsableArea(&width, NULL);
auto fraction = (xx - viewInfo.GetLeftOffset()) / double(width); auto fraction = (xx - viewInfo.GetLeftOffset()) / double(width);
return std::max(0.0, std::min(1.0, fraction)); 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) void AdornedRulerPanel::UpdateQuickPlayPos(wxCoord &mousePosX, bool shiftDown)
{ {
// Keep Quick-Play within usable track area. // Keep Quick-Play within usable track area.
const auto &tp = TrackPanel::Get( *mProject );
const auto &viewInfo = ViewInfo::Get( *mProject ); const auto &viewInfo = ViewInfo::Get( *mProject );
int width; auto width = viewInfo.GetTracksUsableWidth();
tp.GetTracksUsableArea(&width, NULL);
mousePosX = std::max(mousePosX, viewInfo.GetLeftOffset()); mousePosX = std::max(mousePosX, viewInfo.GetLeftOffset());
mousePosX = std::min(mousePosX, viewInfo.GetLeftOffset() + width - 1); mousePosX = std::min(mousePosX, viewInfo.GetLeftOffset() + width - 1);

View File

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

View File

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

View File

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

View File

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

View File

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