More constructor arguments for RulerPanel

This commit is contained in:
Paul Licameli 2017-11-01 09:16:56 -04:00
parent 8625df6814
commit ab5ff9060b
5 changed files with 127 additions and 72 deletions

View File

@ -280,17 +280,16 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
S.StartVerticalLay(2);
{
vRuler = safenew RulerPanel(this, wxID_ANY);
vRuler->ruler.SetBounds(0, 0, 100, 100); // Ruler can't handle small sizes
vRuler->ruler.SetOrientation(wxVERTICAL);
vRuler->ruler.SetRange(0.0, -dBRange);
vRuler->ruler.SetFormat(Ruler::LinearDBFormat);
vRuler->ruler.SetUnits(_("dB"));
vRuler->ruler.SetLabelEdges(true);
int w;
vRuler->ruler.GetMaxSize(&w, NULL);
vRuler->SetMinSize(wxSize(w, 150)); // height needed for wxGTK
vRuler->SetTickColour( theTheme.Colour( clrGraphLabels ));
vRuler = safenew RulerPanel(
this, wxID_ANY, wxVERTICAL,
wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ 0.0, -dBRange },
Ruler::LinearDBFormat,
_("dB"),
RulerPanel::Options{}
.LabelEdges(true)
.TickColour( theTheme.Colour( clrGraphLabels ) )
);
S.AddSpace(wxDefaultCoord, 1);
S.Prop(1);
@ -348,19 +347,18 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
S.StartHorizontalLay(wxEXPAND, 0);
{
hRuler = safenew RulerPanel(this, wxID_ANY);
hRuler->ruler.SetBounds(0, 0, 100, 100); // Ruler can't handle small sizes
hRuler->ruler.SetOrientation(wxHORIZONTAL);
hRuler->ruler.SetLog(true);
hRuler->ruler.SetRange(10, 20000);
hRuler->ruler.SetFormat(Ruler::RealFormat);
hRuler->ruler.SetUnits(_("Hz"));
hRuler->ruler.SetFlip(true);
hRuler->ruler.SetLabelEdges(true);
int h;
hRuler->ruler.GetMaxSize(NULL, &h);
hRuler->SetMinSize(wxSize(wxDefaultCoord, h));
hRuler->SetTickColour( theTheme.Colour( clrGraphLabels ));
hRuler = safenew RulerPanel(
this, wxID_ANY, wxHORIZONTAL,
wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ 10, 20000 },
Ruler::RealFormat,
_("Hz"),
RulerPanel::Options{}
.Log(true)
.Flip(true)
.LabelEdges(true)
.TickColour( theTheme.Colour( clrGraphLabels ) )
);
S.AddSpace(1, wxDefaultCoord);
S.Prop(1);

View File

@ -623,18 +623,17 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
// -------------------------------------------------------------------
S.StartVerticalLay();
{
mdBRuler = safenew RulerPanel(parent, wxID_ANY);
mdBRuler->ruler.SetBounds(0, 0, 100, 100); // Ruler can't handle small sizes
mdBRuler->ruler.SetOrientation(wxVERTICAL);
mdBRuler->ruler.SetRange(60.0, -120.0);
mdBRuler->ruler.SetFormat(Ruler::LinearDBFormat);
mdBRuler->ruler.SetUnits(_("dB"));
mdBRuler->ruler.SetLabelEdges(true);
mdBRuler->ruler.mbTicksAtExtremes = true;
int w;
mdBRuler->ruler.GetMaxSize(&w, NULL);
mdBRuler->SetMinSize(wxSize(w, 150)); // height needed for wxGTK
mdBRuler->ruler.SetTickColour( wxColour(0,0,0) );
mdBRuler = safenew RulerPanel(
parent, wxID_ANY, wxVERTICAL,
wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ 60.0, -120.0 },
Ruler::LinearDBFormat,
_("dB"),
RulerPanel::Options{}
.LabelEdges(true)
.TicksAtExtremes(true)
.TickColour( { 0, 0, 0 } )
);
S.Prop(1);
S.AddSpace(0, 1);
@ -677,20 +676,19 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
// Column 1 is empty
S.AddSpace(1, 1);
mFreqRuler = safenew RulerPanel(parent, wxID_ANY);
mFreqRuler->ruler.SetBounds(0, 0, 100, 100); // Ruler can't handle small sizes
mFreqRuler->ruler.SetOrientation(wxHORIZONTAL);
mFreqRuler->ruler.SetLog(true);
mFreqRuler->ruler.SetRange(mLoFreq, mHiFreq);
mFreqRuler->ruler.SetFormat(Ruler::IntFormat);
mFreqRuler->ruler.SetUnits(_("Hz"));
mFreqRuler->ruler.SetFlip(true);
mFreqRuler->ruler.SetLabelEdges(true);
mFreqRuler->ruler.mbTicksAtExtremes = true;
int h;
mFreqRuler->ruler.GetMaxSize(NULL, &h);
mFreqRuler->SetMinSize(wxSize(wxDefaultCoord, h));
mFreqRuler->ruler.SetTickColour( wxColour(0,0,0) );
mFreqRuler = safenew RulerPanel(
parent, wxID_ANY, wxHORIZONTAL,
wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ mLoFreq, mHiFreq },
Ruler::IntFormat,
_("Hz"),
RulerPanel::Options{}
.Log(true)
.Flip(true)
.LabelEdges(true)
.TicksAtExtremes(true)
.TickColour( { 0, 0, 0 } )
);
S.Prop(1);

