mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-01 16:19:43 +02:00
Correct the allocation of track panel height for affordances...
... with some reinterpretation of what it means to "set the height" of a track. Changing height allocation for a reduced separator between panels may also be done, but that logic should also be localized in TrackPanel.cpp.
This commit is contained in:
parent
fba2ef009e
commit
5f7f180a6a
@ -870,6 +870,52 @@ std::shared_ptr< TrackPanelCell > TrackPanel::GetBackgroundCell()
|
|||||||
return mpBackground;
|
return mpBackground;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::vector<int> FindAdjustedChannelHeights( Track &t )
|
||||||
|
{
|
||||||
|
auto channels = TrackList::Channels(&t);
|
||||||
|
wxASSERT(!channels.empty());
|
||||||
|
|
||||||
|
// Collect heights, and count affordances
|
||||||
|
int nAffordances = 0;
|
||||||
|
int totalHeight = 0;
|
||||||
|
std::vector<int> oldHeights;
|
||||||
|
for (auto channel : channels) {
|
||||||
|
auto &view = TrackView::Get( *channel );
|
||||||
|
const auto height = view.GetHeight();
|
||||||
|
totalHeight += height;
|
||||||
|
oldHeights.push_back( height );
|
||||||
|
if (view.GetAffordanceControls())
|
||||||
|
++nAffordances;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate results
|
||||||
|
auto nChannels = static_cast<int>(oldHeights.size());
|
||||||
|
std::vector<int> results;
|
||||||
|
results.reserve(nChannels);
|
||||||
|
|
||||||
|
// Now reallocate the channel heights for the presence of affordances
|
||||||
|
// and separators
|
||||||
|
auto availableHeight = totalHeight
|
||||||
|
- nAffordances * kAffordancesAreaHeight
|
||||||
|
- (nChannels - 1) * kChannelSeparatorThickness
|
||||||
|
- kTrackSeparatorThickness;
|
||||||
|
int cumulativeOldHeight = 0;
|
||||||
|
int cumulativeNewHeight = 0;
|
||||||
|
for (const auto &oldHeight : oldHeights) {
|
||||||
|
// Preserve the porportions among the stored heights
|
||||||
|
cumulativeOldHeight += oldHeight;
|
||||||
|
const auto newHeight =
|
||||||
|
cumulativeOldHeight * availableHeight / totalHeight
|
||||||
|
- cumulativeNewHeight;
|
||||||
|
cumulativeNewHeight += newHeight;
|
||||||
|
results.push_back(newHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TrackPanel::UpdateVRulers()
|
void TrackPanel::UpdateVRulers()
|
||||||
{
|
{
|
||||||
for (auto t : GetTracks()->Any< WaveTrack >())
|
for (auto t : GetTracks()->Any< WaveTrack >())
|
||||||
@ -892,15 +938,17 @@ void TrackPanel::UpdateTrackVRuler(Track *t)
|
|||||||
if (!t)
|
if (!t)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto heights = FindAdjustedChannelHeights(*t);
|
||||||
|
|
||||||
wxRect rect(mViewInfo->GetVRulerOffset(),
|
wxRect rect(mViewInfo->GetVRulerOffset(),
|
||||||
0,
|
0,
|
||||||
mViewInfo->GetVRulerWidth(),
|
mViewInfo->GetVRulerWidth(),
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
auto pHeight = heights.begin();
|
||||||
for (auto channel : TrackList::Channels(t)) {
|
for (auto channel : TrackList::Channels(t)) {
|
||||||
auto &view = TrackView::Get( *channel );
|
auto &view = TrackView::Get( *channel );
|
||||||
const auto height = view.GetHeight() - (kTopMargin + kBottomMargin);
|
const auto height = *pHeight++;
|
||||||
rect.SetHeight( height );
|
rect.SetHeight( height );
|
||||||
const auto subViews = view.GetSubViews( rect );
|
const auto subViews = view.GetSubViews( rect );
|
||||||
if (subViews.empty())
|
if (subViews.empty())
|
||||||
@ -1078,7 +1126,11 @@ void DrawTrackName(
|
|||||||
// Tracks more than kTranslucentHeight will have maximum translucency for shields.
|
// Tracks more than kTranslucentHeight will have maximum translucency for shields.
|
||||||
const int kOpaqueHeight = 44;
|
const int kOpaqueHeight = 44;
|
||||||
const int kTranslucentHeight = 124;
|
const int kTranslucentHeight = 124;
|
||||||
|
|
||||||
|
// PRL: to do: reexamine this strange use of TrackView::GetHeight,
|
||||||
|
// ultimately to compute an opacity
|
||||||
int h = TrackView::Get( *t ).GetHeight();
|
int h = TrackView::Get( *t ).GetHeight();
|
||||||
|
|
||||||
// f codes the opacity as a number between 0.0 and 1.0
|
// f codes the opacity as a number between 0.0 and 1.0
|
||||||
float f = wxClip((h-kOpaqueHeight)/(float)(kTranslucentHeight-kOpaqueHeight),0.0,1.0);
|
float f = wxClip((h-kOpaqueHeight)/(float)(kTranslucentHeight-kOpaqueHeight),0.0,1.0);
|
||||||
// kOpaque is the shield's alpha for tracks that are not tall
|
// kOpaque is the shield's alpha for tracks that are not tall
|
||||||
@ -1334,7 +1386,7 @@ struct HorizontalGroup final : TrackPanelGroup {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// optional affordance area, and n channels with vertical rulers,
|
// optional affordance areas, and n channels with vertical rulers,
|
||||||
// alternating with n - 1 resizers;
|
// alternating with n - 1 resizers;
|
||||||
// each channel-ruler pair might be divided into multiple views
|
// each channel-ruler pair might be divided into multiple views
|
||||||
struct ChannelGroup final : TrackPanelGroup {
|
struct ChannelGroup final : TrackPanelGroup {
|
||||||
@ -1348,7 +1400,9 @@ struct ChannelGroup final : TrackPanelGroup {
|
|||||||
const auto channels = TrackList::Channels( mpTrack.get() );
|
const auto channels = TrackList::Channels( mpTrack.get() );
|
||||||
const auto pLast = *channels.rbegin();
|
const auto pLast = *channels.rbegin();
|
||||||
wxCoord yy = rect.GetTop();
|
wxCoord yy = rect.GetTop();
|
||||||
for ( auto channel : channels )
|
auto heights = FindAdjustedChannelHeights(*mpTrack);
|
||||||
|
auto pHeight = heights.begin();
|
||||||
|
for ( auto channel : channels )
|
||||||
{
|
{
|
||||||
auto &view = TrackView::Get( *channel );
|
auto &view = TrackView::Get( *channel );
|
||||||
if (auto affordance = view.GetAffordanceControls())
|
if (auto affordance = view.GetAffordanceControls())
|
||||||
@ -1364,7 +1418,7 @@ struct ChannelGroup final : TrackPanelGroup {
|
|||||||
yy += kAffordancesAreaHeight;
|
yy += kAffordancesAreaHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto height = view.GetHeight();
|
auto height = *pHeight++;
|
||||||
rect.SetTop( yy );
|
rect.SetTop( yy );
|
||||||
rect.SetHeight( height - kChannelSeparatorThickness );
|
rect.SetHeight( height - kChannelSeparatorThickness );
|
||||||
refinement.emplace_back( yy,
|
refinement.emplace_back( yy,
|
||||||
@ -1391,10 +1445,12 @@ struct ChannelGroup final : TrackPanelGroup {
|
|||||||
const auto channels = TrackList::Channels(mpTrack.get());
|
const auto channels = TrackList::Channels(mpTrack.get());
|
||||||
const auto pLast = *channels.rbegin();
|
const auto pLast = *channels.rbegin();
|
||||||
wxCoord yy = rect.GetTop();
|
wxCoord yy = rect.GetTop();
|
||||||
|
auto heights = FindAdjustedChannelHeights(*mpTrack);
|
||||||
|
auto pHeight = heights.begin();
|
||||||
for (auto channel : channels)
|
for (auto channel : channels)
|
||||||
{
|
{
|
||||||
auto& view = TrackView::Get(*channel);
|
auto& view = TrackView::Get(*channel);
|
||||||
auto height = view.GetHeight();
|
auto height = *pHeight++;
|
||||||
if (auto affordance = view.GetAffordanceControls())
|
if (auto affordance = view.GetAffordanceControls())
|
||||||
{
|
{
|
||||||
height += kAffordancesAreaHeight;
|
height += kAffordancesAreaHeight;
|
||||||
@ -1551,9 +1607,6 @@ struct Subgroup final : TrackPanelGroup {
|
|||||||
for ( auto channel : TrackList::Channels( leader ) ) {
|
for ( auto channel : TrackList::Channels( leader ) ) {
|
||||||
auto &view = TrackView::Get( *channel );
|
auto &view = TrackView::Get( *channel );
|
||||||
height += view.GetHeight();
|
height += view.GetHeight();
|
||||||
|
|
||||||
if (view.GetAffordanceControls())
|
|
||||||
height += kAffordancesAreaHeight;
|
|
||||||
}
|
}
|
||||||
refinement.emplace_back( yy,
|
refinement.emplace_back( yy,
|
||||||
std::make_shared< ResizingChannelGroup >(
|
std::make_shared< ResizingChannelGroup >(
|
||||||
|
@ -53,15 +53,21 @@ public:
|
|||||||
int GetCumulativeHeightBefore() const { return mY; }
|
int GetCumulativeHeightBefore() const { return mY; }
|
||||||
|
|
||||||
//! @return height of the track when expanded
|
//! @return height of the track when expanded
|
||||||
|
/*! See other comments for GetHeight */
|
||||||
int GetExpandedHeight() const { return mHeight; }
|
int GetExpandedHeight() const { return mHeight; }
|
||||||
|
|
||||||
//! @return height of the track when collapsed
|
//! @return height of the track when collapsed
|
||||||
|
/*! See other comments for GetHeight */
|
||||||
virtual int GetMinimizedHeight() const = 0;
|
virtual int GetMinimizedHeight() const = 0;
|
||||||
|
|
||||||
//! @return height of the track as it now appears, expanded or collapsed
|
//! @return height of the track as it now appears, expanded or collapsed
|
||||||
/*!
|
/*!
|
||||||
Total "height" of channels of a track includes padding areas above and
|
Total "height" of channels of a track includes padding areas above and
|
||||||
below it.
|
below it, and is pixel-accurate for the channel group.
|
||||||
|
The "heights" of channels within a group determine the proportions of
|
||||||
|
heights of the track data shown -- but the actual total pixel heights
|
||||||
|
may differ when other fixed-height adornments and paddings are added,
|
||||||
|
according to other rules for allocation of height.
|
||||||
*/
|
*/
|
||||||
int GetHeight() const;
|
int GetHeight() const;
|
||||||
|
|
||||||
@ -70,6 +76,7 @@ public:
|
|||||||
|
|
||||||
/*! Sets height for expanded state.
|
/*! Sets height for expanded state.
|
||||||
Does not expand a track if it is now collapsed.
|
Does not expand a track if it is now collapsed.
|
||||||
|
See other comments for GetHeight
|
||||||
*/
|
*/
|
||||||
void SetExpandedHeight(int height);
|
void SetExpandedHeight(int height);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user