Permalink
Cannot retrieve contributors at this time
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?
RangeSearch/kdtest/Menu.pde
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
72 lines (63 sloc)
1.76 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
} | |
} | |
} |