在下面的示例代码中(来自https://github.com/piccolo2d/piccolo2d.java/tree/master/examples/src/main/java/org/piccolo2d/examples的修改TooltipExample.java),我在里面创建了一条曲线一个矩形。这条曲线包含的区域/边界似乎不是沿着曲线,而是以灰色突出显示的部分。我试图找出是否有一种方法可以仅沿曲线显示曲线的工具提示。我尝试重置底层 PBounds,但没有运气。有谁知道如何实现这一目标?
import org.piccolo2d.PCamera;
import org.piccolo2d.PCanvas;
import org.piccolo2d.PNode;
import org.piccolo2d.event.PBasicInputEventHandler;
import org.piccolo2d.event.PInputEvent;
import org.piccolo2d.extras.PFrame;
import org.piccolo2d.nodes.PPath;
import org.piccolo2d.nodes.PText;
import java.awt.*;
import java.awt.geom.Point2D;
/**
* Simple example of one way to add tooltips
*
* @author jesse
*/
public class TooltipExample extends PFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public TooltipExample() {
this(null);
}
public TooltipExample(final PCanvas aCanvas) {
super("TooltipExample", false, aCanvas);
}
public void initialize() {
final PNode n1 = PPath.createEllipse(0, 0, 100, 100);
final PNode n2 = PPath.createRectangle(300, 200, 100, 100);
PPath curve = new PPath.Float();
curve.moveTo(318.0,222.0);
curve.curveTo(318.0,222.0, 375.0,228.0, 352.0,278.0);
curve.addAttribute("tooltip","Curve");
curve.setPaint(Color.GRAY);
n1.addAttribute("tooltip", "node 1");
n2.addAttribute("tooltip", "node 2");
getCanvas().getLayer().addChild(n1);
getCanvas().getLayer().addChild(n2);
getCanvas().getLayer().addChild(curve);
final PCamera camera = getCanvas().getCamera();
final PText tooltipNode = new PText();
tooltipNode.setPickable(false);
camera.addChild(tooltipNode);
camera.addInputEventListener(new PBasicInputEventHandler() {
public void mouseMoved(final PInputEvent event) {
updateToolTip(event);
}
public void mouseDragged(final PInputEvent event) {
updateToolTip(event);
}
public void mouseClicked(final PInputEvent event) {
final Point2D p = event.getCanvasPosition();
System.out.println(p.getX()+","+p.getY());
}
public void updateToolTip(final PInputEvent event) {
final PNode n = event.getPickedNode();
final String tooltipString = (String) n.getAttribute("tooltip");
final Point2D p = event.getCanvasPosition();
event.getPath().canvasToLocal(p, camera);
tooltipNode.setText(tooltipString);
tooltipNode.setOffset(p.getX() + 8, p.getY() - 8);
}
});
}
public static void main(final String[] argv) {
new TooltipExample();
}
}
更大的图景:假设我们有许多这样的重叠曲线相互交叉。如果在这些曲线的巨大重叠区域之间放置了另一个较小的形状,我将无法获得该形状的任何事件。基本上我无法单击该形状。我将不胜感激任何解决此问题的建议。提前致谢。
编辑 1:添加新图片以进行问题阐述: