1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-21 23:18:02 +02:00

Commonly used rectangle calculations move into ViewInfo/ZoomInfo...

... reducing need for TrackPanel.h
This commit is contained in:
Paul Licameli 2019-06-26 23:38:31 -04:00
commit 040decf9e3
13 changed files with 146 additions and 165 deletions

View File

@ -535,19 +535,17 @@ namespace
wxCoord GetPlayHeadX( const AudacityProject *pProject )
{
const auto &tp = TrackPanel::Get( *pProject );
int width;
tp.GetTracksUsableArea(&width, NULL);
return tp.GetLeftOffset()
const auto &viewInfo = ViewInfo::Get( *pProject );
auto width = viewInfo.GetTracksUsableWidth();
return viewInfo.GetLeftOffset()
+ width * TracksPrefs::GetPinnedHeadPositionPreference();
}
double GetPlayHeadFraction( const AudacityProject *pProject, wxCoord xx )
{
const auto &tp = TrackPanel::Get( *pProject );
int width;
tp.GetTracksUsableArea(&width, NULL);
auto fraction = (xx - tp.GetLeftOffset()) / double(width);
const auto &viewInfo = ViewInfo::Get( *pProject );
auto width = viewInfo.GetTracksUsableWidth();
auto fraction = (xx - viewInfo.GetLeftOffset()) / double(width);
return std::max(0.0, std::min(1.0, fraction));
}
@ -1709,11 +1707,10 @@ 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 );
int width;
tp.GetTracksUsableArea(&width, NULL);
mousePosX = std::max(mousePosX, tp.GetLeftOffset());
mousePosX = std::min(mousePosX, tp.GetLeftOffset() + width - 1);
const auto &viewInfo = ViewInfo::Get( *mProject );
auto width = viewInfo.GetTracksUsableWidth();
mousePosX = std::max(mousePosX, viewInfo.GetLeftOffset());
mousePosX = std::min(mousePosX, viewInfo.GetLeftOffset() + width - 1);
mQuickPlayPosUnsnapped = mQuickPlayPos = Pos2Time(mousePosX);

View File

@ -413,8 +413,7 @@ 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 = trackPanel.GetLeftOffset();
int trackLeftEdge = viewInfo.GetLeftOffset();
// Time corresponding to mouse position
wxCoord xx;
@ -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;
@ -769,7 +768,7 @@ void ProjectWindow::Init()
auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
// Bottom scrollbar
hs->Add(trackPanel.GetLeftOffset() - 1, 0);
hs->Add(viewInfo.GetLeftOffset() - 1, 0);
hs->Add(mHsbar, 1, wxALIGN_BOTTOM);
hs->Add(mVsbar->GetSize().GetWidth(), 0);
bs->Add(hs.release(), 0, wxEXPAND | wxALIGN_LEFT);
@ -791,7 +790,7 @@ void ProjectWindow::Init()
trackPanel.SetFocus();
FixScrollbars();
ruler.SetLeftOffset(trackPanel.GetLeftOffset()); // bevel on AdornedRuler
ruler.SetLeftOffset(viewInfo.GetLeftOffset()); // bevel on AdornedRuler
//
// Set the Icon
@ -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);
}
@ -1144,8 +1142,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)
@ -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);
}
@ -1469,8 +1467,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);
@ -1632,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.
@ -1770,8 +1767,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)
{
@ -1816,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 =
@ -1844,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);
@ -1857,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
@ -1879,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;
@ -1899,7 +1894,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 +1904,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

