diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index eec317464..192155790 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -53,7 +53,6 @@ audio tracks. #include "prefs/GUISettings.h" #include "prefs/TracksPrefs.h" -#include "tracks/ui/TrackView.h" #include @@ -125,111 +124,6 @@ void TrackArtist::SetColours( int iColorIndex) } } -void TrackArt::DrawTrackNames(TrackPanelDrawingContext &context, - const TrackList * tracks, - const wxRegion & reg, - const wxRect & clip) -{ - // Fix the horizontal extent; will later change only the vertical extent. - const auto artist = TrackArtist::Get( context ); - const auto leftOffset = artist->leftOffset; - wxRect teamRect{ - clip.x + leftOffset, 0, clip.width - (leftOffset + kRightMargin), 0 - }; - - const auto &zoomInfo = *artist->pZoomInfo; - if( !artist->mbShowTrackNameInTrack ) - return; - - for(auto leader : tracks->Leaders()) { - auto group = TrackList::Channels( leader ); - auto &view = TrackView::Get( *leader ); - - teamRect.y = view.GetY() - zoomInfo.vpos; - teamRect.height = group.sum( [&] (const Track *channel) { - auto &channelView = TrackView::Get( *channel ); - return view.GetHeight(); - }); - - if (teamRect.GetBottom() < clip.GetTop()) - continue; - else if (teamRect.GetTop() > clip.GetBottom()) - break; - - for (auto t : group) { - if (teamRect.Intersects(clip) && reg.Contains(teamRect)) { - t = t->SubstitutePendingChangedTrack().get(); - wxRect trackRect { - teamRect.x, - TrackView::Get( *t ).GetY() - zoomInfo.vpos + kTopMargin, - teamRect.width, - teamRect.height - }; - DrawTrackName( context, t, trackRect ); - } - } - } -} - -// 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 ); - - // Logic for name background translucency (aka 'shields') - // Tracks less than kOpaqueHeight high will have opaque shields. - // Tracks more than kTranslucentHeight will have maximum translucency for shields. - const int kOpaqueHeight = 44; - const int kTranslucentHeight = 124; - int h = rect.GetHeight(); - // 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); - // kOpaque is the shield's alpha for tracks that are not tall - // kTranslucent is the shield's alpha for tracks that are tall. - const int kOpaque = 255; - const int kTranslucent = 140; - // 0.0 maps to full opacity, 1.0 maps to full translucency. - int opacity = 255 - (255-140)*f; - -#ifdef __WXMAC__ - // Mac dc is a graphics dc already. - AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, opacity ); - 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()); - - { - std::unique_ptr< wxGraphicsContext > - pGc{ wxGraphicsContext::Create(image) }; - auto &gc = *pGc; - // This is to a gc, not a dc. - AColor::UseThemeColour( &gc, clrTrackInfoSelected, clrTrackPanelText, opacity ); - // Draw at 1,1, not at 0,0 to avoid clipping of the antialiasing. - gc.DrawRoundedRectangle( 1, 1, x+16, y+4, 8.0 ); - // destructor of gc updates the wxImage. - } - 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 -} - /// Takes a value between min and max and returns a value between /// height and 0 /// \todo Should this function move int GuiWaveTrack where it can diff --git a/src/TrackArtist.h b/src/TrackArtist.h index 7c1e5a00c..3cd507866 100644 --- a/src/TrackArtist.h +++ b/src/TrackArtist.h @@ -38,11 +38,6 @@ class ZoomInfo; namespace TrackArt { - void DrawTrackNames(TrackPanelDrawingContext &context, - const TrackList *tracks, - const wxRegion & reg, - const wxRect &clip); - void DrawTrackName(TrackPanelDrawingContext &context, const Track *t, const wxRect & rect ); diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index f93899ae6..f1506b327 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -911,7 +911,6 @@ void TrackPanel::DrawTracks(wxDC * dc) mTrackArtist->hasSolo = hasSolo; this->CellularPanel::Draw( context, TrackArtist::NPasses ); - TrackArt::DrawTrackNames( context, GetTracks(), region, clip ); } void TrackPanel::SetBackgroundCell diff --git a/src/tracks/labeltrack/ui/LabelTrackView.cpp b/src/tracks/labeltrack/ui/LabelTrackView.cpp index 4121bcb3d..66a8bec5a 100644 --- a/src/tracks/labeltrack/ui/LabelTrackView.cpp +++ b/src/tracks/labeltrack/ui/LabelTrackView.cpp @@ -840,6 +840,7 @@ void LabelTrackView::Draw( { if ( iPass == TrackArtist::PassTracks ) Draw( context, rect ); + CommonTrackView::Draw( context, rect, iPass ); } void LabelTrackView::SetSelectedIndex( int index ) diff --git a/src/tracks/playabletrack/notetrack/ui/NoteTrackView.cpp b/src/tracks/playabletrack/notetrack/ui/NoteTrackView.cpp index 00bf54b93..ce7be1ab2 100644 --- a/src/tracks/playabletrack/notetrack/ui/NoteTrackView.cpp +++ b/src/tracks/playabletrack/notetrack/ui/NoteTrackView.cpp @@ -726,5 +726,6 @@ void NoteTrackView::Draw( #endif DrawNoteTrack( context, nt.get(), rect, muted ); } + CommonTrackView::Draw( context, rect, iPass ); } #endif diff --git a/src/tracks/playabletrack/wavetrack/ui/WaveTrackView.cpp b/src/tracks/playabletrack/wavetrack/ui/WaveTrackView.cpp index fe34a15b6..84b9e451c 100644 --- a/src/tracks/playabletrack/wavetrack/ui/WaveTrackView.cpp +++ b/src/tracks/playabletrack/wavetrack/ui/WaveTrackView.cpp @@ -1881,4 +1881,5 @@ void WaveTrackView::Draw( dc.GetGraphicsContext()->SetAntialiasMode(aamode); #endif } + CommonTrackView::Draw( context, rect, iPass ); } diff --git a/src/tracks/timetrack/ui/TimeTrackView.cpp b/src/tracks/timetrack/ui/TimeTrackView.cpp index 4fa53dcaf..28ca09d52 100644 --- a/src/tracks/timetrack/ui/TimeTrackView.cpp +++ b/src/tracks/timetrack/ui/TimeTrackView.cpp @@ -165,4 +165,5 @@ void TimeTrackView::Draw( FindTrack()->SubstitutePendingChangedTrack()); DrawTimeTrack( context, *tt, tt->GetRuler(), rect ); } + CommonTrackView::Draw( context, rect, iPass ); } diff --git a/src/tracks/ui/CommonTrackView.cpp b/src/tracks/ui/CommonTrackView.cpp index 41bf971e0..e39b13876 100644 --- a/src/tracks/ui/CommonTrackView.cpp +++ b/src/tracks/ui/CommonTrackView.cpp @@ -15,11 +15,18 @@ Paul Licameli split from class TrackView #include "TrackControls.h" #include "ZoomHandle.h" #include "../ui/SelectHandle.h" +#include "../../AColor.h" +#include "../../AllThemeResources.h" #include "../../ProjectSettings.h" #include "../../Track.h" +#include "../../TrackArtist.h" #include "../../TrackInfo.h" +#include "../../TrackPanelDrawingContext.h" #include "../../TrackPanelMouseEvent.h" +#include +#include + std::vector CommonTrackView::HitTest (const TrackPanelMouseState &st, const AudacityProject *pProject) @@ -74,6 +81,76 @@ std::vector CommonTrackView::HitTest return results; } +// Draws the track name on the track, if it is needed. +static void 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 ); + + // Logic for name background translucency (aka 'shields') + // Tracks less than kOpaqueHeight high will have opaque shields. + // Tracks more than kTranslucentHeight will have maximum translucency for shields. + const int kOpaqueHeight = 44; + const int kTranslucentHeight = 124; + int h = rect.GetHeight(); + // 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); + // kOpaque is the shield's alpha for tracks that are not tall + // kTranslucent is the shield's alpha for tracks that are tall. + const int kOpaque = 255; + const int kTranslucent = 140; + // 0.0 maps to full opacity, 1.0 maps to full translucency. + int opacity = 255 - (255-140)*f; + +#ifdef __WXMAC__ + // Mac dc is a graphics dc already. + AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, opacity ); + 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()); + + { + std::unique_ptr< wxGraphicsContext > + pGc{ wxGraphicsContext::Create(image) }; + auto &gc = *pGc; + // This is to a gc, not a dc. + AColor::UseThemeColour( &gc, clrTrackInfoSelected, clrTrackPanelText, opacity ); + // Draw at 1,1, not at 0,0 to avoid clipping of the antialiasing. + gc.DrawRoundedRectangle( 1, 1, x+16, y+4, 8.0 ); + // destructor of gc updates the wxImage. + } + 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 CommonTrackView::Draw( + TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass ) +{ + // This overpaints only the track area, so any pass after tracks is late + // enough. + if ( iPass == TrackArtist::PassMargins ) + DrawTrackName( + context, FindTrack()->SubstitutePendingChangedTrack().get(), rect ); +} + std::shared_ptr CommonTrackView::ContextMenuDelegate() { return TrackControls::Get( *FindTrack() ).shared_from_this(); diff --git a/src/tracks/ui/CommonTrackView.h b/src/tracks/ui/CommonTrackView.h index 4a9587284..325a81a7b 100644 --- a/src/tracks/ui/CommonTrackView.h +++ b/src/tracks/ui/CommonTrackView.h @@ -31,6 +31,11 @@ public: (const TrackPanelMouseState &, const AudacityProject *pProject) final override; + // TrackPanelDrawable implementation + void Draw( + TrackPanelDrawingContext &context, + const wxRect &rect, unsigned iPass ) override; + virtual int GetMinimizedHeight() const override; protected: