Problem with ImageButton listener


#1

Hi folks, I’ve upgraded to Juce 1.52, and after the upgrade, my ImageButton listener doesn’t work. The regular TextButton listeners do work. This problem only started when I updated Juce. I was wondering if anyone can help with this problem? Code is identical to before, except I had to change from “AddButtonListener()” to “AddListener()”. Works for TextButton but not for ImageButton.

Inside of constructor for MyComponent:

addAndMakeVisible (imageButton1 = new ImageButton (T("new button")));
        imageButton1->setButtonText (T("Test 3"));
        imageButton1->addListener (this);
        imageButton1->setImages (false, true, true,
        ImageCache::getFromMemory (ImageData::test_png, ImageData::test_pngSize), 1.0000f, Colour (0x0),
        ImageCache::getFromMemory (ImageData::test_png, ImageData::test_pngSize), 1.0000f, Colour (0x0),
        ImageCache::getFromMemory (ImageData::test_png, ImageData::test_pngSize), 1.0000f, Colour (0x0), 1.0000f);

    addAndMakeVisible (textButtonApply = new TextButton (T("ApplyButton")));
        textButtonApply->setButtonText (T("Apply"));
        textButtonApply->addListener (this);

member for button clicked:

void MyComponent::buttonClicked (Button* buttonThatWasClicked)
{
        if (buttonThatWasClicked == textButtonApply) {
                // user selected apply
                // This works when I click this TextButton
        }
        if (buttonThatWasClicked == imageButton1) {

          // Not triggering when I click this ImageButton

        }
}

header file snip:

class MyComponent : public ButtonListener
{
public:
        MyComponent();
        ~MyComponent();
   

        void paint (Graphics& g);
        void resized();
        void buttonClicked (Button* buttonThatWasClicked);

        juce_UseDebuggingNewOperator

#2

Problem resolved. Changed the overImage and downImage parameters, from:

        ImageCache::getFromMemory (ImageData::test_png, ImageData::test_pngSize), 1.0000f, Colour (0x0),
        ImageCache::getFromMemory (ImageData::test_png, ImageData::test_pngSize), 1.0000f, Colour (0x0),
        ImageCache::getFromMemory (ImageData::test_png, ImageData::test_pngSize), 1.0000f, Colour (0x0), 1.0000f);

To:

        ImageCache::getFromMemory (ImageData::test_png, ImageData::test_pngSize), 1.0000f, Colour (0x0),
        Image(),1.000f,Colour(0x0),
        Image(),1.000f,Colour(0x0));

Now the Button Listener works.