MCPcopy Create free account
hub / github.com/audacity/audacity / PaintMeter

Method PaintMeter

src/effects/CompressionMeterPanel.cpp:134–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134void CompressionMeterPanel::PaintMeter(
135 wxPaintDC& dc, const wxColor& color, const wxRect& rect,
136 const MeterValueProvider& provider)
137{
138 const auto dB = provider.GetCurrentMax();
139 const auto maxDb = provider.GetGlobalMax();
140 const auto fiveSecMaxDb = provider.GetFiveSecMax();
141 const auto downwards =
142 provider.GetDirection() == MeterValueProvider::Direction::Downwards;
143
144 const auto gc = MakeGraphicsContext(dc);
145
146 const double left = rect.GetLeft();
147 const double top = rect.GetTop();
148 const double width = rect.GetWidth();
149 const double height = rect.GetHeight();
150
151 constexpr auto lineWidth = 6.;
152
153 const double dbFrac = std::clamp<double>(dB / mDbBottomEdgeValue, 0., 1.);
154 // So that the top of the cap is aligned with the dB value.
155 const auto yAdjust = lineWidth / 2 * (downwards ? -1 : 1);
156 const double dbY = height * dbFrac + yAdjust;
157 const double maxDbY = maxDb / mDbBottomEdgeValue * height + yAdjust;
158 const double fiveSecMaxDbY =
159 fiveSecMaxDb / mDbBottomEdgeValue * height + yAdjust;
160
161 const auto levelTop = downwards ? top : dbY;
162 const auto levelHeight = downwards ? dbY : height - dbY;
163 const auto maxLevelTop = downwards ? levelHeight - top : maxDbY;
164 const auto maxLevelHeight = std::abs(maxDbY - dbY);
165
166 const auto rectLeft = left + 3;
167 const auto rectWidth = width - 4;
168 const auto opaqueColor = wxColor { color.GetRGB() };
169 gc->SetBrush(GetColorMix(opaqueColor, wxTransparentColor, 0.8));
170 gc->DrawRectangle(rectLeft, levelTop, rectWidth, levelHeight);
171 gc->SetBrush(GetColorMix(opaqueColor, wxTransparentColor, 0.6));
172 gc->DrawRectangle(rectLeft, maxLevelTop, rectWidth, maxLevelHeight);
173 gc->SetBrush(opaqueColor);
174 gc->DrawRectangle(rectLeft, dbY - 2, rectWidth, lineWidth);
175 gc->DrawRectangle(rectLeft, maxDbY - 2, rectWidth, lineWidth);
176 gc->SetPen({ opaqueColor, static_cast<int>(lineWidth / 2) });
177 gc->StrokeLine(
178 left + rectWidth / 2, fiveSecMaxDbY, left + rectWidth, fiveSecMaxDbY);
179}
180
181void CompressionMeterPanel::OnTimer(wxTimerEvent& evt)
182{

Callers

nothing calls this directly

Calls 9

MakeGraphicsContextFunction · 0.85
GetColorMixFunction · 0.85
GetHeightMethod · 0.80
GetRGBMethod · 0.80
GetCurrentMaxMethod · 0.45
GetGlobalMaxMethod · 0.45
GetFiveSecMaxMethod · 0.45
GetDirectionMethod · 0.45
GetWidthMethod · 0.45

Tested by

no test coverage detected