In the code below, two circles are drawn, and added to one grouping node.
The following behavior variants observed:
1) Able to drag by any point of circle, including exterior and interior; if drag by intercircle point, drag does not occur
2) Able to drag only by exterior
3) Unable to drag
4) Able to drag by any point in extended bounds
Any behavior is inited by subinitialize()
params.
I wonder, is it possible to finetune active "pickeble" points of a node? For example, can I leave subnodes not pickable, but make the entire group is draggable by circles exteriors only, as it was in case (2)?
The need is required because Piccolo does not allow to determine, in which group object the click was made. Particularly, I can't determine the group node, to which listener were attached, so if I have single listener and attach it to multiple nodes, I won't be able to distinguish, which one was called.
public class Try_Picking_01 {
private static final Logger log = LoggerFactory.getLogger(Try_Picking_01.class);
public static void main(String[] args) {
new PFrame() {
final PNode group = new PNode();
@Override
public void initialize() {
group.addInputEventListener(new PBasicInputEventHandler() {
@Override
public void mouseDragged(PInputEvent event) {
PDimension dim = event.getDeltaRelativeTo(group.getParent());
group.offset(dim.getWidth(), dim.getHeight());
}
});
getCanvas().getLayer().addChild(group);
getCanvas().setPanEventHandler(null);
// able to drag by any point of circle, including exterior and interior
// if drag by intercircle point, drag does not occur
// subinitialize(false, true, false);
// able to drag only by exterior
//subinitialize(true, true, false);
// unable to drag
// subinitialize(true, false, false);
// able to drag by any point in extended bounds
subinitialize(true, false, true);
}
private void subinitialize(boolean emptyFill, boolean pickable, boolean expandBounds) {
PPath path1 = PPath.createEllipse(100, 100, 100, 100);
path1.setStrokePaint(Color.RED);
path1.setPaint( emptyFill ? null : Color.YELLOW ); // line #1
log.info("path1.bounds = {}", path1.getBounds());
path1.setPickable(pickable); // line #2
PPath path2 = PPath.createEllipse(200, 200, 100, 100);
path2.setPaint( emptyFill ? null : Color.YELLOW ); // line #3
log.info("path2.bounds = {}", path2.getBounds());
path2.setPickable(pickable); // line #4
group.addChild(path1);
group.addChild(path2);
log.info("group.bounds = {}", group.getBounds());
if( expandBounds ) {
group.setBounds(group.getFullBounds()); // line #5
log.info("group.bounds = {}", group.getBounds());
}
}
};
}
}