为什么下面的示例中没有出现第一个和第三个矩形?
看上去长方形一旦有零大小就坏了。
package tests.piccolo;
import org.piccolo2d.extras.PFrame;
import org.piccolo2d.nodes.PPath;
public class Try_EmptyRectangle {
public static void main(String[] args) {
new PFrame() {
@Override
public void initialize() {
PPath rect1 = PPath.createRectangle(0, 0, 0, 0);
PPath rect2 = PPath.createRectangle(0, 100, 1, 1);
PPath rect3 = PPath.createRectangle(0, 200, 1, 1);
getCanvas().getLayer().addChild(rect1);
getCanvas().getLayer().addChild(rect2);
rect1.setWidth(50);
rect1.setHeight(50);
rect2.setWidth(50);
rect2.setHeight(50);
rect3.setWidth(0);
rect3.setHeight(0);
rect3.setWidth(50);
rect3.setHeight(50);
}
};
}
}发布于 2015-02-10 08:05:36
这看起来像个窃听器。PPath内部封装GeneralPath。PPath.createRectangle(0, 0, 0, 0)将GeneralPath初始化为零大小矩形形状。然后,更改PPath宽度/高度将触发边界更改。PPath重写internalUpdateBounds(),以便缩放路径以适应指定的边界。零大小路径似乎存在一个问题:
protected void internalUpdateBounds(final double x, final double y, final double width, final double height) {
final Rectangle2D pathBounds = path.getBounds2D();
...
final double scaleX;
if (adjustedWidth == 0 || pathBounds.getWidth() == 0) {
scaleX = 1;
}
...
final double scaleY;
if (adjustedHeight == 0 || pathBounds.getHeight() == 0) {
scaleY = 1;
}
...
TEMP_TRANSFORM.scale(scaleX, scaleY);
...
path.transform(TEMP_TRANSFORM);
}scaleX和scaleY总是1,因此路径实际上从来没有缩放,并且保持为零大小。
https://stackoverflow.com/questions/28410670
复制相似问题