# ImageButton issue

**URL:** <https://forum.juce.com/t/imagebutton-issue/7563>\
**Category:** General JUCE discussion\
**Created:** [October 12, 2011, 3:19pm UTC](https://forum.juce.com/t/imagebutton-issue/7563 "2011-10-12T15:19:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NicoLAC](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@NicoLAC](https://forum.juce.com/u/NicoLAC)\
**Post date:** [October 12, 2011, 3:19pm UTC](https://forum.juce.com/t/imagebutton-issue/7563/1 "2011-10-12T15:19:07Z")

</div>

Hi,

I found an issue in ImageButton which is quite easy to fix :

- In the function getCurrentImage(), you are returning downImage when button is down or toggled
- In the function paintButton(), you are sending down opacity only if button is down

Could you send down opacity when button is toggled ? As you do in getCurrentImage() for image to use ?  
Thanks 🙂

Best regards

---

<div class="post-metadata">

**Author:** ![NicoLAC](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@NicoLAC](https://forum.juce.com/u/NicoLAC)\
**Post date:** [October 13, 2011, 9:46am UTC](https://forum.juce.com/t/imagebutton-issue/7563/2 "2011-10-13T09:46:06Z")

</div>

Any up on this ?

---

<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:** [October 13, 2011, 1:34pm UTC](https://forum.juce.com/t/imagebutton-issue/7563/3 "2011-10-13T13:34:29Z")

</div>

Sorry, don’t quite understand…?

---

<div class="post-metadata">

**Author:** ![NicoLAC](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@NicoLAC](https://forum.juce.com/u/NicoLAC)\
**Post date:** [October 17, 2011, 1:21pm UTC](https://forum.juce.com/t/imagebutton-issue/7563/4 "2011-10-17T13:21:29Z")

</div>

First, there is the ::getCurrentImage() which takes into account the down AND toggle states to return the down image.

```auto
Image ImageButton::getCurrentImage() const
{
    if (isDown() || getToggleState())
        return getDownImage();

    if (isOver())
        return getOverImage();

    return getNormalImage();
}
```

Second, there is the code at the end of the ::paintButton() function. You do not take into account the toggle state to return the overlay.

```auto
        getLookAndFeel().drawImageButton (g, &im, imageX, imageY, imageW, imageH,
                                          isButtonDown ? downOverlay
                                                       : (isMouseOverButton ? overOverlay
                                                                            : normalOverlay),
                                          isButtonDown ? downOpacity
                                                       : (isMouseOverButton ? overOpacity
                                                                            : normalOpacity),
                                          *this);
```

This could be the following code, in order to return down overlay if button is toggled, as it is done in getCurrentImage() function.

```auto
        getLookAndFeel().drawImageButton (g, &im, imageX, imageY, imageW, imageH,
                                          (isButtonDown || getToggleState()) ? downOverlay
                                                       : (isMouseOverButton ? overOverlay
                                                                            : normalOverlay),
                                          (isButtonDown || getToggleState()) ? downOpacity
                                                       : (isMouseOverButton ? overOpacity
                                                                            : normalOpacity),
                                          *this);
```

---

<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:** [October 17, 2011, 3:47pm UTC](https://forum.juce.com/t/imagebutton-issue/7563/5 "2011-10-17T15:47:40Z")

</div>

Ah! I see what you mean - thanks, that does seem like a good idea!

---

<div class="post-metadata">

**Author:** ![NicoLAC](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@NicoLAC](https://forum.juce.com/u/NicoLAC)\
**Post date:** [October 19, 2011, 7:47am UTC](https://forum.juce.com/t/imagebutton-issue/7563/6 "2011-10-19T07:47:48Z")

</div>

Yes I have done it internally to view what it will do in live, and it is really better 🙂  
Thank you for this modification.  
You do a great job !
