We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › ControlP5: Buttons that are images
Pages: 1 2 
ControlP5: Buttons that are images (Read 7197 times)
ControlP5: Buttons that are images
Jun 3rd, 2010, 2:59pm
 
I've been looking into ControlP5 to dynamically create buttons that are images. Is sprites the only way to go?
Re: ControlP5: Buttons that are images
Reply #1 - Jun 3rd, 2010, 3:25pm
 
controlp5 is a great library, i didnt check all the latest changes,  but as far as i know, GUI4P by Quark might be the better choise if you want to use a lot of images to build a more complex GUI.

http://www.lagers.org.uk/g4p/applets/g4p_showcase/index.html
Re: ControlP5: Buttons that are images
Reply #2 - Jun 4th, 2010, 5:02am
 
Cedric wrote on Jun 3rd, 2010, 3:25pm:
controlp5 is a great library, i didnt check all the latest changes,  but as far as i know, GUI4P by Quark might be the better choise if you want to use a lot of images to build a more complex GUI.

http://www.lagers.org.uk/g4p/applets/g4p_showcase/index.html


I'll give it a go, thanks Smiley
Re: ControlP5: Buttons that are images
Reply #3 - Jun 4th, 2010, 7:26am
 
G4P supports buttons with images but not images as buttons.

Using images to create regular and irregular shaped buttons occurred to me awhile ago and I planned to include these in the next release of G4P, this was put on hold while I updated the Shapes3D library but now that is done I can now get back to G4P. Not sure when the next release will be as I have even started coding this enhancement yet.

Smiley
Re: ControlP5: Buttons that are images
Reply #4 - Jun 4th, 2010, 8:32am
 
good to know Smiley
Re: ControlP5: Buttons that are images
Reply #5 - Jun 4th, 2010, 9:06am
 
Is it possible, with controlP5 or with GUI4P, to receive events not from the mouse but from touch (using the TUIO library)?
Re: ControlP5: Buttons that are images
Reply #6 - Jun 5th, 2010, 6:46am
 
Quote:
Is it possible, with controlP5 or with G4P, to receive events not from the mouse but from touch (using the TUIO library)?

I don't believe so since G4P responds to mouse and keyboard input and uses the standard Java event handling and TUIO has its own event handling methods.
Sad
Re: ControlP5: Buttons that are images
Reply #7 - Jun 8th, 2010, 8:02am
 
I'm trying to draw a button for each of the choices I have:

Code:
(...)

for (int i = 0; i < choices.size(); i++) {
   Choice chTemp = (Choice) choices.get(i);
   chTemp.draw(width/2 - chunk/2 + 20, height - 190 + i*20);
}


But I'm getting an error in the Choice class, saying that the constructor GButton is undefined here:

Code:
(...)

public void draw(int x, int y) {
   GButton choiceBtn = new GButton(this, name, icon, 1, x, y, 30, 30);
   choiceBtn.setImageAlign(GAlign.LEFT);
   choiceBtn.setColorScheme(GCScheme.GREEN_SCHEME);
   if (selected) choiceBtn.setFocus(true);
   else choiceBtn.setFocus(false);
}


Any ideas on how to do this right? I tried adding GButton choiceBtn right after the imports, but the problem remains
Re: ControlP5: Buttons that are images
Reply #8 - Jun 8th, 2010, 8:46am
 
Usually you get that error when your list of parameters doesn't match the expected lists. Check your parameters have the right types matching those of:
GButton(PApplet theApplet, java.lang.String text, java.lang.String imgFile, int nbrImages, int x, int y, int width, int height)

[EDIT] You are in the Choice class, so 'this' refers to a Choice object, not to a PApplet object. You have to pass a reference to the current sketch to this constructor.
Re: ControlP5: Buttons that are images
Reply #9 - Jun 8th, 2010, 12:00pm
 
If you want to use image buttons you might want V1.6 of G4P - checkout some image buttons here

http://www.lagers.org.uk/g4p/applets/g4p_image_buttons/index.html
Re: ControlP5: Buttons that are images
Reply #10 - Jun 8th, 2010, 2:29pm
 
Quark wrote on Jun 8th, 2010, 12:00pm:
If you want to use image buttons you might want V1.6 of G4P - checkout some image buttons here

http://www.lagers.org.uk/g4p/applets/g4p_image_buttons/index.html


I'll give it a try Smiley thanks for the new version!

PhiLho  wrote on Jun 8th, 2010, 8:46am:
You are in the Choice class, so 'this' refers to a Choice object, not to a PApplet object. You have to pass a reference to the current sketch to this constructor.


That did the trick, thank you very much Smiley
Re: ControlP5: Buttons that are images
Reply #11 - Jun 8th, 2010, 6:23pm
 
Is there a way of removing these buttons I create dynamically? Tried using the setVisible but it's not doing anything :/

Re: ControlP5: Buttons that are images
Reply #12 - Jun 9th, 2010, 12:34am
 
Thought I had a problem there but I just tried adding
Code:
btnInfo.setVisible(false); 


into setup() in the ImageButtons example that comes with the library and the button dissappeared.

So setVisible, works perhaps you might post your code because obviously something else is wrong if the button remains visible.
Smiley
Re: ControlP5: Buttons that are images
Reply #13 - Jun 9th, 2010, 3:15am
 
Quark wrote on Jun 9th, 2010, 12:34am:
Thought I had a problem there but I just tried adding
Code:
btnInfo.setVisible(false); 


into setup() in the ImageButtons example that comes with the library and the button dissappeared.

So setVisible, works perhaps you might post your code because obviously something else is wrong if the button remains visible.
Smiley


I drawing buttons for when I place and object (representing an Activity) in a specific area of the screen. I use (still using your previous library atm):

In Activity Class
Code:
 (...)

private void drawChoices() {
for (int i = 0; i < choices.size(); i++) {
Choice chTemp = (Choice) choices.get(i);
chTemp.draw(width/2 - chunk/2 + 6, height - 175 + i * 40);
}
}


In Choice Class
Code:
(...)

public void draw (int x, int y) {
appeared = true;
choiceBtn = new GButton(pa, name, icon, 1, x, y, 245, 35);
choiceBtn.setImageAlign(GAlign.LEFT);
if (selected) choiceBtn.setColorScheme(GCScheme.GREEN_SCHEME);
else choiceBtn.setColorScheme(GCScheme.GREY_SCHEME);
}


When the object is not on the area of the screen it should be, I run:

In Activity Class
Code:
(...)

private void removeButtons() {
for (int i = 0; i < choices.size(); i++) {
Choice chTemp = (Choice) choices.get(i);
chTemp.removeButton();
}
}


In Choice Class
Code:
(...)

public void removeButton() {
if (appeared) choiceBtn.setVisible(false);
appeared = false;
}
Re: ControlP5: Buttons that are images
Reply #14 - Jun 9th, 2010, 4:00am
 
Made a change to this method:

Code:
(...)

public void draw (int x, int y) {
if (!appeared) {
choiceBtn = new GButton(pa, name, icon, 1, x, y, 245, 35);
choiceBtn.setImageAlign(GAlign.LEFT);
if (selected) choiceBtn.setColorScheme(GCScheme.GREEN_SCHEME);
else choiceBtn.setColorScheme(GCScheme.GREY_SCHEME);
}
appeared = true;
}


And it's working now Embarrassed sorry for the trouble
Pages: 1 2