Skip to content
Permalink
b9087497bc
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
72 lines (63 sloc) 1.76 KB
class Menu{
ArrayList<Button> _buttonList;
Selector _selector;
Menu(){
_selector = new Selector();
_buttonList = new ArrayList<Button>();
makeButtons();
}
void activate(int button){ _selector.setSelectMode(button); }
void makeButtons(){
_buttonList.add(new Button(0,0,0)); //adds the first button
for( int i = 1; i < 4; i++){ _buttonList.add(new Button(0,i*25+1,i)); }
}
int onaButton(int x, int y){
int i;
for( i = 0; i < 4; i++){ //loop checks if any button was clicked
if(_buttonList.get(i).isInside(x,y)) { return i; } //and returns the _id if one was in fact clicked
}
return 99;
}
void draw(){
pushStyle();
for(int i=0; i<4; i++){ _buttonList.get(i).draw(); }
popStyle();
_selector.draw();
}
void mousePressed(){
int button = onaButton(mouseX,mouseY); //which button is selected
if( button != 99 ){ activate(button); } //99 is an arbitrary invalid button _id
else{ _selector.mousePressed(); }
}
void mouseDragged(){ _selector.stretchSelection(); }
void mouseReleased(){ _selector.resetSelection(); }
}
class Button{
int _x1, _y1, _x2, _y2, _id;
Button(int x,int y, int id){
_x1 = x;
_y1 = y;
_x2 = 60;
_y2 = 24;
_id = id;
}
boolean isInside(int x, int y){
if( x>=_x1 && x<=_x2 && y>_y1 && y<=_y1+_y2){ return true; }
else{ return false; }
}
void draw(){
rect(_x1,_y1,_x2,_y2,0,7,7,0);//basic button shape
switch(_id){
case 0: rect(_x1+_x2/2,_y1+5,10,10);//rect icon
break;
case 1: ellipseMode(CORNER);
//ellipse(0.0,26.0,60.0,25.0);//circle icon
break;
case 2: //ellipse(0.0,52.0,60.0,25.0);//NN icon
break;
case 3:
break;
default:
}
}
}