GoogleCodeArchive / piccolo2d

Automatically exported from code.google.com/p/piccolo2d
0 stars 0 forks source link

Invisible nodes are reported to be picked by InputEventHandler #113

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a Canvas with two layers, each Layer containing a node. Both
nodes have the same bounds.
2. set the second (top) layer to be invisible. 
3. add an InputEventListener to the root Layer, override the mouseClicked
method and print out event.getPickedNode() 
4. click on the Node

What is the expected output? What do you see instead?
I'd expect to be informed that the node from the visible bottom layer is
picked. Instead the invisible (by inheritance) node from the top layer is
being picked. 

Original issue reported on code.google.com by matthias...@gmail.com on 29 Jul 2009 at 12:41

GoogleCodeExporter commented 9 years ago
Here's a proposed fix:

### Eclipse Workspace Patch 1.0
#P piccolo2d-core
Index: src/main/java/edu/umd/cs/piccolo/PNode.java
===================================================================
--- src/main/java/edu/umd/cs/piccolo/PNode.java (revision 617)
+++ src/main/java/edu/umd/cs/piccolo/PNode.java (working copy)
@@ -2722,7 +2722,7 @@
      * @return true if this node or one of its descendents was picked.
      */
     public boolean fullPick(final PPickPath pickPath) {
-        if ((getPickable() || getChildrenPickable()) && 
fullIntersects(pickPath.getPickBounds())) {
+        if (getVisible() && (getPickable() || getChildrenPickable()) && 
fullIntersects(pickPath.getPickBounds())) {
             pickPath.pushNode(this);
             pickPath.pushTransform(transform);

Index: src/test/java/edu/umd/cs/piccolo/PNodeTest.java
===================================================================
--- src/test/java/edu/umd/cs/piccolo/PNodeTest.java (revision 617)
+++ src/test/java/edu/umd/cs/piccolo/PNodeTest.java (working copy)
@@ -29,6 +29,7 @@
 package edu.umd.cs.piccolo;

 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.GraphicsEnvironment;
 import java.awt.geom.AffineTransform;
@@ -52,6 +53,7 @@
 import edu.umd.cs.piccolo.activities.PTransformActivity;
 import edu.umd.cs.piccolo.activities.PColorActivity.Target;
 import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
+import edu.umd.cs.piccolo.event.PInputEvent;
 import edu.umd.cs.piccolo.util.PAffineTransform;
 import edu.umd.cs.piccolo.util.PAffineTransformException;
 import edu.umd.cs.piccolo.util.PBounds;
@@ -1290,4 +1292,25 @@
         node.setOccluded(true);
         assertTrue(node.getOccluded());
     }
+    
+    public void testHiddenNodesAreNotPickable() {
+        PCanvas canvas = new PCanvas();        
+        canvas.setBounds(0, 0, 400, 400);
+        canvas.setPreferredSize(new Dimension(400, 400));        
+        PNode node1 = new PNode();
+        node1.setBounds(0, 0, 100, 100);
+        node1.setPaint(Color.RED);
+        canvas.getLayer().addChild(node1);        
+        
+        PNode node2 = (PNode) node1.clone();
+        node2.setPaint(Color.BLUE);
+        
+        PLayer layer2 = new PLayer();        
+        layer2.addChild(node2);
+        layer2.setVisible(false);
+        canvas.getCamera().addLayer(layer2);
+        
+        PPickPath path = canvas.getCamera().pick(5, 5, 5);
+        assertSame(node1, path.getPickedNode());             
+    }
 }

Original comment by allain.lalonde on 29 Jul 2009 at 7:07

GoogleCodeExporter commented 9 years ago
Fixed in r622

Original comment by allain.lalonde on 29 Jul 2009 at 7:37

GoogleCodeExporter commented 9 years ago

Original comment by mr0...@mro.name on 29 Jul 2009 at 8:13