ShapeButton: Suppress mouse down scaling factor?


Does anyone know how I can suppress the ~90% scaling factor that is applied to Button (specifically ShapeButton in my case) components during mouse down events? (i.e. stop buttons getting a little smaller whilst you click them).

Thanks in advance!


Could you post a reproducible example? Buttons don't scale down when you click them - unless you're referring to something else and I'm misunderstanding.


Thanks Josh, I think it's specific to ShapeButtons.

From modules/juce_gui_basics/buttons/juce_ShapeButton.cpp

void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
    if (! isEnabled())
        isMouseOverButton = false;
        isButtonDown = false;
    Rectangle<float> r (border.subtractedFrom (getLocalBounds()).toFloat().reduced (outlineWidth * 0.5f));
    if (getComponentEffect() != nullptr)
        r = r.reduced (2.0f);
    if (isButtonDown)
        const float sizeReductionWhenPressed = 0.04f;
        r = r.reduced (sizeReductionWhenPressed * r.getWidth(),
                       sizeReductionWhenPressed * r.getHeight());
    const AffineTransform trans (shape.getTransformToScaleToFit (r, maintainShapeProportions));
    g.setColour (isButtonDown ? downColour
                              : isMouseOverButton ? overColour
                                                  : normalColour);
    g.fillPath (shape, trans);
    if (outlineWidth > 0.0f)
        g.setColour (outlineColour);
        g.strokePath (shape, PathStrokeType (outlineWidth), trans);

The functionality of ShapeButton is perfect for my purpose besides sizeReductionWhenPressed. So should I create a custom component class for my project which inherits from ShapeButton and overrides ShapeButton::paintButton() or is there an easier way to disable the size reduction for specific shapeButtons in my project?

I'm drawing very simple polygons into Path objects and using the shapeButton's setShape() method to toggle between two alternate polygons. I just want the button to go directly from one polygon to the other, without the intermediary sizeReduced versions during mouseDown.


Yes, override paintButton seems like the way to go :) Being able to override this more simply also seems like a reasonable feature request ... added it to the backlog!