View File

@ -377,16 +377,15 @@ void EffectScienFilter::PopulateOrExchange(ShuttleGui & S)
S.StartVerticalLay();
{
mdBRuler = safenew RulerPanel(parent, wxID_ANY);
mdBRuler->ruler.SetBounds(0, 0, 100, 100); // Ruler can't handle small sizes
mdBRuler->ruler.SetOrientation(wxVERTICAL);
mdBRuler->ruler.SetRange(30.0, -120.0);
mdBRuler->ruler.SetFormat(Ruler::LinearDBFormat);
mdBRuler->ruler.SetUnits(_("dB"));
mdBRuler->ruler.SetLabelEdges(true);
int w;
mdBRuler->ruler.GetMaxSize(&w, NULL);
mdBRuler->SetSize(wxSize(w, 150)); // height needed for wxGTK
mdBRuler = safenew RulerPanel(
parent, wxID_ANY, wxVERTICAL,
wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ 30.0, -120.0 },
Ruler::LinearDBFormat,
_("dB"),
RulerPanel::Options{}
.LabelEdges(true)
);
S.SetBorder(1);
S.AddSpace(1, 1);
@ -430,18 +429,17 @@ void EffectScienFilter::PopulateOrExchange(ShuttleGui & S)
S.AddSpace(1, 1);
mfreqRuler = safenew RulerPanel(parent, wxID_ANY);
mfreqRuler->ruler.SetBounds(0, 0, 100, 100); // Ruler can't handle small sizes
mfreqRuler->ruler.SetOrientation(wxHORIZONTAL);
mfreqRuler->ruler.SetLog(true);
mfreqRuler->ruler.SetRange(mLoFreq, mNyquist);
mfreqRuler->ruler.SetFormat(Ruler::IntFormat);
mfreqRuler->ruler.SetUnits(wxT(""));
mfreqRuler->ruler.SetFlip(true);
mfreqRuler->ruler.SetLabelEdges(true);
int h;
mfreqRuler->ruler.GetMaxSize(NULL, &h);
mfreqRuler->SetMinSize(wxSize(-1, h));
mfreqRuler = safenew RulerPanel(
parent, wxID_ANY, wxHORIZONTAL,
wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ mLoFreq, mNyquist },
Ruler::IntFormat,
wxT(""),
RulerPanel::Options{}
.Log(true)
.Flip(true)
.LabelEdges(true)
);
S.Prop(1);
S.AddWindow(mfreqRuler, wxEXPAND | wxALIGN_LEFT | wxRIGHT);

View File

@ -1606,10 +1606,37 @@ END_EVENT_TABLE()
IMPLEMENT_CLASS(RulerPanel, wxPanelWrapper)
RulerPanel::RulerPanel(wxWindow* parent, wxWindowID id,
wxOrientation orientation,
const wxSize &bounds,
const Range &range,
Ruler::RulerFormat format,
const wxString &units,
const Options &options,
const wxPoint& pos /*= wxDefaultPosition*/,
const wxSize& size /*= wxDefaultSize*/):
wxPanelWrapper(parent, id, pos, size)
{
ruler.SetBounds( 0, 0, bounds.x, bounds.y );
ruler.SetOrientation(orientation);
ruler.SetRange( range.first, range.second );
ruler.SetLog( options.log );
ruler.SetFormat(format);
ruler.SetUnits( units );
ruler.SetFlip( options.flip );
ruler.SetLabelEdges( options.labelEdges );
ruler.mbTicksAtExtremes = options.ticksAtExtremes;
if (orientation == wxVERTICAL) {
wxCoord w;
ruler.GetMaxSize(&w, NULL);
SetMinSize(wxSize(w, 150)); // height needed for wxGTK
}
else if (orientation == wxHORIZONTAL) {
wxCoord h;
ruler.GetMaxSize(NULL, &h);
SetMinSize(wxSize(wxDefaultCoord, h));
}
if (options.hasTickColour)
ruler.SetTickColour( options.tickColour );
}
RulerPanel::~RulerPanel()

View File

@ -245,7 +245,41 @@ class AUDACITY_DLL_API RulerPanel final : public wxPanelWrapper {
DECLARE_DYNAMIC_CLASS(RulerPanel)
public:
using Range = std::pair<double, double>;
struct Options {
bool log { false };
bool flip { false };
bool labelEdges { false };
bool ticksAtExtremes { false };
bool hasTickColour{ false };
wxColour tickColour;
Options() {}
Options &Log( bool l )
{ log = l; return *this; }
Options &Flip( bool f )
{ flip = f; return *this; }
Options &LabelEdges( bool l )
{ labelEdges = l; return *this; }
Options &TicksAtExtremes( bool t )
{ ticksAtExtremes = t; return *this; }
Options &TickColour( const wxColour c )
{ tickColour = c; hasTickColour = true; return *this; }
};
RulerPanel(wxWindow* parent, wxWindowID id,
wxOrientation orientation,
const wxSize &bounds,
const Range &range,
Ruler::RulerFormat format,
const wxString &units,
const Options &options = {},
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize);