From 9ba023d607cb8a79cdf90c9b0ef9dec9af98e6a9 Mon Sep 17 00:00:00 2001 From: James Crook Date: Sat, 6 Apr 2019 22:26:59 +0100 Subject: [PATCH] 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). --- src/LabelTrack.cpp | 19 ++++++++++ src/TrackArtist.cpp | 90 +++++++++++++++++++++++---------------------- src/TrackArtist.h | 5 ++- 3 files changed, 70 insertions(+), 44 deletions(-) diff --git a/src/LabelTrack.cpp b/src/LabelTrack.cpp index fcfd67ba7..bd726c27e 100644 --- a/src/LabelTrack.cpp +++ b/src/LabelTrack.cpp @@ -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 ) @@ -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= nRowsUsed ) nRowsUsed=iRow+1; diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index 97ada06cf..8dd1f2631 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -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); diff --git a/src/TrackArtist.h b/src/TrackArtist.h index 7604fe110..8dabcaadf 100644 --- a/src/TrackArtist.h +++ b/src/TrackArtist.h @@ -60,6 +60,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( @@ -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;