diff --git a/src/TrackInfo.cpp b/src/TrackInfo.cpp index c675d4678..24526deff 100644 --- a/src/TrackInfo.cpp +++ b/src/TrackInfo.cpp @@ -32,9 +32,11 @@ Paul Licameli split from TrackPanel.cpp #include #include +#include #include "AColor.h" #include "AllThemeResources.h" +#include "Prefs.h" #include "Project.h" #include "Track.h" #include "TrackPanelDrawingContext.h" @@ -520,30 +522,35 @@ unsigned TrackInfo::DefaultTrackHeight( const TCPLines &topLines ) return (unsigned) std::max( needed, (int) TrackView::DefaultHeight ); } -void TrackInfo::UpdatePrefs( wxWindow *pParent ) -{ - gPrefs->Read(wxT("/GUI/Solo"), &gSoloPref, wxT("Simple")); +// Subscribe to preference changes to update static variables +static struct MyPrefsListener : PrefsListener { + void UpdatePrefs() override + { + gPrefs->Read(wxT("/GUI/Solo"), &gSoloPref, wxT("Simple")); - // Calculation of best font size depends on language, so it should be redone in case - // the language preference changed. + // Calculation of best font size depends on language, so it should be redone in case + // the language preference changed. - int fontSize = 10; - gFont.Create(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); + int fontSize = 10; + gFont.Create(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); - int allowableWidth = - // PRL: was it correct to include the margin? - ( kTrackInfoWidth + kLeftMargin ) - - 2; // 2 to allow for left/right borders - int textWidth, textHeight; - do { - gFont.SetPointSize(fontSize); - pParent->GetTextExtent(_("Stereo, 999999Hz"), - &textWidth, - &textHeight, - NULL, - NULL, - &gFont); - fontSize--; - } while (textWidth >= allowableWidth); -} + int allowableWidth = + // PRL: was it correct to include the margin? + ( kTrackInfoWidth + kLeftMargin ) + - 2; // 2 to allow for left/right borders + int textWidth; + std::unique_ptr pContext( + wxGraphicsContext::Create() + ); + pContext->SetFont( gFont, *wxBLACK ); + do { + gFont.SetPointSize(fontSize); + double dWidth; + pContext->GetTextExtent( + _("Stereo, 999999Hz"), &dWidth, nullptr ); + textWidth = (wxCoord)( dWidth + 0.5 ); + fontSize--; + } while (textWidth >= allowableWidth); + } +} sPrefsListener; diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 75ea6f273..b601e8aaa 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -70,7 +70,6 @@ is time to refresh some aspect of the screen. #include "Prefs.h" #include "RefreshCode.h" #include "TrackArtist.h" -#include "TrackInfo.h" #include "TrackPanelAx.h" #include "WaveTrack.h" #ifdef EXPERIMENTAL_MIDI_OUT @@ -259,8 +258,6 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id, #pragma warning( default: 4355 ) #endif { - TrackInfo::UpdatePrefs( this ); - SetLayoutDirection(wxLayout_LeftToRight); SetLabel(_("Track Panel")); SetName(_("Track Panel")); @@ -340,8 +337,6 @@ void TrackPanel::UpdatePrefs() // frequences may have been changed. UpdateVRulers(); - TrackInfo::UpdatePrefs( this ); - Refresh(); }