ShapeButton clickable area to follow the shape

Hi all I'm trying to get a clickable zone of a ShapeButton class to be exactly what the path describes.

For example if I have a round shaped path in the ShapeButton, it should receive clicks if the mouse if above the ellipse, not in the rectangle bounds area (which is always a rectangle I believe?)

Thanks a lot for your help.

Silvere

 

 

If you have access to the Path, perhaps you could use the Path::contains() function to check if a mouse down or mouse over is inside the Path and handle that accordingly. I'm not sure of the specifics for your case, but I'm pretty sure it's possible.

You’d override hitTest and return true or false depending on if the x, y co-ordinate is contained in the Path.

Rail

Ahh really? That's much easier than I thought it would be. :)

Thanks guys I'll try this today!

It works perfectly cheers

Correct me if i’m wrong, but if i want to create a class which derives from juce::shapebutton it is not possible to get the right behaviour overriding hittTest() since the shape object is private, hence it is not possible to use shape.contains(x,y,tolerance):
this is gives an error:

bool hitTest(int x, int y) override
{
     return shape.contains(x,y,0.1f);
}

how exactly should i implement a custom hitbox the right way for a shapebutton?