-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated how buttons are made to a list based implementation
- Loading branch information
Showing
5 changed files
with
511 additions
and
68 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,73 @@ | ||
class Menu{ | ||
ArrayList<Button> _buttonList; | ||
Selector _selector; | ||
Menu(){ | ||
_selector = new Selector(); | ||
_buttonList = new ArrayList<Button>(); | ||
makeButtons(); | ||
} | ||
|
||
void activate(int button){ | ||
_selector.setSelectMode(button); | ||
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){ | ||
if( 0<x && x<=60 && y>0 && y<=25){ return 1; } | ||
else if( 0<x && x<=60 && y>25 && y<=51){ return 2; } | ||
else if( 0<x && x<=60 && y>51 && y<=77){ return 3; } | ||
else if( 0<x && x<=60 && y>77 && y<=103){ return 4; } | ||
else { return 0; } | ||
int i; | ||
for( i = 0; i < 4; i++){ | ||
if(_buttonList.get(i).isInside(x,y)) { return i; } | ||
} | ||
return 99; | ||
} | ||
|
||
void draw(){ | ||
pushStyle(); | ||
rect(0,0,60,25,0,7,7,0);//rect button | ||
rect(15,20,5,10);//rect icon | ||
rect(0,26,60,25,0,7,7,0);//circle button | ||
ellipseMode(CORNER); | ||
ellipse(0.0,26.0,60.0,25.0);//circle icon | ||
rect(0,52,60,25,0,7,7,0);//NN button | ||
ellipse(0.0,52.0,60.0,25.0);//NN icon | ||
rect(0,78,60,25,0,7,7,0);//InserPoint button | ||
for(int i=0; i<4; i++){ _buttonList.get(i).draw(); } | ||
popStyle(); | ||
_selector.draw(); | ||
} | ||
|
||
void mousePressed(){ | ||
int button = onaButton(mouseX,mouseY); | ||
if( button != 0 ){ activate(button); } | ||
println("%d \n",button); | ||
if( button != 99 ){ activate(button); } //99 is an arbitrary invalid _id value | ||
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: | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.