-
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.
Rebuilt Menu and Buttons so that Menu and Selector are no seperate, a…
…nd buttons work as a toggle group, and they're prettier and more flexable.
- Loading branch information
Showing
7 changed files
with
261 additions
and
188 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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
class CirSHandler implements ButtonHandler{ | ||
void Selected() { | ||
selector.setSelectMode(1); | ||
useSelector = true; | ||
} | ||
} | ||
|
||
class RectSHandler implements ButtonHandler{ | ||
void Selected() { | ||
selector.setSelectMode(0); | ||
useSelector = true; | ||
} | ||
} | ||
class PanHandler implements ButtonHandler{ | ||
void Selected() { | ||
cam.setMode(0); | ||
useSelector = false; | ||
} | ||
} | ||
|
||
class RotHandler implements ButtonHandler{ | ||
void Selected() { | ||
cam.setMode(1); | ||
useSelector = false; | ||
} | ||
} | ||
|
||
class PlaceHandler implements ButtonHandler{ | ||
void Selected() { | ||
selector.setSelectMode(3); | ||
useSelector = true; | ||
} | ||
} | ||
|
||
interface ButtonHandler { | ||
void Selected (); | ||
} | ||
|
||
class Button { | ||
int _x; | ||
int _y; | ||
int _w; | ||
int _h; | ||
int _r; | ||
boolean _isSel; | ||
String _label; | ||
ArrayList<ButtonHandler> _handlerList; | ||
|
||
Button (int x, int y, String label) { | ||
_x = x; | ||
_y = y; | ||
_w = i_buttonWidth; | ||
_h = i_buttonHeight; | ||
_r = i_buttonRad; | ||
_handlerList = new ArrayList<ButtonHandler> (); | ||
_label = label; | ||
_isSel = false; | ||
} | ||
|
||
boolean isMouseOver() { | ||
return mouseX >= _x && mouseX <= _x + _w && mouseY >= _y && mouseY <= _y + _h; | ||
} | ||
|
||
void Select() { | ||
_isSel = true; | ||
for(ButtonHandler h: _handlerList) { | ||
h.Selected(); | ||
} | ||
} | ||
|
||
void unSelect() { | ||
_isSel = false; | ||
} | ||
|
||
void draw () { | ||
pushStyle(); | ||
stroke(c_buttonStr); | ||
if(_isSel) { | ||
fill(c_buttonSel); | ||
} else { | ||
fill(c_buttonDef); | ||
} | ||
rect(_x, _y, _w, _h, 0, _r, _r, 0); | ||
if(_isSel) { | ||
fill(c_WHITE); | ||
} else { | ||
fill(c_BLACK); | ||
} | ||
textSize(20); | ||
text(_label, _x + 3, _y + _h - 10); | ||
popStyle(); | ||
} | ||
|
||
void addHandler (ButtonHandler h) { | ||
_handlerList.add(h); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,91 @@ | ||
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)); } | ||
void draw(){ | ||
for(Button b: _buttonList) { | ||
b.draw(); | ||
} | ||
} | ||
|
||
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 | ||
boolean mousePressed(){ | ||
boolean result = false; | ||
for(Button b: _buttonList) { | ||
boolean check = b.isMouseOver(); | ||
if(check) { | ||
result = true; | ||
for(Button b0: _buttonList) { | ||
b0.unSelect(); | ||
} | ||
b.Select(); | ||
break; | ||
} | ||
} | ||
return 99; | ||
return result; | ||
} | ||
|
||
void draw(){ | ||
pushStyle(); | ||
for(int i=0; i<4; i++){ _buttonList.get(i).draw(); } | ||
popStyle(); | ||
_selector.draw(); | ||
void mouseDragged() { | ||
selector.stretchSelection(); | ||
} | ||
|
||
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 mouseReleased() { | ||
selector.resetSelection(); | ||
} | ||
|
||
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 makeButtons() { | ||
int y = 50; | ||
Button cirS = new Button (0, y, "Circ Sel"); | ||
y += i_buttonHeight + 10; | ||
_buttonList.add(cirS); | ||
cirS.addHandler(new CirSHandler()); | ||
|
||
Button rectS = new Button (0, y, "Rect Sel"); | ||
y += i_buttonHeight + 10; | ||
_buttonList.add(rectS); | ||
rectS.addHandler(new RectSHandler()); | ||
|
||
Button pan = new Button (0, y, "Pan"); | ||
y += i_buttonHeight + 10; | ||
_buttonList.add(pan); | ||
pan.addHandler(new PanHandler()); | ||
|
||
Button rot = new Button (0, y, "Rotate"); | ||
y += i_buttonHeight + 10; | ||
_buttonList.add(rot); | ||
rot.addHandler(new RotHandler()); | ||
|
||
Button place = new Button (0, y, "Place"); | ||
y += i_buttonHeight + 10; | ||
_buttonList.add(place); | ||
place.addHandler(new PlaceHandler()); | ||
place.Select(); | ||
} | ||
|
||
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: | ||
} | ||
} | ||
} | ||
|
||
void drawHelpMenu() { | ||
float hwidth = 400; | ||
float hheight = 600; | ||
|
||
pushStyle(); | ||
strokeWeight (i_helpStrokeWidth); | ||
stroke(c_helpStroke); | ||
fill(c_helpBackground); | ||
rect(width/2 - hwidth/2, height/2 - hheight/2, hwidth, hheight, 50, 50, 50, 50); | ||
textSize(40); | ||
fill(c_helpText); | ||
text("Help:", width/2 - 50, height/2 - hheight/2 + 50); | ||
textSize (30); | ||
float x = width/2 - 150; | ||
float y = height/2 - hheight/2 + 100; | ||
for (int i = 0; i < i_helpStrings; i++) { | ||
text(s_helpStrings[i], x, y); | ||
y += 35; | ||
} | ||
popStyle(); | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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.