# ShapeButton HitTest

**URL:** <https://forum.juce.com/t/shapebutton-hittest/12490>\
**Category:** General JUCE discussion\
**Created:** [March 5, 2014, 3:04am UTC](https://forum.juce.com/t/shapebutton-hittest/12490 "2014-03-05T03:04:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![govind678](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/govind678/32/234_2.png) [@govind678](https://forum.juce.com/u/govind678)\
**Post date:** [March 5, 2014, 3:04am UTC](https://forum.juce.com/t/shapebutton-hittest/12490/1 "2014-03-05T03:04:46Z")

</div>

Hey,

Currently the shapeButton does not actually check if a mouse event is inside the path that was set for the button.  
Say&nbsp;if the button is showing&nbsp;as&nbsp;a circle, clicks or mouse downs that occur in the shape's rectangular bounding box are also registered (which is very un-intuitive, especially for an amateur&nbsp;JUCE user like me).  
  
Do you think you could just add a hitTest() to the ShapeButton class, like so:  
  
&nbsp;

```
bool ShapeButton::hitTest(int x, int y)
{
    return shape.contains(x, y);
}
```

&nbsp;

This would make the ShapeButton actually behave like a "Shape Button".

&nbsp;

Thanks

&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 5, 2014, 11:29am UTC](https://forum.juce.com/t/shapebutton-hittest/12490/2 "2014-03-05T11:29:18Z")

</div>

Mostly&nbsp;people will use ShapeButton&nbsp;for icons. Icons tend to have holes in the path.&nbsp;Can you imagine how irritating it'd be to have&nbsp;an icon&nbsp;where you can only click on the solid parts of the shape, and not inside any holes in the image!

I certainly can't think of any places where I've ever used a shape button where I'd want it to behave like that, and if you did want to do so, it's simple for someone to write their own derived class, override hitTest, and use either the path or some other path to do whatever custom testing they need.

---

<div class="post-metadata">

**Author:** ![govind678](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/govind678/32/234_2.png) [@govind678](https://forum.juce.com/u/govind678)\
**Post date:** [March 6, 2014, 12:51am UTC](https://forum.juce.com/t/shapebutton-hittest/12490/3 "2014-03-06T00:51:51Z")

</div>

I see. I didn't realize the icons part.  
My application required to create pie-chart segments where each segment was to be a button. So&nbsp;I just extended the shapeButton by adding a hitTest.

&nbsp;
