improved menu
This commit is contained in:
78
buttons.pde
78
buttons.pde
@@ -1,78 +0,0 @@
|
||||
int buttonCount = 6;
|
||||
int i_buttonId;
|
||||
|
||||
void initButtons() {
|
||||
buttons[0] = new Button(10, 10, "Add Node");
|
||||
buttons[1] = new Button(104, 10, "Delete Node");
|
||||
buttons[2] = new Button(10, 50, "Dark/Bright Mode");
|
||||
buttons[3] = new Button(10, 90, "Save");
|
||||
buttons[4] = new Button(10, 130, "Open");
|
||||
buttons[5] = new Button(10, 170, "Export Image");
|
||||
/* buttons[0] = new Button(10, 10, "Node Hinzufügen");
|
||||
buttons[1] = new Button(155, 10, "Löschen");
|
||||
buttons[2] = new Button(10, 50, "Farben umkehren");
|
||||
buttons[3] = new Button(10, 90, "Speichern");
|
||||
buttons[4] = new Button(10, 130, "Öffnen");
|
||||
buttons[5] = new Button(10, 170, "Bild Exportieren");*/
|
||||
}
|
||||
|
||||
void buttonFunctions(int functionID) {
|
||||
switch (functionID) {
|
||||
case(0):
|
||||
addNode(int(random(50, width-50)), int(random(30, height-150)), "");
|
||||
i_selectedNode = nodeCount-1;
|
||||
break;
|
||||
case(1):
|
||||
deleteSelectedNode();
|
||||
break;
|
||||
case(2):
|
||||
darkMode = !darkMode;
|
||||
break;
|
||||
case(3):
|
||||
saveCSV(dataPath("save.csv"));
|
||||
selectOutput("Where to save .csv file to?", "saveCSVFile");
|
||||
break;
|
||||
case(4):
|
||||
selectInput("Select csv File", "loadCSVFile");
|
||||
break;
|
||||
case(5):
|
||||
selectOutput("Where to export .png image file to?", "savePNGFile");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Button buttons[] = new Button[buttonCount];
|
||||
|
||||
class Button {
|
||||
int id, x, y, w, h;
|
||||
String label;
|
||||
|
||||
boolean hover() {
|
||||
return (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) ? true : false;
|
||||
}
|
||||
|
||||
void click() {
|
||||
buttonFunctions(id);
|
||||
}
|
||||
Button(int x_, int y_, String label_) {
|
||||
id = i_buttonId;
|
||||
i_buttonId++;
|
||||
x = x_;
|
||||
y = y_ ;
|
||||
label = label_;
|
||||
w = int(textWidth(label))+18;
|
||||
h = 32;
|
||||
}
|
||||
|
||||
void display() {
|
||||
stroke(0);
|
||||
strokeWeight(1);
|
||||
fill(255, 127);
|
||||
rect(x, y, w, h, 4);
|
||||
fill(0);
|
||||
text(label, x+9, y+h/2+5);
|
||||
}
|
||||
}
|
||||
25
gui.pde
25
gui.pde
@@ -1,8 +1,14 @@
|
||||
int buttonCount = 8;
|
||||
int i_buttonId;
|
||||
boolean menuOpen = true;
|
||||
int[] menuButtons = {2, 3, 4, 5, 6};
|
||||
|
||||
|
||||
|
||||
void menu() {
|
||||
menuOpen = !menuOpen;
|
||||
for (int i = 0; i < menuButtons.length; i++) {
|
||||
buttons[menuButtons[i]].active = menuOpen;
|
||||
}
|
||||
}
|
||||
|
||||
void initButtons() {
|
||||
buttons[0] = new Button(72, 10, "Add Node");
|
||||
@@ -13,6 +19,7 @@ void initButtons() {
|
||||
buttons[5] = new Button(10, 170, "Export Image");
|
||||
buttons[6] = new Button(10, 210, "Empty Workspace");
|
||||
buttons[7] = new Button(10, 10, "Menu");
|
||||
menu();
|
||||
/* buttons[0] = new Button(10, 10, "Node Hinzufügen");
|
||||
buttons[1] = new Button(155, 10, "Löschen");
|
||||
buttons[2] = new Button(10, 50, "Farben umkehren");
|
||||
@@ -62,14 +69,16 @@ Button buttons[] = new Button[buttonCount];
|
||||
class Button {
|
||||
int id, x, y, w, h;
|
||||
String label;
|
||||
boolean active;
|
||||
|
||||
boolean hover() {
|
||||
return (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) ? true : false;
|
||||
return (active) ? ((mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) ? true : false) : false;
|
||||
}
|
||||
|
||||
void click() {
|
||||
buttonFunctions(id);
|
||||
}
|
||||
|
||||
Button(int x_, int y_, String label_) {
|
||||
id = i_buttonId;
|
||||
i_buttonId++;
|
||||
@@ -78,9 +87,11 @@ class Button {
|
||||
label = label_;
|
||||
w = int(textWidth(label))+18;
|
||||
h = 32;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void display() {
|
||||
if (active) {
|
||||
stroke(0);
|
||||
strokeWeight(1);
|
||||
fill(255, 127);
|
||||
@@ -89,12 +100,4 @@ class Button {
|
||||
text(label, x+9, y+h/2+5);
|
||||
}
|
||||
}
|
||||
|
||||
boolean menuOpen;
|
||||
|
||||
void menu() {
|
||||
if (menuOpen) {
|
||||
} else {
|
||||
}
|
||||
menuOpen = !menuOpen;
|
||||
}
|
||||
|
||||
@@ -57,13 +57,11 @@ void draw() {
|
||||
textAlign(CORNER);
|
||||
buttons[0].display();
|
||||
if (i_selectedNode != -1) buttons[1].display();
|
||||
if (menuOpen) {
|
||||
buttons[2].display();
|
||||
buttons[3].display();
|
||||
buttons[4].display();
|
||||
buttons[5].display();
|
||||
buttons[6].display();
|
||||
}
|
||||
buttons[7].display();
|
||||
rectMode(CENTER);
|
||||
textAlign(CENTER);
|
||||
|
||||
Reference in New Issue
Block a user