class Menu { String name; int item; int x; int y; boolean dropDown; public Menu(String name, int x, int y, int item) { this.name = name; this.item = item; this.x = x; this.y = y; this.dropDown = false; } void draw() { rectMode(CORNER); textAlign(LEFT, CENTER); text(name + "-axis:", x, y); strokeWeight(1); fill(255); rect(x + 10, y + 10, 130, 20); fill(0); textAlign(LEFT, TOP); text(menuItems[item], x + 15, y + 15); if (dropDown) drawDropDown(); } void drawDropDown() { dropDown = true; // draw all buttons strokeWeight(1); fill(255); rect(x + 10, y + 30, 130, menuItemCount * 20); fill(0); textAlign(LEFT, TOP); for (int i = 0; i < menuItemCount; i++) { text(menuItems[i], x + 15, y + 35 + i * 20); } } int getItem() { return item; } boolean clicked() { return (mouseX > x) && (mouseX < x + 130) && (mouseY > y + 10) && (mouseY < y + 30); } boolean isDropDown() { return dropDown; } void closeDropDown() { dropDown = false; // pick new menu item if ((mouseX > x + 5) && (mouseX < x + 130) && (mouseY > y + 30) && (mouseY < y + 30 + menuItemCount * 20)) { item = (mouseY - y - 30) / 20; // recalculate stats if (name.equals("x")) { xStats.calculate(xMenu.getItem()); xAxisMin = xStats.getMin(); xAxisMax = xStats.getMax(); } if (name.equals("y")) { yStats.calculate(yMenu.getItem()); yAxisMin = yStats.getMin(); yAxisMax = yStats.getMax(); } // reset zoom if (zoomOutButton.isDisplay()) zoomOutButton.reset(); } } }