Audacity 3.2.0
DynamicRangeProcessorPanelCommon.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 DynamicRangeProcessorPanelCommon.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
12#include "wxPanelWrapper.h"
13#include <wx/dcclient.h>
14#include <wx/pen.h>
15
17{
18std::unique_ptr<wxGraphicsContext> MakeGraphicsContext(const wxPaintDC& dc)
19{
20 auto gc = wxGraphicsContext::Create(dc);
21 gc->SetAntialiasMode(wxANTIALIAS_DEFAULT);
22 gc->SetInterpolationQuality(wxINTERPOLATION_BEST);
23 return std::unique_ptr<wxGraphicsContext>(gc);
24}
25
26wxColor GetColorMix(const wxColor& a, const wxColor& b, double aWeight)
27{
28 return wxColor(
29 a.Red() * aWeight + b.Red() * (1 - aWeight),
30 a.Green() * aWeight + b.Green() * (1 - aWeight),
31 a.Blue() * aWeight + b.Blue() * (1 - aWeight),
32 a.Alpha() * aWeight + b.Alpha() * (1 - aWeight));
33}
34
35float GetGraphDbRange(int height)
36{
37 const auto factor = std::max(1.f, 1.f * height / graphMinHeight);
38 return factor * graphMinRangeDb;
39}
40
41wxGraphicsBrush GetGraphBackgroundBrush(wxGraphicsContext& gc, int height)
42{
43 // It looks like we're not going to use a gradient for the background after
44 // all, but keep the way we had it available for a while, in case we change
45 // our mind. (Whoever still sees this code in this state in the future please
46 // feel free to clean up.)
47 constexpr auto useGradient = false;
48 return useGradient ? gc.CreateLinearGradientBrush(
49 0, 0, 0, height, backgroundColor,
50 GetColorMix(backgroundColor, *wxWHITE, 0.75)) :
51 gc.CreateBrush(backgroundColor);
52}
53
54wxRect GetPanelRect(const wxPanelWrapper& panel)
55{
56#ifndef __WXMAC__
57 return panel.GetClientRect();
58#else
59 auto rect = panel.GetClientRect();
60 rect.SetX(rect.GetX() + 1);
61 rect.SetY(rect.GetY() + 1);
62 rect.SetWidth(rect.GetWidth() - 1);
63 rect.SetHeight(rect.GetHeight() - 1);
64 return rect;
65#endif
66}
67
68} // namespace DynamicRangeProcessorPanel
wxColor GetColorMix(const wxColor &a, const wxColor &b, double aWeight)
std::unique_ptr< wxGraphicsContext > MakeGraphicsContext(const wxPaintDC &dc)
wxRect GetPanelRect(const wxPanelWrapper &panel)
wxGraphicsBrush GetGraphBackgroundBrush(wxGraphicsContext &gc, int height)