1

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());
                }

            }
        };
    }
}
Charles
  • 50,943
  • 13
  • 104
  • 142
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

1 Answers1

2

Suzan,

Looking at how Piccolo manages input events the most sensible thing would be to create a specific event handler for each of your node groups. The piccolo only provides you with a generic input handler at the PNode level. This renders all PNode events effectively the same. If you want to define different behavior per node (or group) you'll need to derive a class (for instance from PNode or PPath) and add the logic to detect which node group was clicked and drag according to the settings passed in subInitialize.

The great thing about Java is that you can easily extend libraries like Piccolo to suit your own purpose.