Detecting when an ImageComponent has been clicked on


#1

Hello everyone!

I'm still fairly new to the Juce framework. I have a question that probably has a fairly simple answer.

Basically in my plugin's gui, i have 4 buttons that i'm trying to set up like radio buttons in html.

I want to be able to click a button and have the image change to the "on Image" and set all of the others to 

the "off image".

I figured the easiest way to do this was to use ImageComponents and use if statements to check which

button was clicked on and then change all of the images. Here is the code i have so far.

void SaturationPluginAudioProcessorEditor::paint (Graphics& g)
{
    g.drawImage(background, 0, 0, 400, 150, 0, 0, 400, 150);

    button1->setBounds(25, 50, 25, 25);
    button2->setBounds(25, 75, 25, 25);
    button3->setBounds(25, 100, 25, 25);
    button4->setBounds(25, 125, 25, 25);

    if (button1->isMouseButtonDown()){
        button1->setImage(buttonOnImage);
        button2->setImage(buttonOffImage);
        button3->setImage(buttonOffImage);
        button4->setImage(buttonOffImage);
    }

    if (button2->isMouseButtonDown()){
        button1->setImage(buttonOffImage);
        button2->setImage(buttonOnImage);
        button3->setImage(buttonOffImage);
        button4->setImage(buttonOffImage);
    }

    if (button3->isMouseButtonDown()){
        button1->setImage(buttonOffImage);
        button2->setImage(buttonOffImage);
        button3->setImage(buttonOnImage);
        button4->setImage(buttonOffImage);
    }

    if (button4->isMouseButtonDown()){
        button1->setImage(buttonOffImage);
        button2->setImage(buttonOffImage);
        button3->setImage(buttonOffImage);
        button4->setImage(buttonOnImage);
    }


    Gain->setBounds(10, 30, 260, 20);
    Gain->addListener(this);

    //satKnob->setBounds(40, 40, 20, 20);
    satKnob->setBounds(125, 80, 50, 50);
}

I'm not sure where to actually put the if statements though. When I put them in the paint method of the processorEditor, it only works the first time I click a button, and then wont change after that. I've also tried inheriting mouseListener and putting the code in mouseDown();, but that didnt seem to work either, but I could be missing something.

Like i said, i'm really new to Juce and it's the first API i've tried to learn, so any help would be much appreciatted!


#2

Okay so not even 5 minutes after I posted this, it hit me. I forgot to add listeners to the buttons. I added them

and moved the if statements to the mouseDown() method and boom! It worked! Sorry for the meaningless post.