# PreferencesPanel and DrawableButton

**URL:** <https://forum.juce.com/t/preferencespanel-and-drawablebutton/6524>\
**Category:** General JUCE discussion\
**Created:** [March 4, 2011, 5:24pm UTC](https://forum.juce.com/t/preferencespanel-and-drawablebutton/6524 "2011-03-04T17:24:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdsp](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mdsp](https://forum.juce.com/u/mdsp)\
**Post date:** [March 4, 2011, 5:24pm UTC](https://forum.juce.com/t/preferencespanel-and-drawablebutton/6524/1 "2011-03-04T17:24:10Z")

</div>

hi,

I wanted more control over the DrawableButtons than what’s available by default with PreferencesPanel (different images when toggle state is true).  
So after adding the pages with addSettingsPage(“page name”, NULL, NULL);

I then scan the child components and explicitly call setImages(). the problem is that afterward the button is clickable everywhere but not on the icon image anymore.  
I had to use a custom Drawable image with a custom hitTest and createCopy to avoid that.

looking briefly at the Drawable button code my patch shouldn’t be necessary, the following code is already enough to avoid the custom hitTest but it doesn’t work in my case:

```auto
        if (currentImage != 0)
        {
            currentImage->setInterceptsMouseClicks (false, false);
            addAndMakeVisible (currentImage);
            DrawableButton::resized();
        }
```

---

<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 4, 2011, 5:52pm UTC](https://forum.juce.com/t/preferencespanel-and-drawablebutton/6524/2 "2011-03-04T17:52:59Z")

</div>

I fixed a bug last week in DrawableImage::hitTest() - have you grabbed that latest version?

---

<div class="post-metadata">

**Author:** ![mdsp](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mdsp](https://forum.juce.com/u/mdsp)\
**Post date:** [March 4, 2011, 6:21pm UTC](https://forum.juce.com/t/preferencespanel-and-drawablebutton/6524/3 "2011-03-04T18:21:28Z")

</div>

here is mine:

```auto
bool DrawableImage::hitTest (int x, int y)
{
    return image.isValid() && image.getPixelAt (x, y).getAlpha() >= 127;
}
```

but I had to disable it like that with a CustomDrawableImage as a workaround:

```auto
virtual bool hitTest(int,int) { return false; }
```

---

<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 4, 2011, 7:44pm UTC](https://forum.juce.com/t/preferencespanel-and-drawablebutton/6524/4 "2011-03-04T19:44:39Z")

</div>

Yes, it’s ignoring your setInterceptsMouseClicks() setting, I guess I should make it check that too.

---

<div class="post-metadata">

**Author:** ![mdsp](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mdsp](https://forum.juce.com/u/mdsp)\
**Post date:** [March 7, 2011, 10:21am UTC](https://forum.juce.com/t/preferencespanel-and-drawablebutton/6524/5 "2011-03-07T10:21:41Z")

</div>

```auto

comes straight from the DrawableButton code.
```

comes straight from the DrawableButton code.

---

<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 7, 2011, 10:24am UTC](https://forum.juce.com/t/preferencespanel-and-drawablebutton/6524/6 "2011-03-07T10:24:12Z")

</div>

I updated the class now, so that you should be able to use setInterceptsMouseClicks
