ToggleImageButon


#1

Hi,

I’d like to do a kind of ToggleImageButton, by that I mean a button which stay down when it’s pressed and which gets its original state when we click it again. And I have two images for the “normal” state and the “down” state. For the moment I use an ImageButton, and I call setImage to change the image when the button is clicked, but it’s not working. Can somebody tell me the best way to do it? Thanx

Leskimo


#2

Did you call repaint()?


#3

yep, but It crashed when I called setImage(). But I 've found another way to do it, I create a subclass of Button, and in the “paintButton” method, I draw my images depending on its state. No sure that’s the best way, but it works. Thanks for answering.

Leskimo


#4

[quote=“leskimo”]yep, but It crashed when I called setImage(). But I 've found another way to do it, I create a subclass of Button, and in the “paintButton” method, I draw my images depending on its state. No sure that’s the best way, but it works. Thanks for answering.

Leskimo[/quote]

…ugh. So you’ve written your own version of something that already works… Have a look at the demo app, where it has buttons like this. If it’s crashing then you’re probably passing it a dodgy image pointer or deleting the image when you shouldn’t.


#5

jules, i wonder if the ImageButton class
reacts to the “setClickingTogglesState()” method ?

does it ?

thx in advance,
matthias


#6

[quote=“mgpro.de”]jules, i wonder if the ImageButton class
reacts to the “setClickingTogglesState()” method ?

does it ?

thx in advance,
matthias[/quote]

Yes - that’s a base class method, so works for all buttons.


#7

so, what i’m doing wrong ?

      uiButton3 = new ImageButton (T("uiButton3"));
      uiButton3->setImages(true,true,true,
                            uiB3Image, 1.0f,Colours::transparentWhite,
                            0, 1.0f, Colours::transparentWhite,
                            uiB4Image, 1.0f, Colours::transparentWhite,
                            0.0f);


      addAndMakeVisible(uiButton3);
      uiButton3->setClickingTogglesState(true);

the button does not stay in down state after releasing the mouse click.

anyone knows what i mean ?!


#8

the “down” image isn’t the same as the “toggled-on” image. Any button can be made to toggle, but the imagebutton doesn’t actually let you specifiy different images for its different toggle states. The DrawableButton does, so you could just use one of those. I thought you were asking about it in a more general sense!


#9

(sorry, for all the annoying questions)

but:
i changed my code, so that there is onyl one image,
but different opacity and colour values.

uiButton3 = new ImageButton (T("uiButton3"));
uiButton3->setImages(true,true,true,
                      uiB3Image, 1.0f, Colours::transparentWhite,
                      uiB3Image, 1.0f, Colours::transparentWhite,
                      uiB3Image, 0.0f, Colours::black,
                      0.0f);

addAndMakeVisible(uiButton3);
uiButton3->setClickingTogglesState(true);

and still the “down state” do not stay after releasing the mouse click.
also, the isDown()-method tells “false” after the release …

so, how does the images button alter its behaviour regarding to the
setClickingTogglesState(true) method ?

i do not see any difference whether i call
setClickingTogglesState(true) or setClickingTogglesState(false) ?!


#10

“down” is the image it shows when the mouse button is down. It has nothing to do with toggling…


#11

ah ok, i see !

i muddled up getToggleState() and isDown() …

thx, i got it now :wink:


#12