官术网_书友最值得收藏!

Paths

Path is a metashape. You can merge any combination of shape-like PathElement objects into one Path and use the result as a single shape.

The following PathElement classes are supported in JavaFX 9:

ArcTo, ClosePath, CubicCurveTo, HLineTo, LineTo, MoveTo, QuadCurveTo, VLineTo

Their parameters mostly resemble corresponding shapes, except ClosePath, which is a marker of the path end.

Here is an example:

Take a look at the following code snippet:

// chapter2/shapes/PathDemo.java
ArcTo arcTo = new ArcTo();
arcTo.setRadiusX(250);
arcTo.setRadiusY(90);
arcTo.setX(50);
arcTo.setY(100);
arcTo.setSweepFlag(true);

Path path = new Path(
new MoveTo(0, 0),
new HLineTo(50),
arcTo, // ArcTo is set separately due to its complexity
new VLineTo(150),
new HLineTo(0),
new ClosePath()
);

SVGPath is similar to Path, but it uses text commands instead of code elements. These commands are not specific to JavaFX, they are part of Scalable Vector Graphics specification. So, you can reuse existing SVG shapes in JavaFX:

SVGPath svgPath = new SVGPath();
svgPath.setContent("M0,0 H50 A250,90 0 0,1 50,100 V150 H0 Z");
// SVG notation help:
// M - move, H - horizontal line, A - arc
// V - vertical line, Z - close path
svgPath.setFill(Color.DARKGREY);

This is the result:

By comparing Path and SVGPath, you can see a certain resemblance. It explains an odd, at first, choice of PathElement objects—they were mimicked after SVG ones.

主站蜘蛛池模板: 赤城县| 宁武县| 奉节县| 石城县| 都江堰市| 正镶白旗| 凉城县| 平湖市| 枣阳市| 固镇县| 秀山| 江北区| 壤塘县| 班戈县| 自贡市| 蒙山县| 遂川县| 宁陕县| 博客| 汤原县| 鹤岗市| 霸州市| 门源| 彩票| 景泰县| 博白县| 溧水县| 屯留县| 肥城市| 新晃| 安达市| 来凤县| 祁连县| 长宁区| 荔波县| 土默特右旗| 上林县| 平顺县| 沭阳县| 望城县| 农安县|