From fc11565fbea933b1ebfc1e3feb1345bdac4afa73 Mon Sep 17 00:00:00 2001 From: laa11004 Date: Fri, 4 Dec 2015 22:10:24 -0500 Subject: [PATCH] integrated selector and menu into kdtest and added a tree container to clean up some code --- kdtest/Menu.pde | 14 +++++++------- kdtest/Properties.pde | 3 ++- kdtest/Selector.pde | 4 ++-- kdtest/Tree.pde | 14 ++++++++++++++ kdtest/kdtest.pde | 31 ++++++++++++++----------------- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/kdtest/Menu.pde b/kdtest/Menu.pde index 816c4b3..be75e9f 100644 --- a/kdtest/Menu.pde +++ b/kdtest/Menu.pde @@ -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){ @@ -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(); } +} \ No newline at end of file diff --git a/kdtest/Properties.pde b/kdtest/Properties.pde index 995b8a7..c078119 100644 --- a/kdtest/Properties.pde +++ b/kdtest/Properties.pde @@ -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); @@ -44,4 +45,4 @@ String[] s_helpStrings = { "a: Place Point", "g: Select Point", "c: Clear Points" -}; +}; \ No newline at end of file diff --git a/kdtest/Selector.pde b/kdtest/Selector.pde index 7268d49..328f721 100644 --- a/kdtest/Selector.pde +++ b/kdtest/Selector.pde @@ -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); } } @@ -95,4 +95,4 @@ class Selector{ _searching = false; } } -} +} \ No newline at end of file diff --git a/kdtest/Tree.pde b/kdtest/Tree.pde index d07e72e..cc4102b 100644 --- a/kdtest/Tree.pde +++ b/kdtest/Tree.pde @@ -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(); } } \ No newline at end of file diff --git a/kdtest/kdtest.pde b/kdtest/kdtest.pde index 3f46b73..d5acf30 100644 --- a/kdtest/kdtest.pde +++ b/kdtest/kdtest.pde @@ -2,6 +2,8 @@ Console con; Camera cam; Mode statusLine; KdTree tree; +TreeContainer pot;//or tree +Menu menu; ArrayList pointList; @@ -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(); - tree = null; + //tree = null; drawCon = false; drawHelp = true; @@ -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) { @@ -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(); } } \ No newline at end of file