Audacity 3.2.0
TrackInfo.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5TrackInfo.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9
10**********************************************************************/
11
12
13#include "TrackInfo.h"
14
15#include <wx/app.h>
16#include <wx/dc.h>
17#include <wx/font.h>
18#include <wx/window.h>
19
20#include "AColor.h"
21#include "AllThemeResources.h"
22#include "PlayableTrack.h"
23#include "Prefs.h"
24#include "Project.h"
25#include "SyncLock.h"
26#include "Theme.h"
28#include "UIHandle.h"
29#include "ViewInfo.h"
31
32// Subscribe to preference changes to update static variables
34 wxFont gFont;
35
36 bool mInitialized{ false };
37
38 void UpdatePrefs() override
39 {
40 // Calculation of best font size depends on language, so it should be redone in case
41 // the language preference changed.
42
43 // wxWidgets seems to need a window to do this portably.
44 if ( !wxTheApp )
45 return;
46 auto window = wxTheApp->GetTopWindow();
47 if ( !window )
48 return;
49
50 int fontSize = 10;
51 gFont.Create(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
52
53 int allowableWidth =
54 // PRL: was it correct to include the margin?
56 - 2; // 2 to allow for left/right borders
57 int textWidth;
58 do {
59 gFont.SetPointSize(fontSize);
60 window->GetTextExtent(_("Stereo, 999999Hz"),
61 &textWidth, nullptr, nullptr, nullptr, &gFont);
62 fontSize--;
63 } while (textWidth >= allowableWidth);
64
65 mInitialized = true;
66 }
67};
68
70{
71 static Settings theSettings;
72 if ( !theSettings.mInitialized )
73 theSettings.UpdatePrefs();
74 return theSettings;
75}
76
77// return y value and height
78std::pair< int, int >
79TrackInfo::CalcItemY( const TCPLines &lines, unsigned iItem )
80{
81 int y = 0;
82 auto pLines = lines.begin();
83 while ( pLines != lines.end() &&
84 0 == (pLines->items & iItem) ) {
85 y += pLines->height + pLines->extraSpace;
86 ++pLines;
87 }
88 int height = 0;
89 if ( pLines != lines.end() )
90 height = pLines->height;
91 return { y, height };
92}
93
96{
97 dc->SetFont(settings().gFont);
98}
99
#define _(s)
Definition: Internat.h:73
Extends Track with notions of mute and solo setting.
static Settings & settings()
Definition: TrackInfo.cpp:69
@ kTrackInfoWidth
Definition: ZoomInfo.h:30
@ kLeftMargin
Definition: ZoomInfo.h:27
A listener notified of changes in preferences.
Definition: Prefs.h:652
AUDACITY_DLL_API void SetTrackInfoFont(wxDC *dc)
Definition: TrackInfo.cpp:95
std::vector< TCPLine > TCPLines
Definition: TrackInfo.h:59
AUDACITY_DLL_API std::pair< int, int > CalcItemY(const TCPLines &lines, unsigned iItem)
Definition: TrackInfo.cpp:79
bool mInitialized
Definition: TrackInfo.cpp:36
void UpdatePrefs() override
Definition: TrackInfo.cpp:38
wxFont gFont
Definition: TrackInfo.cpp:34