Loading...
Logo
Processing Forum
We work with guicomponant library, a great library, but we have a little probleme.

Copy code
  1.         String[] files;
            files = new String[] {
                    "data/tjoff.jpg", "data/tjover.jpg", "data/tjdown.jpg"
                };
            btnCoins =  new GImageButton(this, "data/tjmask.png", files, 150,10);
and the event handler

Copy code
  1.     public void handleImageButtonEvents(GImageButton imagebutton) {
            if (imagebutton == btnCoins){
                println("Coins -  png images using transparency");
            }
        }
My question is, how can we have a pressed state? For moment there are three event, ROLL_OVER, ROLL_OUT and CLICKED but after a clic, the GImageButton return on it's basic image. We need to change the image of  just pressed button up to an other was pressed ...
I'm french i dont know if i give good explanation. If you need some precision, tell me!

Thx!

Replies(4)

I have moved the topic here because it is about a contributed library.

It looks like you are using Processing 1.5.1 - but which version of G4P are you using?

Unfortunately I am not sure what the actual problem is.
An image button can have upto 3 images
  1. when the mouse is off the button
  2. when the mouse is over the button
  3. when the mouse is over the button and the mouse is pressed.

There are three possible events
  1. CLICKED - mouse-button is clicked
  2. PRESSED - mouse-button pressed when over the image button
  3. RELEASED - mouse-button is released after being PRESSED. (This is only fired if the mouse has moved since the PRESSED event occured - if it has not moved then the CLICKED event would have been fired)
The default setting means that only PRESSED events are fired. To get the other events you need to use

Copy code
  1. button_variable_name.fireAllEvents(true);




Thx for putting my post in the right way.

I use the 1.7.6 of G4P (before 2.0, it's guicomponant instead of G4P).

And my problem is not really what you explain. I read the documentation and after some test, i can't put an image for a clicked image. I mean, there is a normal image, a roll over image and a pressed image but after being pressed, when click is released, the button return on its basic, normal image.

And i dont find a method on the GImageButton which permit to access image or image array.

I mean, there is a normal image, a roll over image and a pressed image but after being pressed, when click is released, the button return on its basic, normal image.

That is normal behaviour for standard button. What you want is a toggle button but the library does not have any.

One solution would be to have a boolean variable that flips between true and false each time the button is clicked, and then based on the value of the boolean variable provide some other visual guide e.g. draw a box round the button for instance.

We do as you say. We use different image to represent 'toggle' button.

Thank for your reply.