@ -170,6 +170,8 @@ BEGIN_EVENT_TABLE(TrackPanel, CellularPanel)
EVT_TIMER(wxID_ANY, TrackPanel::OnTimer)
EVT_SIZE(TrackPanel::OnSize)
END_EVENT_TABLE()
/// Makes a cursor from an XPM, uses CursorId as a fallback.
@ -252,8 +254,7 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
mTracks(tracks),
mRuler(ruler),
mTrackArtist(nullptr),
mRefreshBacking(false),
vrulerSize(36,0)
mRefreshBacking(false)
#ifndef __WXGTK__ //Get rid if this pragma for gtk
#pragma warning( default: 4355 )
#endif
@ -344,24 +345,6 @@ void TrackPanel::UpdatePrefs()
Refresh();
}
wxSize TrackPanel::GetTracksUsableArea() const
{
auto size = GetSize();
return {
std::max( 0, size.GetWidth() - ( 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
@ -384,6 +367,14 @@ AudacityProject * TrackPanel::GetProject() const
return &static_cast<ProjectWindow*>( pWind )->GetProject();
}
void TrackPanel::OnSize( wxSizeEvent &evt )
{
evt.Skip();
const auto &size = evt.GetSize();
mViewInfo->SetWidth( size.GetWidth() );
mViewInfo->SetHeight( size.GetHeight() );
}
void TrackPanel::OnIdle(wxIdleEvent& event)
{
event.Skip();
@ -507,13 +498,6 @@ void TrackPanel::OnProjectSettingsChange( wxCommandEvent &event )
}
}
double TrackPanel::GetScreenEndTime() const
{
int width;
GetTracksUsableArea(&width, NULL);
return mViewInfo->PositionToTime(width, 0, true);
}
void TrackPanel::OnUndoReset( wxCommandEvent &event )
{
event.Skip();
@ -675,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()
@ -830,7 +814,8 @@ void TrackPanel::OnMouseEvent(wxMouseEvent & event)
double TrackPanel::GetMostRecentXPos()
{
return mViewInfo->PositionToTime(MostRecentXCoord(), GetLabelWidth());
return mViewInfo->PositionToTime(
MostRecentXCoord(), mViewInfo->GetLabelWidth());
}
void TrackPanel::RefreshTrack(Track *trk, bool refreshbacking)
@ -925,7 +910,7 @@ void TrackPanel::DrawTracks(wxDC * dc)
return (pt && pt->GetSolo());
} );
mTrackArtist->leftOffset = GetLeftOffset();
mTrackArtist->leftOffset = mViewInfo->GetLeftOffset();
mTrackArtist->drawEnvelope = envelopeFlag;
mTrackArtist->bigPoints = bigPointsFlag;
mTrackArtist->drawSliders = sliderFlag;
@ -999,11 +984,11 @@ void TrackPanel::DrawEverythingElse(TrackPanelDrawingContext &context,
trackRect.y = view.GetY() - mViewInfo->vpos + kTopMargin;
trackRect.height = view.GetHeight();
if (region.Contains(
0, trackRect.y, GetLeftOffset(), trackRect.height)) {
0, trackRect.y, mViewInfo->GetLeftOffset(), trackRect.height)) {
wxRect rect{
mViewInfo->GetVRulerOffset(),
trackRect.y,
GetVRulerWidth() + 1,
mViewInfo->GetVRulerWidth() + 1,
trackRect.height - kSeparatorThickness
};
TrackArt::DrawVRuler(context, channel, rect, bSelected);
@ -1058,7 +1043,7 @@ void TrackPanel::DrawOutside
// Now exclude the resizer below
rect.height -= kSeparatorThickness;
int labelw = GetLabelWidth();
int labelw = mViewInfo->GetLabelWidth();
int vrul = mViewInfo->GetVRulerOffset();
TrackInfo::DrawBackground( dc, rect, t->GetSelected(), vrul );
@ -1068,7 +1053,7 @@ void TrackPanel::DrawOutside
//if (t->IsSyncLockSelected()) {
// wxRect tileFill = rect;
// tileFill.x = mViewInfo->GetVRulerOffset();
// tileFill.width = GetVRulerWidth();
// tileFill.width = mViewInfo->GetVRulerWidth();
// TrackArt::DrawSyncLockTiles(dc, tileFill);
//}
@ -1259,7 +1244,7 @@ void TrackPanel::UpdateTrackVRuler(const Track *t)
wxRect rect(mViewInfo->GetVRulerOffset(),
kTopMargin,
GetVRulerWidth(),
mViewInfo->GetVRulerWidth(),
0);
@ -1278,9 +1263,10 @@ void TrackPanel::UpdateVRulerSize()
for (auto t : trackRange)
s.IncTo(t->vrulerSize);
if (vrulerSize != s) {
vrulerSize = s;
mRuler->SetLeftOffset(GetLeftOffset()); // bevel on AdornedRuler
if (mViewInfo->GetVRulerWidth() != s.GetWidth()) {
mViewInfo->SetVRulerWidth( s.GetWidth() );
mRuler->SetLeftOffset(
mViewInfo->GetLeftOffset()); // bevel on AdornedRuler
mRuler->Refresh();
}
}
@ -1290,8 +1276,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)
@ -1304,7 +1289,7 @@ void TrackPanel::ScrollIntoView(double pos)
void TrackPanel::ScrollIntoView(int x)
{
ScrollIntoView(mViewInfo->PositionToTime(x, GetLeftOffset()));
ScrollIntoView(mViewInfo->PositionToTime(x, mViewInfo->GetLeftOffset()));
}
void TrackPanel::OnTrackMenu(Track *t)
@ -1560,7 +1545,8 @@ struct Subgroup final : TrackPanelGroup {
explicit Subgroup( TrackPanel &panel ) : mPanel{ panel } {}
Subdivision Children( const wxRect &rect ) override
{
wxCoord yy = -mPanel.GetViewInfo()->vpos;
const auto &viewInfo = *mPanel.GetViewInfo();
wxCoord yy = -viewInfo.vpos;
Refinement refinement;
auto &tracks = *mPanel.GetTracks();
@ -1576,7 +1562,7 @@ struct Subgroup final : TrackPanelGroup {
}
refinement.emplace_back( yy,
std::make_shared< ResizingChannelGroup >(
leader->SharedPointer(), mPanel.GetLeftOffset() )
leader->SharedPointer(), viewInfo.GetLeftOffset() )
);
yy += height;
}
@ -1628,16 +1614,6 @@ wxRect TrackPanel::FindTrackRect( const Track * target )
} );
}
int TrackPanel::GetVRulerWidth() const
{
return vrulerSize.x;
}
int TrackPanel::GetLabelWidth() const
{
return mViewInfo->GetVRulerOffset() + GetVRulerWidth();
}
/// Displays the bounds of the selection in the status bar.
void TrackPanel::DisplaySelection()
{
@ -1755,7 +1731,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

@ -96,20 +96,13 @@ class AUDACITY_DLL_API TrackPanel final
double GetMostRecentXPos();
void OnSize( wxSizeEvent & );
void OnIdle(wxIdleEvent & event);
void OnTimer(wxTimerEvent& event);
void OnODTask(wxCommandEvent &event);
void OnProjectSettingsChange(wxCommandEvent &event);
void OnTrackFocusChange( wxCommandEvent &event );
int GetLeftOffset() const { return GetLabelWidth() + 1;}
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
@ -141,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();
@ -172,11 +161,7 @@ protected:
// area into cells
std::shared_ptr<TrackPanelNode> Root() override;
int GetVRulerWidth() const;
public:
int GetLabelWidth() const;
// JKC Nov-2011: These four functions only used from within a dll such as mod-track-panel
// They work around some messy problems with constructors.
const TrackList * GetTracks() const { return mTracks.get(); }
@ -271,9 +256,6 @@ protected:
SelectedRegion mLastDrawnSelectedRegion {};
public:
wxSize vrulerSize;
protected:
std::shared_ptr<TrackPanelCell> mpBackground;

View File

@ -21,20 +21,14 @@
// See big pictorial comment in TrackPanel.cpp for explanation of these numbers
enum : int {
kLeftInset = 4,
kRightInset = kLeftInset,
// constants related to y coordinates in the track panel
kTopInset = 4,
kShadowThickness = 1,
kBorderThickness = 1,
kTopMargin = kTopInset + kBorderThickness,
kBottomMargin = kShadowThickness + kBorderThickness,
kLeftMargin = kLeftInset + kBorderThickness,
kRightMargin = kRightInset + kShadowThickness + kBorderThickness,
kSeparatorThickness = kBottomMargin + kTopMargin,
};
enum : int {
kTrackInfoWidth = 100 - kLeftMargin,
kTrackInfoBtnSize = 18, // widely used dimension, usually height
kTrackInfoSliderHeight = 25,
kTrackInfoSliderWidth = 84,
@ -103,7 +97,8 @@ public:
ViewInfo(double start, double screenDuration, double pixelsPerSecond);
int GetVRulerOffset() const { return kTrackInfoWidth + kLeftMargin; }
int GetHeight() const { return mHeight; }
void SetHeight( int height ) { mHeight = height; }
static int UpdateScrollPrefsID();
void UpdatePrefs() override;
@ -157,6 +152,9 @@ public:
// Receive track panel timer notifications
void OnTimer(wxCommandEvent &event);
private:
int mHeight{ 0 };
};
#endif

View File

@ -22,6 +22,20 @@
class AudacityProject;
// See big pictorial comment in TrackPanel.cpp for explanation of these numbers
enum : int {
// Constants related to x coordinates in the track panel
kBorderThickness = 1,
kShadowThickness = 1,
kLeftInset = 4,
kRightInset = kLeftInset,
kLeftMargin = kLeftInset + kBorderThickness,
kRightMargin = kRightInset + kShadowThickness + kBorderThickness,
kTrackInfoWidth = 100 - kLeftMargin,
};
// The subset of ViewInfo information (other than selection)
// that is sufficient for purposes of TrackArtist,
// and for computing conversions between track times and pixel positions.
@ -78,6 +92,29 @@ public:
return PositionToTime(offset + TimeToPosition(time, ignoreFisheye), ignoreFisheye);
}
int GetWidth() const { return mWidth; }
void SetWidth( int width ) { mWidth = width; }
int GetVRulerWidth() const { return mVRulerWidth; }
void SetVRulerWidth( int width ) { mVRulerWidth = width; }
int GetVRulerOffset() const { return kTrackInfoWidth + kLeftMargin; }
int GetLabelWidth() const { return GetVRulerOffset() + GetVRulerWidth(); }
int GetLeftOffset() const { return GetLabelWidth() + 1;}
int GetTracksUsableWidth() const
{
return
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;
@ -137,6 +174,9 @@ public:
// Exclusive:
wxInt64 GetFisheyeRightBoundary(wxInt64 WXUNUSED(origin = 0)) const
{return 0;} // stub
int mWidth{ 0 };
int mVRulerWidth{ 36 };
};
#endif

