Skip to content

Commit

Permalink
started displaying param min/max values
Browse files Browse the repository at this point in the history
  • Loading branch information
matkatmusic committed Mar 29, 2021
1 parent 955021e commit e552b1a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
38 changes: 34 additions & 4 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ void RotarySliderWithLabels::paint(juce::Graphics &g)

auto sliderBounds = getSliderBounds();

// g.setColour(Colours::red);
// g.drawRect(getLocalBounds());
// g.setColour(Colours::yellow);
// g.drawRect(sliderBounds);
g.setColour(Colours::red);
g.drawRect(getLocalBounds());
g.setColour(Colours::yellow);
g.drawRect(sliderBounds);

getLookAndFeel().drawRotarySlider(g,
sliderBounds.getX(),
Expand All @@ -97,6 +97,33 @@ void RotarySliderWithLabels::paint(juce::Graphics &g)
startAng,
endAng,
*this);

auto center = sliderBounds.toFloat().getCentre();
auto radius = sliderBounds.getWidth() * 0.5f;

g.setColour(Colour(0u, 172u, 1u));
g.setFont(getTextHeight());

auto numChoices = labels.size();
for( int i = 0; i < numChoices; ++i )
{
auto pos = labels[i].pos;
jassert(0.f <= pos);
jassert(pos <= 1.f);

auto ang = jmap(pos, 0.f, 1.f, startAng, endAng);

auto c = center.getPointOnCircumference(radius + getTextHeight() * 0.5f + 1, ang);

Rectangle<float> r;
auto str = labels[i].label;
r.setSize(g.getCurrentFont().getStringWidth(str), getTextHeight());
r.setCentre(c);
r.setY(r.getY() + getTextHeight());

g.drawFittedText(str, r.toNearestInt(), juce::Justification::centred, 1);
}

}

juce::Rectangle<int> RotarySliderWithLabels::getSliderBounds() const
Expand Down Expand Up @@ -292,6 +319,9 @@ highCutSlopeSliderAttachment(audioProcessor.apvts, "HighCut Slope", highCutSlope
// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.

peakFreqSlider.labels.add({0.f, "20Hz"});
peakFreqSlider.labels.add({1.f, "20kHz"});

for( auto* comp : getComps() )
{
addAndMakeVisible(comp);
Expand Down
8 changes: 8 additions & 0 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ struct RotarySliderWithLabels : juce::Slider
setLookAndFeel(nullptr);
}

struct LabelPos
{
float pos;
juce::String label;
};

juce::Array<LabelPos> labels;

void paint(juce::Graphics& g) override;
juce::Rectangle<int> getSliderBounds() const;
int getTextHeight() const { return 14; }
Expand Down

0 comments on commit e552b1a

Please sign in to comment.