Lenticular
YaBB Newbies
Offline
Posts: 36
Re: Can I call a class from within a class?
Reply #4 - Sep 4th , 2009, 2:02pm
Thanks. I will try to down load and have a look at that menu code. I booked marked both those sites and will likely refer to them in the future more after I get some experience with processing. I don't think I have ever seen any large or sophisticated program made with processing. I wish there was a site where people posted their processing programs to be down loaded along with the source code so people could learn from each other. Maybe it will help to illustrate the growing complexity of my one class if I post the code. By the way; Blindfish helped me with the creation of the sub-menu. If I were to add a few more sub-menus or a sub-sub-menus, this one class would get very confusing to work on. I thought I could combine some of this into separate objects or classes and store them on different tabs. Menu menu; boolean button = false; boolean submenu = false; void setup() { size(300,300); menu = new Menu(); } void draw() { background(180); menu.display_gui(); menu.display_menu(); } void mouseClicked() { menu.mouseClicked(); } class Menu { void display_gui() { //upper blue button fill (140,160,220); if (mouseX > 10 && mouseX < 110 && mouseY > 10 && mouseY < 30) { fill(150,190,250); } rect(10,10,100,20); } void display_menu() { if (button) { fill(255); rect(10,30,100,150); // white menu fill (140,160,220); if (mouseX > 10 && mouseX < 110 && mouseY > 100 && mouseY < 120) { fill(150,190,250); } rect(10,100,100,20); // lower blue button // check that the mouse is hovering over the second button if (mouseX > 10 && mouseX < 110 && mouseY > 100 && mouseY < 120) { // if it is set the boolean variable to true submenu = true; } // If the boolean is true we can display the submenu if (submenu) { fill(255); rect(110,100,100,150); if (! (mouseX>=110 && mouseX<210 && mouseY>100 && mouseY<250 || mouseX > 10 && mouseX < 110 && mouseY > 100 && mouseY < 120) ){ // If it does we set the boolean to false and the submenu is hidden submenu = false; } } } void mouseClicked() { if (mouseX > 10 && mouseX < 110 && mouseY > 10 && mouseY < 30) { button = !button; } } }