View File

@ -761,7 +761,7 @@ void GetInfoCommand::ExploreTrackPanel( const CommandContext &context,
R.width -= kLeftInset * 2;
R.height -= kTopInset;
int labelw = pTP->GetLabelWidth();
int labelw = viewInfo.GetLabelWidth();
//int vrul = viewInfo.GetVRulerOffset();
bool bIsWave = true;
//mTrackInfo.DrawBackground(dc, R, t->GetSelected(), bIsWave, labelw, vrul);
@ -780,7 +780,7 @@ void GetInfoCommand::ExploreTrackPanel( const CommandContext &context,
wxRect R = trackRect;
R.x += viewInfo.GetVRulerOffset();
R.y += kTopMargin;
R.width = tp.GetVRulerWidth();
R.width = viewInfo.GetVRulerWidth();
R.height -= (kTopMargin + kBottomMargin);
R.SetPosition( R.GetPosition() + P );

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

@ -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
@ -230,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() );
@ -308,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)
@ -323,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

@ -2045,7 +2045,7 @@ int LabelTrackView::DialogForLabelName(
wxPoint position = trackPanel.FindTrackRect(trackPanel.GetFocusedTrack()).GetBottomLeft();
// The start of the text in the text box will be roughly in line with the label's position
// if it's a point label, or the start of its region if it's a region label.
position.x += trackPanel.GetLabelWidth()
position.x += viewInfo.GetLabelWidth()
+ std::max(0, static_cast<int>(viewInfo.TimeToPosition(region.t0())))
-40;
position.y += 2; // just below the bottom of the track

View File

@ -54,15 +54,16 @@ unsigned EditCursorOverlay::SequenceNumber() const
std::pair<wxRect, bool> EditCursorOverlay::DoGetRectangle(wxSize size)
{
const auto &selection = ViewInfo::Get( *mProject ).selectedRegion;
const auto &viewInfo = ViewInfo::Get( *mProject );
const auto &selection = viewInfo.selectedRegion;
if (!selection.isPoint()) {
mCursorTime = -1.0;
mNewCursorX = -1;
}
else {
mCursorTime = selection.t0();
mNewCursorX = ViewInfo::Get( *mProject ).TimeToPosition(
mCursorTime, TrackPanel::Get( *mProject ).GetLeftOffset());
mNewCursorX = viewInfo.TimeToPosition(
mCursorTime, viewInfo.GetLeftOffset());
}
// Excessive height in case of the ruler, but it matters little.
@ -89,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,9 +148,8 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
ruler.AddOverlay( mPartner );
}
auto &trackPanel = TrackPanel::Get( *mProject );
int width;
trackPanel.GetTracksUsableArea(&width, nullptr);
const auto &viewInfo = ViewInfo::Get( *mProject );
auto width = viewInfo.GetTracksUsableWidth();
if (!ProjectAudioIO::Get( *mProject ).IsAudioActive()) {
mNewIndicatorX = -1;
@ -158,15 +157,13 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
const auto &scrubber = Scrubber::Get( *mProject );
if (scrubber.HasMark()) {
auto position = scrubber.GetScrubStartPosition();
const auto offset = trackPanel.GetLeftOffset();
if(position >= trackPanel.GetLeftOffset() &&
const auto offset = viewInfo.GetLeftOffset();
if(position >= viewInfo.GetLeftOffset() &&
position < offset + width)
mNewIndicatorX = position;
}
}
else {
const auto &viewInfo = ViewInfo::Get( *mProject );
// Calculate the horizontal position of the indicator
const double playPos = viewInfo.mRecentStreamTime;
@ -178,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();
@ -215,7 +211,7 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
onScreen = playPos >= 0.0 &&
between_incexc(viewInfo.h,
playPos,
trackPanel.GetScreenEndTime());
viewInfo.GetScreenEndTime());
}
}
@ -225,7 +221,8 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
window.TP_RedrawScrollbars();
if (onScreen)
mNewIndicatorX = viewInfo.TimeToPosition(playPos, trackPanel.GetLeftOffset());
mNewIndicatorX =
viewInfo.TimeToPosition(playPos, viewInfo.GetLeftOffset());
else
mNewIndicatorX = -1;

