Bigger reach for dial Slider

hi guys,

I have made a new LookandFeel class because I need one rotary slider that has 12 positions and needs to turn from 0-330 degrees in 30 degree steps.

Can you guys help me where I need to change the new reach of the slider? I think the standard is 270 degrees.

This is my class:

class OtherLookAndFeel2 : public LookAndFeel_V4
        setColour (Slider::thumbColourId, Colours::red);
    void drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos,
                           const float rotaryStartAngle, const float rotaryEndAngle, Slider&) override
        auto radius = jmin (width / 2, height / 2) - 15.0f;
        auto centreX = x + width  * 0.5f;
        auto centreY = y + height * 0.5f;
        auto rx = centreX - radius;
        auto ry = centreY - radius;
        auto rw = radius * 2.0f;
        auto angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
        // fill
        g.setColour (Colours::blue);
        g.fillEllipse (rx, ry, rw, rw);
        // outline
        g.setColour (Colours::blue);
        g.drawEllipse (rx, ry, rw, rw, 1.0f);
        Path p;
        auto pointerLength = radius;
        auto pointerThickness = 3.0f;
        p.addRectangle (-pointerThickness * 0.5f, -radius, pointerThickness, pointerLength);
        p.applyTransform (AffineTransform::rotation (angle).translated (centreX, centreY));
        // pointer
        g.setColour (Colours::white);
        g.fillPath (p);

And I use this in my code:

dial2.setBounds (400,187,100,100);

Please help! :wink:


1 Like

@G-Mon thanks for that!

dial1.setRotaryParameters(degreesToRadians(0.0f), degreesToRadians(330.0f), true);

did it for me!

Now I only need to change the starting position to be at 210 degrees in stead of 0, then I am golden.

this does not work (although it starts at the right position)

dial1.setRotaryParameters(degreesToRadians(210.0f), degreesToRadians(180.0f), true);

Could you help me with that?

Found it!!

dial1.setTransform(juce::AffineTransform::rotation(3.4033920414f, 450.0f, 237.0f));


I wouldn’t do that. Instead in your setRotaryParameters, if the range passes 2*pi, you simply add 2*pi, so that endAngle is higher than startAngle. The acceptable range for both is between 0 - 4*pi and endAngle > startAngle.

1 Like