在下面的代码中,绘制了两个圆圈,并添加到一个分组节点。
观察到以下行为变体:
1) 可以拖动圆的任意一点,包括外部和内部;如果通过圆间点拖动,则不会发生拖动
2)只能通过外部拖动
3) 无法拖动
4) 能够在扩展范围内拖动任意点
任何行为都是由subinitialize()
参数发起的。
我想知道,是否可以微调节点的活动“pickeble”点?例如,我是否可以让子节点不可拾取,但让整个组只能被圆圈外部拖动,就像情况 (2) 一样?
之所以需要,是因为 Piccolo 不允许确定单击是在哪个组对象中进行的。特别是,我无法确定连接到哪个侦听器的组节点,所以如果我有单个侦听器并将其附加到多个节点,我将无法区分调用了哪个。
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());
}
}
};
}
}