View File

@ -353,10 +353,9 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
wxCoord position = xx;
if (abs(mScrubStartPosition - position) >= SCRUBBING_PIXEL_TOLERANCE) {
auto &viewInfo = ViewInfo::Get( *mProject );
auto &trackPanel = TrackPanel::Get( *mProject );
auto &ctb = ControlToolBar::Get( *mProject );
double maxTime = TrackList::Get( *mProject ).GetEndTime();
const int leftOffset = trackPanel.GetLeftOffset();
const int leftOffset = viewInfo.GetLeftOffset();
double time0 = std::min(maxTime,
viewInfo.PositionToTime(mScrubStartPosition, leftOffset)
);
@ -375,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;
@ -605,15 +604,14 @@ void Scrubber::ContinueScrubbingPoll()
else
#endif
{
const auto origin = trackPanel.GetLeftOffset();
const auto origin = viewInfo.GetLeftOffset();
auto xx = position.x;
if (!seek && !mSmoothScrollingScrub) {
// If mouse is out-of-bounds, so that we scrub at maximum speed
// 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;
@ -822,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);
}
@ -1007,6 +1005,7 @@ void ScrubbingOverlay::OnTimer(wxCommandEvent &event)
}
else {
TrackPanel &trackPanel = TrackPanel::Get( *mProject );
auto &viewInfo = ViewInfo::Get( *mProject );
int panelWidth, panelHeight;
trackPanel.GetSize(&panelWidth, &panelHeight);
@ -1021,7 +1020,7 @@ void ScrubbingOverlay::OnTimer(wxCommandEvent &event)
scrubber.IsScrollScrubbing()
? scrubber.FindScrubSpeed( seeking,
ViewInfo::Get( *mProject )
.PositionToTime(position.x, trackPanel.GetLeftOffset()))
.PositionToTime(position.x, viewInfo.GetLeftOffset()))
: maxScrubSpeed;
const wxChar *format =
@ -1073,12 +1072,12 @@ void Scrubber::DoScrub(bool seek)
const bool scroll = ShouldScrubPinned();
if (!wasScrubbing) {
auto &tp = TrackPanel::Get( *mProject );
const auto &viewInfo = ViewInfo::Get( *mProject );
wxCoord xx = tp.ScreenToClient(::wxGetMouseState().GetPosition()).x;
// Limit x
int width;
tp.GetTracksUsableArea(&width, nullptr);
const auto offset = tp.GetLeftOffset();
auto width = viewInfo.GetTracksUsableWidth();
const auto offset = viewInfo.GetLeftOffset();
xx = (std::max(offset, std::min(offset + width - 1, xx)));
MarkScrubStart(xx, scroll, seek);