Move height calculation utilities to class TrackView

This commit is contained in:
Paul Licameli 2019-06-22 08:39:20 -04:00
parent a6e2ca0aa8
commit 4339c0df68
10 changed files with 46 additions and 43 deletions

View File

@ -72,7 +72,8 @@ bool AudacityPrintout::OnPrintPage(int WXUNUSED(page))
dc->GetSize(&width, &height);
int rulerScreenHeight = 40;
int screenTotalHeight = mTracks->GetHeight() + rulerScreenHeight;
int screenTotalHeight =
TrackView::GetTotalHeight( *mTracks ) + rulerScreenHeight;
double scale = height / (double)screenTotalHeight;

View File

@ -29,6 +29,7 @@ Paul Licameli split from AudacityProject.cpp
#include "toolbars/ControlToolBar.h"
#include "toolbars/ToolManager.h"
#include "tracks/ui/Scrubbing.h"
#include "tracks/ui/TrackView.h"
#include "widgets/wxPanelWrapper.h"
#include "widgets/WindowAccessible.h"
@ -1137,7 +1138,7 @@ void ProjectWindow::FixScrollbars()
bool refresh = false;
bool rescroll = false;
int totalHeight = (tracks.GetHeight() + 32);
int totalHeight = TrackView::GetTotalHeight( tracks ) + 32;
int panelWidth, panelHeight;
trackPanel.GetTracksUsableArea(&panelWidth, &panelHeight);

View File

