1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 00:20:06 +02:00

Redo layout tables as std::vector

This commit is contained in:
Paul Licameli 2017-06-13 13:34:12 -04:00
parent 063c6c236f
commit 5982dccd36
2 changed files with 43 additions and 35 deletions

View File

@ -5056,6 +5056,9 @@ struct TrackInfo::TCPLine {
namespace { namespace {
#define RANGE(array) (array), (array) + sizeof(array)/sizeof(*(array))
using TCPLines = std::vector< TrackInfo::TCPLine >;
enum : unsigned { enum : unsigned {
// The sequence is not significant, just keep bits distinct // The sequence is not significant, just keep bits distinct
kItemBarButtons = 1 << 0, kItemBarButtons = 1 << 0,
@ -5107,12 +5110,12 @@ enum : unsigned {
#define COMMON_ITEMS \ #define COMMON_ITEMS \
TITLE_ITEMS TITLE_ITEMS
const TrackInfo::TCPLine commonTrackTCPLines[] = { const TrackInfo::TCPLine defaultCommonTrackTCPLines[] = {
COMMON_ITEMS COMMON_ITEMS
{ 0, 0, 0, nullptr }
}; };
TCPLines commonTrackTCPLines{ RANGE(defaultCommonTrackTCPLines) };
const TrackInfo::TCPLine waveTrackTCPLines[] = { const TrackInfo::TCPLine defaultWaveTrackTCPLines[] = {
COMMON_ITEMS COMMON_ITEMS
MUTE_SOLO_ITEMS(2) MUTE_SOLO_ITEMS(2)
{ kItemGain, kTrackInfoSliderHeight, kTrackInfoSliderExtra, { kItemGain, kTrackInfoSliderHeight, kTrackInfoSliderExtra,
@ -5120,10 +5123,10 @@ const TrackInfo::TCPLine waveTrackTCPLines[] = {
{ kItemPan, kTrackInfoSliderHeight, kTrackInfoSliderExtra, { kItemPan, kTrackInfoSliderHeight, kTrackInfoSliderExtra,
&TrackInfo::PanSliderDrawFunction }, &TrackInfo::PanSliderDrawFunction },
STATUS_ITEMS STATUS_ITEMS
{ 0, 0, 0, nullptr }
}; };
TCPLines waveTrackTCPLines{ RANGE(defaultWaveTrackTCPLines) };
const TrackInfo::TCPLine noteTrackTCPLines[] = { const TrackInfo::TCPLine defaultNoteTrackTCPLines[] = {
COMMON_ITEMS COMMON_ITEMS
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
MUTE_SOLO_ITEMS(0) MUTE_SOLO_ITEMS(0)
@ -5132,24 +5135,23 @@ const TrackInfo::TCPLine noteTrackTCPLines[] = {
{ kItemVelocity, kTrackInfoSliderHeight, kTrackInfoSliderExtra, { kItemVelocity, kTrackInfoSliderHeight, kTrackInfoSliderExtra,
&TrackInfo::VelocitySliderDrawFunction }, &TrackInfo::VelocitySliderDrawFunction },
#endif #endif
{ 0, 0, 0, nullptr }
}; };
TCPLines noteTrackTCPLines{ RANGE(defaultNoteTrackTCPLines) };
int totalTCPLines( const TrackInfo::TCPLine *pLines, bool omitLastExtra ) int totalTCPLines( const TCPLines &lines, bool omitLastExtra )
{ {
int total = 0; int total = 0;
int lastExtra = 0; int lastExtra = 0;
while ( pLines->items ) { for ( const auto line : lines ) {
lastExtra = pLines->extraSpace; lastExtra = line.extraSpace;
total += pLines->height + lastExtra; total += line.height + lastExtra;
++pLines;
} }
if (omitLastExtra) if (omitLastExtra)
total -= lastExtra; total -= lastExtra;
return total; return total;
} }
const TrackInfo::TCPLine *getTCPLines( const Track &track ) const TCPLines &getTCPLines( const Track &track )
{ {
#ifdef USE_MIDI #ifdef USE_MIDI
if ( track.GetKind() == Track::Note ) if ( track.GetKind() == Track::Note )
@ -5163,38 +5165,45 @@ const TrackInfo::TCPLine *getTCPLines( const Track &track )
} }
// return y value and height // return y value and height
std::pair< int, int > CalcItemY( const TrackInfo::TCPLine *pLines, unsigned iItem ) std::pair< int, int > CalcItemY( const TCPLines &lines, unsigned iItem )
{ {
int y = 0; int y = 0;
while ( pLines->items && auto pLines = lines.begin();
while ( pLines != lines.end() &&
0 == (pLines->items & iItem) ) { 0 == (pLines->items & iItem) ) {
y += pLines->height + pLines->extraSpace; y += pLines->height + pLines->extraSpace;
++pLines; ++pLines;
} }
return { y, pLines->height }; int height = 0;
if ( pLines != lines.end() )
height = pLines->height;
return { y, height };
} }
// Items for the bottom of the panel, listed bottom-upwards // Items for the bottom of the panel, listed bottom-upwards
// As also with the top items, the extra space is below the item // As also with the top items, the extra space is below the item
const TrackInfo::TCPLine commonTrackTCPBottomLines[] = { const TrackInfo::TCPLine defaultCommonTrackTCPBottomLines[] = {
// The '0' avoids impinging on bottom line of TCP // The '0' avoids impinging on bottom line of TCP
// Use -1 if you do want to do so. // Use -1 if you do want to do so.
{ kItemSyncLock | kItemMinimize, kTrackInfoBtnSize, 0, { kItemSyncLock | kItemMinimize, kTrackInfoBtnSize, 0,
&TrackInfo::MinimizeSyncLockDrawFunction }, &TrackInfo::MinimizeSyncLockDrawFunction },
{ 0, 0, 0, nullptr }
}; };
TCPLines commonTrackTCPBottomLines{ RANGE(defaultCommonTrackTCPBottomLines) };
// return y value and height // return y value and height
std::pair< int, int > CalcBottomItemY std::pair< int, int > CalcBottomItemY
( const TrackInfo::TCPLine *pLines, unsigned iItem, int height ) ( const TCPLines &lines, unsigned iItem, int height )
{ {
int y = height; int y = height;
while ( pLines->items && auto pLines = lines.begin();
while ( pLines != lines.end() &&
0 == (pLines->items & iItem) ) { 0 == (pLines->items & iItem) ) {
y -= pLines->height + pLines->extraSpace; y -= pLines->height + pLines->extraSpace;
++pLines; ++pLines;
} }
return { y - (pLines->height + pLines->extraSpace ), pLines->height }; if (pLines != lines.end())
y -= (pLines->height + pLines->extraSpace );
return { y, pLines->height };
} }
} }
@ -7284,37 +7293,35 @@ void TrackInfo::DrawItems
void TrackInfo::DrawItems void TrackInfo::DrawItems
( wxDC *dc, const wxRect &rect, const Track *pTrack, ( wxDC *dc, const wxRect &rect, const Track *pTrack,
const TCPLine topLines[], const TCPLine bottomLines[], const std::vector<TCPLine> &topLines, const std::vector<TCPLine> &bottomLines,
int mouseCapture, bool captured ) int mouseCapture, bool captured )
{ {
TrackInfo::SetTrackInfoFont(dc); TrackInfo::SetTrackInfoFont(dc);
dc->SetTextForeground(theTheme.Colour(clrTrackPanelText)); dc->SetTextForeground(theTheme.Colour(clrTrackPanelText));
{ {
const auto table = topLines;
int yy = 0; int yy = 0;
for ( auto line = table; line->items; ++line ) { for ( const auto &line : topLines ) {
wxRect itemRect{ wxRect itemRect{
rect.x, rect.y + yy, rect.x, rect.y + yy,
rect.width, line->height rect.width, line.height
}; };
if ( !TrackInfo::HideTopItem( rect, itemRect ) && if ( !TrackInfo::HideTopItem( rect, itemRect ) &&
line->drawFunction ) line.drawFunction )
line->drawFunction( dc, itemRect, pTrack, mouseCapture, captured ); line.drawFunction( dc, itemRect, pTrack, mouseCapture, captured );
yy += line->height + line->extraSpace; yy += line.height + line.extraSpace;
} }
} }
{ {
const auto table = bottomLines;
int yy = rect.height; int yy = rect.height;
for ( auto line = table; line->items; ++line ) { for ( const auto &line : bottomLines ) {
yy -= line->height + line->extraSpace; yy -= line.height + line.extraSpace;
if ( line->drawFunction ) { if ( line.drawFunction ) {
wxRect itemRect{ wxRect itemRect{
rect.x, rect.y + yy, rect.x, rect.y + yy,
rect.width, line->height rect.width, line.height
}; };
line->drawFunction( dc, itemRect, pTrack, mouseCapture, captured ); line.drawFunction( dc, itemRect, pTrack, mouseCapture, captured );
} }
} }
} }
@ -9645,7 +9652,7 @@ void TrackInfo::DrawMinimize(wxDC * dc, const wxRect & rect, Track * t, bool dow
} }
namespace { namespace {
unsigned DefaultTrackHeight( const TrackInfo::TCPLine topLines[] ) unsigned DefaultTrackHeight( const TCPLines &topLines )
{ {
int needed = int needed =
kTopMargin + kBottomMargin + kTopMargin + kBottomMargin +

View File

@ -92,7 +92,8 @@ public:
static void DrawItems static void DrawItems
( wxDC *dc, const wxRect &rect, const Track *pTrack, ( wxDC *dc, const wxRect &rect, const Track *pTrack,
const TCPLine topLines[], const TCPLine bottomLines[], const std::vector<TCPLine> &topLines,
const std::vector<TCPLine> &bottomLines,
int mouseCapture, bool captured ); int mouseCapture, bool captured );
static void CloseTitleDrawFunction static void CloseTitleDrawFunction