经过一番尝试,我通过编辑 gwt-g2d 源找到了解决方案。
gwt-g2d 为每个 Surface 创建一个带有画布的 div。现在我将 Surface 更改为仅创建具有位置:绝对的画布。现在我只是创建多个画布并使用它的函数 IsPointInPath。
Surface.java 中的更改:
public Surface(int width, int height) {
canvas = Document.get().createElement("canvas").cast();
setElement(Document.get().createDivElement());
getElement().appendChild(canvas);
canvasInitializer.init(canvas, width, height);
setStylePrimaryName("g2d-Surface");
this.width = width;
this.height = height;
context = canvas.getContext2D();
}
至:
public Surface(int width, int height) {
canvas = Document.get().createElement("canvas").cast();
canvas.setAttribute("style", "position:absolute;");
setElement(canvas);
canvasInitializer.init(canvas, width, height);
setStylePrimaryName("g2d-Surface");
this.width = width;
this.height = height;
context = canvas.getContext2D();
}