@ -842,15 +842,6 @@ Track *TrackList::GetPrev(Track * t, bool linked) const
return nullptr;
}
/// For mono track height of track
/// For stereo track combined height of both channels.
int TrackList::GetGroupHeight(const Track * t) const
{
const auto GetHeight = []( const Track *track )
{ return TrackView::Get( *track ).GetHeight(); };
return Channels(t).sum( GetHeight );
}
bool TrackList::CanMoveUp(Track * t) const
{
return GetPrev(t, true) != NULL;
@ -970,19 +961,6 @@ size_t TrackList::size() const
return cnt;
}
int TrackList::GetHeight() const
{
int height = 0;
if (!empty()) {
auto track = getPrev( getEnd() ).first->get();
auto &view = TrackView::Get( *track );
height = view.GetY() + view.GetHeight();
}
return height;
}
namespace {
// Abstract the common pattern of the following three member functions
inline double Accumulate

View File

@ -1360,8 +1360,6 @@ public:
/// Make the list empty
void Clear(bool sendEvent = true);
int GetGroupHeight(const Track * t) const;
bool CanMoveUp(Track * t) const;
bool CanMoveDown(Track * t) const;
@ -1393,7 +1391,6 @@ public:
double GetEndTime() const;
double GetMinOffset() const;
int GetHeight() const;
#if LEGACY_PROJECT_FILE_SUPPORT
// File I/O

View File

@ -832,10 +832,8 @@ void TrackPanel::RefreshTrack(Track *trk, bool refreshbacking)
trk = *GetTracks()->FindLeader(trk);
auto &view = TrackView::Get( *trk );
const auto GetHeight = []( const Track *track )
{ return TrackView::Get( *track ).GetHeight(); };
auto height =
TrackList::Channels(trk).sum( GetHeight )
TrackList::Channels(trk).sum( TrackView::GetTrackHeight )
- kTopInset - kShadowThickness;
// subtract insets and shadows from the rectangle, but not border
@ -1327,9 +1325,7 @@ void TrackPanel::EnsureVisible(Track * t)
trackTop += trackHeight;
auto channels = TrackList::Channels(it);
const auto GetHeight = []( const Track *track )
{ return TrackView::Get( *track ).GetHeight(); };
trackHeight = channels.sum( GetHeight );
trackHeight = channels.sum( TrackView::GetTrackHeight );
//We have found the track we want to ensure is visible.
if (channels.contains(t)) {
@ -1363,15 +1359,13 @@ void TrackPanel::VerticalScroll( float fracPosition){
int trackHeight = 0;
auto tracks = GetTracks();
const auto GetHeight =
[&]( const Track *t ){ return tracks->GetGroupHeight(t); };
auto range = tracks->Leaders();
if (!range.empty()) {
trackHeight = GetHeight( *range.rbegin() );
trackHeight = TrackView::GetChannelGroupHeight( *range.rbegin() );
--range.second;
}
trackTop = range.sum( GetHeight );
trackTop = range.sum( TrackView::GetChannelGroupHeight );
int delta;

View File

@ -497,7 +497,7 @@ bool GetInfoCommand::SendTracks(const CommandContext & context)
context.AddBool( (trk == fTrack), "focused");
context.AddBool( trk->GetSelected(), "selected" );
//JKC: Possibly add later...
//context.AddItem( GetTrackView::Get( *trk ).GetHeight(), "height" );
//context.AddItem( TrackView::Get( *trk ).GetHeight(), "height" );
trk->TypeSwitch( [&] (const WaveTrack* t ) {
float vzmin, vzmax;
t->GetDisplayBounds(&vzmin, &vzmax);

View File

@ -206,10 +206,9 @@ void DoZoomFitV(AudacityProject &project)
height -= 28;
// The height of minimized and non-audio tracks cannot be apportioned
const auto GetHeight = []( const Track *track )
{ return TrackView::Get( *track ).GetHeight(); };
height -=
tracks.Any().sum( GetHeight ) - range.sum( GetHeight );
tracks.Any().sum( TrackView::GetTrackHeight )
- range.sum( TrackView::GetTrackHeight );
// Give each resized track the average of the remaining height
height = height / count;

View File

@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../Audacity.h"
#include "TrackSelectHandle.h"
#include "TrackView.h"
#include "../../Menus.h"
#include "../../Project.h"
#include "../../ProjectAudioIO.h"
@ -219,7 +220,7 @@ void TrackSelectHandle::CalculateRearrangingThresholds(const wxMouseEvent & even
if (tracks.CanMoveUp(mpTrack.get()))
mMoveUpThreshold =
event.m_y -
tracks.GetGroupHeight(
TrackView::GetChannelGroupHeight(
* -- tracks.FindLeader( mpTrack.get() ) );
else
mMoveUpThreshold = INT_MIN;
@ -227,7 +228,7 @@ void TrackSelectHandle::CalculateRearrangingThresholds(const wxMouseEvent & even
if (tracks.CanMoveDown(mpTrack.get()))
mMoveDownThreshold =
event.m_y +
tracks.GetGroupHeight(
TrackView::GetChannelGroupHeight(
* ++ tracks.FindLeader( mpTrack.get() ) );
else
mMoveDownThreshold = INT_MAX;

View File

@ -18,6 +18,29 @@ TrackView::~TrackView()
{
}
int TrackView::GetTrackHeight( const Track *pTrack )
{
return pTrack ? Get( *pTrack ).GetHeight() : 0;
}
int TrackView::GetChannelGroupHeight( const Track *pTrack )
{
return pTrack ? TrackList::Channels( pTrack ).sum( GetTrackHeight ) : 0;
}
int TrackView::GetCumulativeHeight( const Track *pTrack )
{
if ( !pTrack )
return 0;
auto &view = Get( *pTrack );
return view.GetY() + view.GetHeight();
}
int TrackView::GetTotalHeight( const TrackList &list )
{
return GetCumulativeHeight( *list.Any().rbegin() );
}
void TrackView::Copy( const TrackView &other )
{
mMinimized = other.mMinimized;

View File

@ -15,6 +15,7 @@ Paul Licameli split from class Track
#include "CommonTrackPanelCell.h" // to inherit
class Track;
class TrackList;
class TrackVRulerControls;
class TrackPanelResizerCell;
@ -32,6 +33,14 @@ public:
: CommonTrackCell{ pTrack } {}
virtual ~TrackView() = 0;
// some static conveniences, useful for summation over track iterator
// ranges
static int GetTrackHeight( const Track *pTrack );
static int GetChannelGroupHeight( const Track *pTrack );
// Total height of the given track and all previous ones (constant time!)
static int GetCumulativeHeight( const Track *pTrack );
static int GetTotalHeight( const TrackList &list );
// Copy view state, for undo/redo purposes
virtual void Copy( const TrackView &other );