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 & HelpPrograms › text buttons
Page Index Toggle Pages: 1
text buttons (Read 605 times)
text buttons
May 21st, 2006, 3:29pm
 
ive looked through the examples and havent seen any which discuss text buttons. ive developed a project interface with a number of buttons in processing, and id like to place text on the buttons to inform of the button function. is there a tutorial i could follow on this?

cheers
Re: text buttons
Reply #1 - May 21st, 2006, 4:27pm
 
Markavian has a library you could use to save yourself a lot of hassle.

The other option is that you have to write out the code all yourself. This is tiresome but once you have the interface buttons you want you can always port them from project to project.
Code:

PFont font;
Button button;
void setup(){
size(200,200);
font = loadFont("ArialMT-20.vlw");
textFont(font, 20);
button = new Button(50, 50, "my Button");
}
void draw(){
background(150);
button.draw();
}
void mousePressed(){
if(button.over()){
println("Whoo clicky!");
}
}
class Button{
int x,y;
String label;
Button(int x, int y, String label){
this.x = x;
this.y = y;
this.label = label;
}
void draw(){
fill(200);
if(over()){
fill(255);
}
rect(x, y, textWidth(label), 25);
fill(0);
text(label, x, y + 20);
}
boolean over(){
if(mouseX >= x && mouseY >= y && mouseX <= x + textWidth(label) && mouseY <= y + 22){
return true;
}
return false;
}
}
Page Index Toggle Pages: 1