diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index ae8daf0f0..a8f42548e 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -1589,7 +1589,7 @@ wxRect TrackPanel::FindTrackRect( const Track * target ) { auto leader = *GetTracks()->FindLeader( target ); if (!leader) { - return { 0, 0, 0, 0 }; + return {}; } return CellularPanel::FindRect( [&] ( TrackPanelNode &node ) { @@ -1599,6 +1599,34 @@ wxRect TrackPanel::FindTrackRect( const Track * target ) } ); } +wxRect TrackPanel::FindFocusedTrackRect( const Track * target ) +{ + auto rect = FindTrackRect(target); + if (rect != wxRect{}) { + // Enlarge horizontally. + // PRL: perhaps it's one pixel too much each side, including some gray + // beyond the yellow? + rect.x = 0; + GetClientSize(&rect.width, nullptr); + + // Enlarge vertically, enough to enclose the yellow focus border pixels + // The the outermost ring of gray pixels is included on three sides + // but not the top (should that be fixed?) + + // (Note that TrackPanel paints its focus over the "top margin" of the + // rectangle allotted to the track, according to TrackView::GetY() and + // TrackView::GetHeight(), but also over the margin of the next track.) + + rect.height += kBottomMargin; + int dy = kTopMargin - 1; + rect.Inflate( 0, dy ); + + // Note that this rectangle does not coincide with any one of + // the nodes in the subdivision. + } + return rect; +} + TrackPanelCell *TrackPanel::GetFocusedCell() { auto pTrack = TrackFocus::Get( *GetProject() ).Get(); diff --git a/src/TrackPanel.h b/src/TrackPanel.h index e622bf7e3..d29ebbae6 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -135,10 +135,20 @@ protected: public: void MakeParentRedrawScrollbars(); - // Rectangle includes track control panel, and the vertical ruler, and - // the proper track area of all channels, and the separators between them. + /*! + @return includes track control panel, and the vertical ruler, and + the proper track area of all channels, and the separators between them. + If target is nullptr, returns empty rectangle. + */ wxRect FindTrackRect( const Track * target ); + /*! + @return includes what's in `FindTrackRect(target)` and the focus ring + area around it. + If target is nullptr, returns empty rectangle. + */ + wxRect FindFocusedTrackRect( const Track * target ); + protected: // Get the root object defining a recursive subdivision of the panel's // area into cells diff --git a/src/commands/ScreenshotCommand.cpp b/src/commands/ScreenshotCommand.cpp index b06ba245c..82605f857 100644 --- a/src/commands/ScreenshotCommand.cpp +++ b/src/commands/ScreenshotCommand.cpp @@ -710,27 +710,7 @@ wxRect ScreenshotCommand::GetTracksRect(TrackPanel * panel){ wxRect ScreenshotCommand::GetTrackRect( AudacityProject * pProj, TrackPanel * panel, int n){ auto FindRectangle = []( TrackPanel &panel, Track &t ) { - // This rectangle omits the focus ring about the track, and - // also within that, a narrow black border with a "shadow" below and - // to the right - wxRect rect = panel.FindTrackRect( &t ); - - // Enlarge horizontally. - // PRL: perhaps it's one pixel too much each side, including some gray - // beyond the yellow? - rect.x = 0; - panel.GetClientSize(&rect.width, nullptr); - - // Enlarge vertically, enough to enclose the yellow focus border pixels - // Omit the outermost ring of gray pixels - - // (Note that TrackPanel paints its focus over the "top margin" of the - // rectangle allotted to the track, according to TrackView::GetY() and - // TrackView::GetHeight(), but also over the margin of the next track.) - - rect.height += kBottomMargin; - int dy = kTopMargin - 1; - rect.Inflate( 0, dy ); + wxRect rect = panel.FindFocusedTrackRect( &t ); // Reposition it relative to parent of panel rect.SetPosition(