ok, i not know your project status,
but i think it’s worth to have a easy
TOGGLE button code ready.
// Basic Button Example / TOGGLE Version
//_________________________________________________________________ SETUP
void setup() {
size(200, 200);
}
//_________________________________________________________________ DRAW
void draw() {
background(200, 200, 0);
myButton();
}
//_________________________________________________________________ MOUSE pressed function
void mousePressed() {
left_mouse_click_button();
}
//_________________________________________________________________ YOUR code if button pressed
void user_on_button_click() {
bV = ! bV; // TOGGLE
println("button PV "+bV);
println("?what you want me to do now?");
}
//_________________________________________________________________ BUTTON ?TAB?
int bx=20, by=170, bw=60, bh=20; // button rectangle settings X,Y,W,H
int bts=15; // button text size
color bs = color(0, 50, 150); // stroke
color bf0 = color(0, 0, 200); // PV fill STOP
color bf1 = color(0, 200, 0); // PV fill RUN
color cshow = bf0; // selected PV color
color bt = color(200, 200, 0); // text
boolean benable=true; // false; // use button?
boolean bV = false; // true; // button status
String bT0 = "START"; // SP Text
String bT1 = "STOP"; // SP Text
String tshow = ""; // selected SP text temp
void myButton() {
if (benable) {
push();
stroke(bs);
strokeWeight(2);
cshow = ( bV) ? bf1 : bf0;
fill(cshow); // same if ( bV ) fill(bf1); else fill(bf0);
rect(bx, by, bw, bh);
fill(bt);
textSize(bts);
textAlign(CENTER);
tshow = ( bV ) ? bT1 : bT0; // same if ( bV ) tshow = bT1; else tshow = bT0;
text(tshow, bx+bw/2, by+bh/2+bts/2);
pop();
}
}
//_________________________________________________________________ mouse click left on button
void left_mouse_click_button() {
if (mouseButton == LEFT && overRect(bx, by, bw, bh) && benable ) user_on_button_click();
}
//_________________________________________________________________ mouse over rectangle yes/no
boolean overRect(int rx, int ry, int rwidth, int rheight) {
if (mouseX >= rx && mouseX <= rx+rwidth &&
mouseY >= ry && mouseY <= ry+rheight) return true;
return false;
}
/*
// Basic Button Example
//_________________________________________________________________ SETUP
void setup() {
size(200, 200);
}
//_________________________________________________________________ DRAW
void draw() {
background(200, 200, 0);
myButton();
}
//_________________________________________________________________ MOUSE pressed function
void mousePressed() {
left_mouse_click_button();
}
//_________________________________________________________________ YOUR code if button pressed
void user_on_button_click() {
println("what you want me to do now?");
}
//_________________________________________________________________ BUTTON ?TAB?
int bx=20, by=170, bw=60, bh=20; // button rectangle settings X,Y,W,H
color bs = color(0, 50, 150); // stroke
color bf = color(0, 200, 200); // fill
color bt = color(0, 0, 200); // text
boolean benable=true; // false; // use button?
String bT = "click me"; // Text
void myButton() {
if (benable) {
push();
stroke(bs);
strokeWeight(2);
fill(bf);
rect(bx, by, bw, bh);
fill(bt);
text(bT, bx+5, by+15);
pop();
}
}
//_________________________________________________________________ mouse click left on button
void left_mouse_click_button() {
if (mouseButton == LEFT && overRect(bx, by, bw, bh) && benable ) user_on_button_click();
}
//_________________________________________________________________ mouse over rectangle yes/no
boolean overRect(int rx, int ry, int rwidth, int rheight) {
if (mouseX >= rx && mouseX <= rx+rwidth &&
mouseY >= ry && mouseY <= ry+rheight) return true;
return false;
}
*/