Skip to content

Commit

Permalink
integrated selector and menu into kdtest and added a tree container t…
Browse files Browse the repository at this point in the history
…o clean up some code
  • Loading branch information
laa11004 committed Dec 5, 2015
1 parent 17baa76 commit fc11565
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
14 changes: 7 additions & 7 deletions kdtest/Menu.pde
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class Menu{
Selector _selector;
Menu(){
selector = new Selector();
_selector = new Selector();
}

void activate(int button){
selector.setSelectMode(button);
_selector.setSelectMode(button);
}

int onaButton(int x, int y){
Expand All @@ -27,16 +27,16 @@ class Menu{
ellipse(0.0,52.0,60.0,25.0);//NN icon
rect(0,78,60,25,0,7,7,0);//InserPoint button
popStyle();
selector.draw();
_selector.draw();
}

void mousePressed(){
int button = onaButton(mouseX,mouseY);
if( button != 0 ){ activate(button); }
else{ selector.mousePressed(); }
else{ _selector.mousePressed(); }
}

void mouseDragged(){ selector.stretchSelection(); }
void mouseDragged(){ _selector.stretchSelection(); }

void mouseReleased(){ selector.resetSelection(); }
}
void mouseReleased(){ _selector.resetSelection(); }
}
3 changes: 2 additions & 1 deletion kdtest/Properties.pde
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ color c_BLACK = color (0, 0, 0);
color c_PROCBLUE = color (5,13,22);
color c_LIGHTBLUE = color (0, 215, 255);
color c_YELLOW = color (215, 255, 0);
color c_HILITE = color (251, 255, 20, 100);//selector filling

// Screen Color
color c_background = color (26, 26, 26);
Expand Down Expand Up @@ -44,4 +45,4 @@ String[] s_helpStrings = {
"a: Place Point",
"g: Select Point",
"c: Clear Points"
};
};
4 changes: 2 additions & 2 deletions kdtest/Selector.pde
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Selector{
break;
case 4: Point p = cam.transform(new Point(mouseX, mouseY)); //place point
pointList.add(p);
tree.insert(p);
pot.insert(p);
}
}

Expand Down Expand Up @@ -95,4 +95,4 @@ class Selector{
_searching = false;
}
}
}
}
14 changes: 14 additions & 0 deletions kdtest/Tree.pde
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,18 @@ class KdTree {
float d = depth * 0.2;
return color((int)255*cos(d) * cos(d), (int)255*abs(sin(d + PI)), (int)255*abs(sin(d+0.5)));
}
}

class TreeContainer {
KdTree tree;
TreeContainer(){
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));}
}

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

ArrayList<Point> pointList;

Expand All @@ -11,20 +13,21 @@ int G_mode;
// 1 = SCALE
// 2 = PAN
// 3 = ROTATE
// 4 = PLACE
// 4 = PLACE [removed]
// 5 = SELECT

void setup() {
size(800,800);
background(120);
ellipseMode(CENTER);

menu = new Menu();
con = new Console();
cam = new Camera();
statusLine = new Mode();
pot = new TreeContainer();

pointList = new ArrayList<Point>();
tree = null;
//tree = null;

drawCon = false;
drawHelp = true;
Expand All @@ -41,13 +44,14 @@ void draw() {
cam.update();
if(drawGnoman) GnomanDraw(200);
if(drawTree && tree != null) {
tree.draw();
pot.draw();
}
for(Point p: pointList) {
p.draw();
}
popMatrix();

menu.draw();
if(drawCon) con.draw();

if (drawHelp) {
Expand Down Expand Up @@ -146,23 +150,16 @@ void GnomanDraw(int r) {
}

void mousePressed() {
if(G_mode == 4) {
Point p = cam.transform(new Point(mouseX, mouseY));
pointList.add(p);
if(tree != null) {
tree.insert(p);
}
if(tree == null) {
tree = new KdTree (p, true, 0, new BoundingBox(-width/2,width/2,-height/2,height/2));
}
}
cam.mousePressed();
if(mouseButton == LEFT){ menu.mousePressed(); }
if(mouseButton == RIGHT){ cam.mousePressed(); }
}

void mouseDragged() {
cam.mouseDragged();
if(mouseButton == LEFT){ menu.mouseDragged(); }
if(mouseButton == RIGHT){ cam.mouseDragged(); }
}

void mouseReleased() {
cam.mouseReleased();
if(mouseButton == LEFT){ menu.mouseReleased(); }
if(mouseButton == RIGHT){ cam.mouseReleased(); }
}

0 comments on commit fc11565

Please sign in to comment.