mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
Bug 1965 - Enh: Track name overlay display for all track types
OK now that we have translucent name background. Includes logic to move first label down to avoid the name (if it is shown).
This commit is contained in:
parent
81dd2befab
commit
9ba023d607
@ -477,7 +477,10 @@ void LabelTrack::ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const
|
||||
// allowed to be obscured by the text].
|
||||
const int xExtra= (3 * mIconWidth)/2;
|
||||
|
||||
bool bAvoidName = false;
|
||||
const int nRows = wxMin((r.height / yRowHeight) + 1, MAX_NUM_ROWS);
|
||||
if( nRows > 2 )
|
||||
bAvoidName = gPrefs->ReadBool(wxT("/GUI/ShowTrackNameInWaveform"), false);
|
||||
// Initially none of the rows have been used.
|
||||
// So set a value that is less than any valid value.
|
||||
{
|
||||
@ -502,6 +505,7 @@ void LabelTrack::ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const
|
||||
// (This is to encourage merging of adjacent label boundaries).
|
||||
while( (iRow<nRowsUsed) && (xUsed[iRow] != x ))
|
||||
iRow++;
|
||||
|
||||
// IF we didn't find one THEN
|
||||
// find any row that can take a span starting at x.
|
||||
if( iRow >= nRowsUsed )
|
||||
@ -513,6 +517,21 @@ void LabelTrack::ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const
|
||||
// IF we found such a row THEN record a valid position.
|
||||
if( iRow<nRows )
|
||||
{
|
||||
// Logic to ameliorate case where first label is under the
|
||||
// (on track) track name. For later labels it does not matter
|
||||
// as we can scroll left or right and/or zoom.
|
||||
// A possible alternative idea would be to (instead) increase the
|
||||
// translucency of the track name, when the mouse is inside it.
|
||||
if( (i==0 ) && (iRow==0) && bAvoidName ){
|
||||
// reserve some space in first row.
|
||||
// reserve max of 200px or t1, or text box right edge.
|
||||
const int x2 = zoomInfo.TimeToPosition(0.0, r.x) + 200;
|
||||
xUsed[iRow]=x+labelStruct.width+xExtra;
|
||||
if( xUsed[iRow] < x1 ) xUsed[iRow]=x1;
|
||||
if( xUsed[iRow] < x2 ) xUsed[iRow]=x2;
|
||||
iRow=1;
|
||||
}
|
||||
|
||||
// Possibly update the number of rows actually used.
|
||||
if( iRow >= nRowsUsed )
|
||||
nRowsUsed=iRow+1;
|
||||
|
@ -289,11 +289,53 @@ void TrackArt::DrawTracks(TrackPanelDrawingContext &context,
|
||||
}
|
||||
}
|
||||
|
||||
// Draws the track name on the track, if it is needed.
|
||||
void TrackArt::DrawTrackName( TrackPanelDrawingContext &context, const Track * t, const wxRect & rect )
|
||||
{
|
||||
auto name = t->GetName();
|
||||
if( name.IsEmpty())
|
||||
return;
|
||||
if( !t->IsLeader())
|
||||
return;
|
||||
auto &dc = context.dc;
|
||||
wxBrush Brush;
|
||||
wxCoord x,y;
|
||||
wxFont labelFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
||||
dc.SetFont(labelFont);
|
||||
dc.GetTextExtent( t->GetName(), &x, &y );
|
||||
|
||||
#ifdef __WXMAC__
|
||||
// Mac dc is a graphics dc already.
|
||||
// Shield's background is translucent, alpha=140
|
||||
AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, 140 );
|
||||
dc.DrawRoundedRectangle( rect.x+7, rect.y+1, x+16, y+4, 8.0 );
|
||||
#else
|
||||
// This little dance with wxImage in order to draw to a graphic dc
|
||||
// which we can then paste as a translucent bitmap onto the real dc.
|
||||
wxImage image( x+18, y+6 );
|
||||
image.InitAlpha();
|
||||
unsigned char *alpha=image.GetAlpha();
|
||||
memset(alpha, wxIMAGE_ALPHA_TRANSPARENT, image.GetWidth()*image.GetHeight());
|
||||
|
||||
wxGraphicsContext &gc=*wxGraphicsContext::Create(image);
|
||||
// Shield's background is translucent, alpha=140. This is to a gc, not a dc.
|
||||
AColor::UseThemeColour( &gc, clrTrackInfoSelected, clrTrackPanelText, 140 );
|
||||
// Draw at 1,1, not at 0,0 to avoid clipping of the antialiasing.
|
||||
gc.DrawRoundedRectangle( 1, 1, x+16, y+4, 8.0 );
|
||||
// delete the gc so as to free and so update the wxImage.
|
||||
delete &gc;
|
||||
wxBitmap bitmap( image );
|
||||
dc.DrawBitmap( bitmap, rect.x+6, rect.y);
|
||||
#endif
|
||||
dc.SetTextForeground(theTheme.Colour( clrTrackPanelText ));
|
||||
dc.DrawText (t->GetName(), rect.x+15, rect.y+3); // move right 15 pixels to avoid overwriting <- symbol
|
||||
}
|
||||
|
||||
void TrackArt::DrawTrack(TrackPanelDrawingContext &context,
|
||||
const Track * t,
|
||||
const wxRect & rect)
|
||||
{
|
||||
auto &dc = context.dc;
|
||||
const auto artist = TrackArtist::Get( context );
|
||||
|
||||
t->TypeSwitch(
|
||||
[&](const WaveTrack *wt) {
|
||||
@ -301,7 +343,6 @@ void TrackArt::DrawTrack(TrackPanelDrawingContext &context,
|
||||
clip->ClearDisplayRect();
|
||||
}
|
||||
|
||||
const auto artist = TrackArtist::Get( context );
|
||||
const auto hasSolo = artist->hasSolo;
|
||||
bool muted = (hasSolo || wt->GetMute()) &&
|
||||
!wt->GetSolo();
|
||||
@ -325,51 +366,12 @@ void TrackArt::DrawTrack(TrackPanelDrawingContext &context,
|
||||
#if defined(__WXMAC__)
|
||||
dc.GetGraphicsContext()->SetAntialiasMode(aamode);
|
||||
#endif
|
||||
|
||||
const auto bShowTrackNameInWaveform =
|
||||
artist->mbShowTrackNameInWaveform;
|
||||
if (bShowTrackNameInWaveform &&
|
||||
wt->IsLeader() &&
|
||||
// Exclude empty name.
|
||||
!wt->GetName().empty()) {
|
||||
wxBrush Brush;
|
||||
wxCoord x,y;
|
||||
wxFont labelFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
||||
dc.SetFont(labelFont);
|
||||
dc.GetTextExtent( wt->GetName(), &x, &y );
|
||||
|
||||
#ifdef __WXMAC__
|
||||
// Mac dc is a graphics dc already.
|
||||
// Shield's background is translucent, alpha=180
|
||||
AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, 180 );
|
||||
dc.DrawRoundedRectangle( rect.x+7, rect.y+1, x+16, y+4, 8.0 );
|
||||
#else
|
||||
// This little dance with wxImage in order to draw to a graphic dc
|
||||
// which we can then paste as a translucent bitmap onto the real dc.
|
||||
wxImage image( x+18, y+6 );
|
||||
image.InitAlpha();
|
||||
unsigned char *alpha=image.GetAlpha();
|
||||
memset(alpha, wxIMAGE_ALPHA_TRANSPARENT, image.GetWidth()*image.GetHeight());
|
||||
|
||||
wxGraphicsContext &gc=*wxGraphicsContext::Create(image);
|
||||
// Shield's background is translucent, alpha=180. This is to a gc, not a dc.
|
||||
AColor::UseThemeColour( &gc, clrTrackInfoSelected, clrTrackPanelText, 180 );
|
||||
// Draw at 1,1, not at 0,0 to avoid clipping of the antialiasing.
|
||||
gc.DrawRoundedRectangle( 1, 1, x+16, y+4, 8.0 );
|
||||
// delete the gc so as to free and so update the wxImage.
|
||||
delete &gc;
|
||||
wxBitmap bitmap( image );
|
||||
dc.DrawBitmap( bitmap, rect.x+6, rect.y);
|
||||
#endif
|
||||
dc.SetTextForeground(theTheme.Colour( clrTrackPanelText ));
|
||||
dc.DrawText (wt->GetName(), rect.x+15, rect.y+3); // move right 15 pixels to avoid overwriting <- symbol
|
||||
}
|
||||
},
|
||||
#ifdef USE_MIDI
|
||||
[&](const NoteTrack *nt) {
|
||||
bool muted = false;
|
||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||
const auto artist = TrackArtist::Get( context );
|
||||
// const auto artist = TrackArtist::Get( context );
|
||||
const auto hasSolo = artist->hasSolo;
|
||||
muted = (hasSolo || nt->GetMute()) && !nt->GetSolo();
|
||||
#endif
|
||||
@ -383,6 +385,8 @@ void TrackArt::DrawTrack(TrackPanelDrawingContext &context,
|
||||
DrawTimeTrack( context, tt, rect );
|
||||
}
|
||||
);
|
||||
if( artist->mbShowTrackNameInTrack )
|
||||
DrawTrackName( context, t, rect );
|
||||
}
|
||||
|
||||
void TrackArt::DrawVRuler
|
||||
@ -3245,7 +3249,7 @@ void TrackArtist::UpdatePrefs()
|
||||
mShowClipping = gPrefs->Read(wxT("/GUI/ShowClipping"), mShowClipping);
|
||||
mSampleDisplay = TracksPrefs::SampleViewChoice();
|
||||
|
||||
mbShowTrackNameInWaveform =
|
||||
mbShowTrackNameInTrack =
|
||||
gPrefs->ReadBool(wxT("/GUI/ShowTrackNameInWaveform"), false);
|
||||
|
||||
SetColours(0);
|
||||
|
@ -61,6 +61,9 @@ namespace TrackArt {
|
||||
void DrawVRuler(TrackPanelDrawingContext &context,
|
||||
const Track *t, const wxRect & rect, bool bSelected );
|
||||
|
||||
void DrawTrackName(TrackPanelDrawingContext &context,
|
||||
const Track *t, const wxRect & rect );
|
||||
|
||||
// Helper: draws the "sync-locked" watermark tiled to a rectangle
|
||||
void DrawSyncLockTiles(
|
||||
TrackPanelDrawingContext &context, const wxRect &rect );
|
||||
@ -177,7 +180,7 @@ public:
|
||||
float mdBrange; // "/GUI/EnvdBRange"
|
||||
long mShowClipping; // "/GUI/ShowClipping"
|
||||
int mSampleDisplay;
|
||||
bool mbShowTrackNameInWaveform; // "/GUI/ShowTrackNameInWaveform"
|
||||
bool mbShowTrackNameInTrack; // "/GUI/ShowTrackNameInWaveform"
|
||||
|
||||
wxBrush blankBrush;
|
||||
wxBrush unselectedBrush;
|
||||
|
Loading…
x
Reference in New Issue
Block a user