@@ -45,18 +45,43 @@ MagicLevelMeter::MagicLevelMeter()
45
45
setColour (outlineColourId, juce::Colours::silver);
46
46
setColour (tickmarkColourId, juce::Colours::silver);
47
47
48
+ lookAndFeelChanged ();
49
+
48
50
startTimerHz (30 );
49
51
}
50
52
51
53
void MagicLevelMeter::paint (juce::Graphics& g)
52
54
{
53
- if (auto * lnf = dynamic_cast <LookAndFeelMethods*>(&getLookAndFeel ()))
54
- {
55
- lnf->drawLevelMeter (g, *this , source, getLocalBounds ());
56
- return ;
57
- }
55
+ actualLookAndFeel->drawLevelMeter (g, *this , source, getLocalBounds ());
56
+ }
57
+
58
+ void MagicLevelMeter::setLevelSource (MagicLevelSource* newSource)
59
+ {
60
+ source = newSource;
61
+ }
62
+
63
+ void MagicLevelMeter::timerCallback ()
64
+ {
65
+ repaint ();
66
+ }
67
+
68
+ void MagicLevelMeter::lookAndFeelChanged ()
69
+ {
70
+ auto * lnf = dynamic_cast <LookAndFeelMethods*> (&getLookAndFeel ());
71
+
72
+ if (lnf)
73
+ actualLookAndFeel = lnf;
74
+ else
75
+ actualLookAndFeel = &lookAndFeelFallback;
76
+
77
+ repaint ();
78
+ }
79
+
80
+ // ================================================================================
58
81
59
- const auto backgroundColour = findColour (backgroundColourId);
82
+ void MagicLevelMeter::LookAndFeelFallback::drawLevelMeter (juce::Graphics& g, MagicLevelMeter& meter, MagicLevelSource* source, juce::Rectangle<int > bounds)
83
+ {
84
+ const auto backgroundColour = meter.findColour (backgroundColourId);
60
85
if (!backgroundColour.isTransparent ())
61
86
g.fillAll (backgroundColour);
62
87
@@ -67,39 +92,29 @@ void MagicLevelMeter::paint (juce::Graphics& g)
67
92
if (numChannels == 0 )
68
93
return ;
69
94
70
- auto bounds = getLocalBounds () .reduced (3 ).toFloat ();
95
+ auto inner = bounds .reduced (3 ).toFloat ();
71
96
72
- const auto width = bounds .getWidth () / numChannels;
73
- const auto barBackgroundColour = findColour (barBackgroundColourId);
74
- const auto barFillColour = findColour (barFillColourId);
75
- const auto outlineColour = findColour (outlineColourId);
97
+ const auto width = inner .getWidth () / static_cast < float > ( numChannels) ;
98
+ const auto barBackgroundColour = meter. findColour (barBackgroundColourId);
99
+ const auto barFillColour = meter. findColour (barFillColourId);
100
+ const auto outlineColour = meter. findColour (outlineColourId);
76
101
77
102
const auto infinity = -100 .0f ;
78
- for (int i= 0 ; i < numChannels; ++i)
103
+ for (int i = 0 ; i < numChannels; ++i)
79
104
{
80
- auto bar = bounds .removeFromLeft (width).reduced (1 );
105
+ auto bar = inner .removeFromLeft (width).reduced (1 );
81
106
g.setColour (barBackgroundColour);
82
107
g.fillRect (bar);
83
108
g.setColour (outlineColour);
84
109
g.drawRect (bar, 1 .0f );
85
110
bar.reduce (1 , 1 );
86
111
g.setColour (barFillColour);
87
- g.fillRect (bar.withTop (juce::jmap (juce::Decibels::gainToDecibels (source->getRMSvalue (i), infinity),
88
- infinity, 0 .0f , bar.getBottom (), bar.getY ())));
89
- g.drawHorizontalLine (juce::roundToInt (juce::jmap (juce::Decibels::gainToDecibels (source->getMaxValue (i), infinity),
90
- infinity, 0 .0f , bar.getBottom (), bar.getY ())),
91
- static_cast <float >(bar.getX ()), static_cast <float >(bar.getRight ()));
112
+ g.fillRect (bar.withTop (juce::jmap (juce::Decibels::gainToDecibels (source->getRMSvalue (i), infinity), infinity, 0 .0f , bar.getBottom (), bar.getY ())));
113
+ g.drawHorizontalLine (juce::roundToInt (
114
+ juce::jmap (juce::Decibels::gainToDecibels (source->getMaxValue (i), infinity), infinity, 0 .0f , bar.getBottom (), bar.getY ())),
115
+ static_cast <float > (bar.getX ()), static_cast <float > (bar.getRight ()));
92
116
}
93
117
}
94
118
95
- void MagicLevelMeter::setLevelSource (MagicLevelSource* newSource)
96
- {
97
- source = newSource;
98
- }
99
-
100
- void MagicLevelMeter::timerCallback ()
101
- {
102
- repaint ();
103
- }
104
119
105
- } // namespace foleys
120
+ } // namespace foleys
0 commit comments