gpt4 book ai didi

java - 如何在Piccolo2D中精细控制可拾取性?

转载 作者:行者123 更新时间:2023-11-30 04:07:12 26 4
gpt4 key购买 nike

在下面的代码中,绘制了两个圆圈,并将其添加到一个分组节点。

观察到以下行为变体:

1) 可以拖动圆的任意点,包括外部和内部;如果通过圆间点拖动,则不会发生拖动

2) 只能通过外部拖动

3) 无法拖动

4) 能够拖动扩展范围内的任意点

任何行为均由 subinitialize() 参数启动。

我想知道,是否可以微调节点的 Activity “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());
}

}
};
}
}

最佳答案

苏珊,

看看 Piccolo 如何管理输入事件,最明智的做法是为每个节点组创建一个特定的事件处理程序。 piccolo 仅在 PNode 级别为您提供通用输入处理程序。这使得所有 PNode 事件实际上相同。如果要为每个节点(或组)定义不同的行为,则需要派生一个类(例如从 PNode 或 PPath)并添加逻辑来检测单击了哪个节点组并根据 subInitialize 中传递的设置进行拖动。

Java 的伟大之处在于您可以轻松扩展 Piccolo 等库来满足您自己的目的。

关于java - 如何在Piccolo2D中精细控制可拾取性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20477952/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com