Newbie DrawableButton help please


I’m very new to JUCE so this is bound to be a really dumb question…

I’m trying to get a DrawableButton to work on my interface (its an audio plugin, but I don’t think that’s significant which is why I’m posting in the general forum).

I’ve got it so that the button starts displaying my “off” image, but to get it to change to my “on” image, I have to click it and then move the mouse away from its hit area. Once its showing the “on” image, to get it to go back to the “off” image again, I have to click it and then move my mouse away again.

What I want is for it to change image when I click it, and for me not to need to move my mouse away.

Please, does anyone have any idea what I’m doing wrong here?

Here’s my code (I’m pulling the images for the button out of one image which has the “off” state in the top half, and the “on” state in the bottom half VSTGUI style).

		Image imageBtn = ImageFileFormat::loadFrom (BinaryData::analysis_button_png, BinaryData::analysis_button_pngSize);
		Rectangle<int> rectBtnOff = imageBtn.getBounds();
		rectBtnOff.setHeight( rectBtnOff.getHeight() / 2 );
		Rectangle<int> rectBtnOn = rectBtnOff;
		rectBtnOn.setPosition( 0, rectBtnOff.getHeight() );

		DrawableImage dimageBtnOff, dimageBtnOn;
		dimageBtnOff.setImage( imageBtn.getClippedImage( rectBtnOff ) );
		dimageBtnOn.setImage( imageBtn.getClippedImage( rectBtnOn ) );
		m_btnAnalysis.setBounds (514, 359, rectBtnOff.getWidth(), rectBtnOff.getHeight() );
		m_btnAnalysis.setBackgroundColours( Colours::transparentBlack, Colours::transparentBlack );
		m_btnAnalysis.setImages( &dimageBtnOff, 0, 0, 0, &dimageBtnOn, 0, 0, 0 );

Thanks for any help


Well, I’ve looked into the DrawableButton and Button code a bit now, and maybe its not such a dumb question.

The way I’m reading the code, Button::mouseUp calls updateState and then, sometimes, calls internalClickCallback. The problem with this seems to be that updateState is what ends up working out what image it should be displaying (in DrawableButton::buttonStateChanged), and internalClickCallback is what triggers the actual toggling of the on/off value of the button (in Button::setToggleState). So these things seem to me to be getting called in the wrong order.

As an experiment I’ve tried changing the order of the code to be…

[code]void Button::mouseUp (const MouseEvent& e)
const bool wasDown = isDown();

if (wasDown && isOver() && ! triggerOnMouseDown)
    internalClickCallback (e.mods);

updateState (isMouseOver(), false);


And that does seem to then produce a DrawableButton which behaves how I was expecting. But, I’m pretty loath to just blithely make this change because I’m probably breaking something I don’t understand.