Skip to content

Commit

Permalink
updated how buttons are made to a list based implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
laa11004 committed Dec 6, 2015
1 parent fc11565 commit 39925cb
Show file tree
Hide file tree
Showing 5 changed files with 511 additions and 68 deletions.
67 changes: 49 additions & 18 deletions kdtest/Menu.pde
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:
}
}
}
29 changes: 17 additions & 12 deletions kdtest/Selector.pde
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Selector{
float _startX,_startY, _endX, _endY, _state;
int _startX,_startY, _endX, _endY;
float _state;
float _a, _b, _radius;
boolean _selecting, _animating, _searching;
int _select_mode;
Expand All @@ -11,7 +12,7 @@ class Selector{
_searching = false;
_a = 0;
_b = 0;
_select_mode = 1;
_select_mode = 0; //default is rectangular select
_endX = -1;
_endY = -1;
}
Expand All @@ -22,15 +23,15 @@ class Selector{
_startX = mouseX;
_startY = mouseY;
switch(_select_mode){
case 1: _selecting = true; //rectangular selection
case 0: _selecting = true; //rectangular selection
break;
case 2: _selecting = true; //ellipse selection
case 1: _selecting = true; //ellipse selection
break;
case 3: _searching = true; //nearest neighbor search
case 2: _searching = true; //nearest neighbor search
_state = 0.0;
_animating = true;
break;
case 4: Point p = cam.transform(new Point(mouseX, mouseY)); //place point
case 3: Point p = cam.transform(new Point(mouseX, mouseY)); //place point
pointList.add(p);
pot.insert(p);
}
Expand All @@ -39,9 +40,12 @@ class Selector{
void resetSelection(){//triggered on mouseReleased()
if(_selecting){ //selecting with rect or circle
switch(_select_mode){
case 1: //_tree.rectQuery(cam.transform(new Point(_startX,_startY)),cam.transform(new Point(_endX,_endY)));
break;
case 2: //_tree.circleQuery(cam.transform(new Point(_a,_b)),
case 0:
Point p1 = cam.transform(new Point(_startX, _startY));
Point p2 = cam.transform(new Point(_endX, _endY));
//pot._tree.query(new BoundingBox(p1._x, p1._y, p2._x, p2._y));
break;
case 1: //_tree.circleQuery(cam.transform(new Point(_a,_b)),
}
_selecting = false;
_startX = -1;
Expand All @@ -56,6 +60,7 @@ class Selector{
_a = 0;
_b = 0;
}

void stretchSelection(){
if(_selecting){
_endX = mouseX-_startX;
Expand All @@ -69,9 +74,9 @@ class Selector{
fill(c_HILITE);
if(_selecting){
switch(_select_mode){
case 1: rect(_startX,_startY,_endX,_endY);
case 0: rect(_startX,_startY,_endX,_endY);
break;
case 2: _a = mouseX-_startX;
case 1: _a = mouseX-_startX;
_b = mouseY-_startY;
_radius = sqrt(_a*_a+_b*_b);
ellipseMode(RADIUS);
Expand All @@ -95,4 +100,4 @@ class Selector{
_searching = false;
}
}
}
}
15 changes: 9 additions & 6 deletions kdtest/Tree.pde
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,18 @@ class KdTree {
}

class TreeContainer {
KdTree tree;
KdTree _tree;
TreeContainer(){
tree = null;
_tree = null;
}

void insert(Point p){
if(tree != null) { tree.insert(p); }
else { tree = new KdTree (p, true, 0, new BoundingBox(-width/2,width/2,-height/2,height/2));}
if(_tree != null) { _tree.insert(p); }
else { _tree = new KdTree (p, true, 0, new BoundingBox(-width/2,width/2,-height/2,height/2));}
}

KdTree getTree(){ return _tree;}
void clearTree(){ _tree = null; }

void draw(){ tree.draw(); }
}
void draw(){ _tree.draw(); }
}
14 changes: 6 additions & 8 deletions kdtest/kdtest.pde
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Console con;
Camera cam;
Mode statusLine;
KdTree tree;
//KdTree tree;
TreeContainer pot;//or tree
Menu menu;

Expand Down Expand Up @@ -43,7 +43,7 @@ void draw() {
pushMatrix();
cam.update();
if(drawGnoman) GnomanDraw(200);
if(drawTree && tree != null) {
if(drawTree && pot.getTree() != null) {
pot.draw();
}
for(Point p: pointList) {
Expand Down Expand Up @@ -92,7 +92,7 @@ void keyPressed() {
case 'c':
case 'C':
pointList.clear();
tree = null;
pot.clearTree();
break;
case 'h':
case 'H':
Expand All @@ -109,7 +109,7 @@ void keyPressed() {
case '1':
BoundingBox test2 = new BoundingBox(-width/2,width/2,-height/2,height/2);
test2.draw();
ArrayList<Point> pl = tree.query(test2);
ArrayList<Point> pl = pot.getTree().query(test2);
println(pl.size());
break;
}
Expand Down Expand Up @@ -137,9 +137,7 @@ void drawHelpMenu() {
popStyle();
}

void checkSelect() {

}
void checkSelect() {}

void GnomanDraw(int r) {
pushStyle();
Expand All @@ -162,4 +160,4 @@ void mouseDragged() {
void mouseReleased() {
if(mouseButton == LEFT){ menu.mouseReleased(); }
if(mouseButton == RIGHT){ cam.mouseReleased(); }
}
}
Loading

0 comments on commit 39925cb

Please sign in to comment.