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.
Page Index Toggle Pages: 1
Button Matrix (Read 234 times)
Button Matrix
Feb 16th, 2009, 11:24pm
 
Hi,

im trying to create a button matrix. I created a class called button and putted the whole if(mousePressed) thing in that class. When i only have one button its working! but when i create a for loop for my button it making a weird bug.
here goes my code with the for structure and see what is happening:

color c = 255;
void setup() {
 size(400,400);
 smooth();
 rectMode(CENTER);
}

void draw() {
 for(int i = 45; i < 400; i = i+75) {
 for(int j = 45; j < 400; j = j+75) {
 button(i,j,50,50);
 }}
}

void button(int x, int y, int w, int h) {
 strokeWeight(5);
 fill(c);
 rect(x,y,w,h);
 
if(mousePressed == true && mouseX <= x + w/2 && mouseX >= x - w/2 && mouseY >= y - h/2 && mouseY <= y + h/2) {
  c = 100;
} else {
 c = 255;
}
}

please have a look at it and see what you guys can do... you know... im a noob....
Re: Button Matrix
Reply #1 - Feb 17th, 2009, 3:33am
 
You draw before you fill, so the next one gets filled. thats it... easy to fix :)


color c = 255;
void setup() {
 size(400,400);
 smooth();
 rectMode(CENTER);
}

void draw() {
 for(int i = 45; i < 400; i+=75) {
 for(int j = 45; j < 400; j+=75) {
 button(i,j,50,50);
 }}
}

void button(int x, int y, int w, int h) {
 if(mousePressed == true && mouseX <= x + w/2 && mouseX >= x - w/2 && mouseY >= y - h/2 && mouseY <= y + h/2) {
  c = 100;
} else {
 c = 255;
}
 
 strokeWeight(5);
 fill(c);
 rect(x,y,w,h);
 

}  
Re: Button Matrix
Reply #2 - Feb 17th, 2009, 9:23pm
 
Thanks you, now my buttons work great as momentaries, but i would like to make them to toggle on/off ...
i would need a void mousePressed but i cant switch my c value from my mousePressed void to my button void.... so it compile without errors but they just dont trun dark anymore =/

so i would like to know how to create a void mousePressed() wich change some values in my custom object(button).

Thanks for answers,
Odin
Page Index Toggle Pages: 1