下面列出了怎么用javafx.scene.shape.CubicCurve的API类实例代码及写法,或者点击链接到github查看源代码。
public static Node createIconContent() {
CubicCurve cubicCurve = new CubicCurve();
cubicCurve.setStartX(0);
cubicCurve.setStartY(50);
cubicCurve.setControlX1(20);
cubicCurve.setControlY1(0);
cubicCurve.setControlX2(70);
cubicCurve.setControlY2(100);
cubicCurve.setEndX(80);
cubicCurve.setEndY(50);
cubicCurve.setStroke(Color.web("#b9c0c5"));
cubicCurve.setStrokeWidth(5);
cubicCurve.getStrokeDashArray().addAll(15d,15d);
cubicCurve.setFill(null);
javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
effect.setOffsetX(1);
effect.setOffsetY(1);
effect.setRadius(3);
effect.setColor(Color.rgb(0,0,0,0.6));
cubicCurve.setEffect(effect);
return cubicCurve;
}
public static Node createIconContent() {
CubicCurve cubicCurve = new CubicCurve();
cubicCurve.setStartX(0);
cubicCurve.setStartY(50);
cubicCurve.setControlX1(20);
cubicCurve.setControlY1(0);
cubicCurve.setControlX2(70);
cubicCurve.setControlY2(100);
cubicCurve.setEndX(80);
cubicCurve.setEndY(50);
cubicCurve.setStroke(Color.web("#b9c0c5"));
cubicCurve.setStrokeWidth(5);
cubicCurve.getStrokeDashArray().addAll(15d,15d);
cubicCurve.setFill(null);
javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
effect.setOffsetX(1);
effect.setOffsetY(1);
effect.setRadius(3);
effect.setColor(Color.rgb(0,0,0,0.6));
cubicCurve.setEffect(effect);
return cubicCurve;
}
public CubicCurveSample() {
super(180,90);
// Create cubicCurve shape
CubicCurve cubicCurve = new CubicCurve();
cubicCurve.setStartX(0);
cubicCurve.setStartY(45);
cubicCurve.setControlX1(30);
cubicCurve.setControlY1(10);
cubicCurve.setControlX2(150);
cubicCurve.setControlY2(80);
cubicCurve.setEndX(180);
cubicCurve.setEndY(45);
cubicCurve.setStroke(Color.RED);
cubicCurve.setFill(Color.ROSYBROWN);
cubicCurve.setStrokeWidth(2d);
// show the cubicCurve shape;
getChildren().add(cubicCurve);
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Cubic Curve Fill", cubicCurve.fillProperty()),
new SimplePropertySheet.PropDesc("Cubic Curve Stroke", cubicCurve.strokeProperty()),
new SimplePropertySheet.PropDesc("Cubic Curve Start X", cubicCurve.startXProperty(), 0d, 170d),
new SimplePropertySheet.PropDesc("Cubic Curve Start Y", cubicCurve.startYProperty(), 10d, 80d),
new SimplePropertySheet.PropDesc("Cubic Curve Control X1", cubicCurve.controlX1Property(), 0d, 180d),
new SimplePropertySheet.PropDesc("Cubic Curve Control Y1", cubicCurve.controlY1Property(), 0d, 90d),
new SimplePropertySheet.PropDesc("Cubic Curve Control X2", cubicCurve.controlX2Property(), 0d, 180d),
new SimplePropertySheet.PropDesc("Cubic Curve Control Y2", cubicCurve.controlY2Property(), 0d, 90d),
new SimplePropertySheet.PropDesc("Cubic Curve End X", cubicCurve.endXProperty(), 10d, 180d),
new SimplePropertySheet.PropDesc("Cubic Curve End Y", cubicCurve.endYProperty(), 10d, 80d)
);
// END REMOVE ME
}
public CubicCurveSample() {
super(180,90);
// Create cubicCurve shape
CubicCurve cubicCurve = new CubicCurve();
cubicCurve.setStartX(0);
cubicCurve.setStartY(45);
cubicCurve.setControlX1(30);
cubicCurve.setControlY1(10);
cubicCurve.setControlX2(150);
cubicCurve.setControlY2(80);
cubicCurve.setEndX(180);
cubicCurve.setEndY(45);
cubicCurve.setStroke(Color.RED);
cubicCurve.setFill(Color.ROSYBROWN);
cubicCurve.setStrokeWidth(2d);
// show the cubicCurve shape;
getChildren().add(cubicCurve);
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Cubic Curve Fill", cubicCurve.fillProperty()),
new SimplePropertySheet.PropDesc("Cubic Curve Stroke", cubicCurve.strokeProperty()),
new SimplePropertySheet.PropDesc("Cubic Curve Start X", cubicCurve.startXProperty(), 0d, 170d),
new SimplePropertySheet.PropDesc("Cubic Curve Start Y", cubicCurve.startYProperty(), 10d, 80d),
new SimplePropertySheet.PropDesc("Cubic Curve Control X1", cubicCurve.controlX1Property(), 0d, 180d),
new SimplePropertySheet.PropDesc("Cubic Curve Control Y1", cubicCurve.controlY1Property(), 0d, 90d),
new SimplePropertySheet.PropDesc("Cubic Curve Control X2", cubicCurve.controlX2Property(), 0d, 180d),
new SimplePropertySheet.PropDesc("Cubic Curve Control Y2", cubicCurve.controlY2Property(), 0d, 90d),
new SimplePropertySheet.PropDesc("Cubic Curve End X", cubicCurve.endXProperty(), 10d, 180d),
new SimplePropertySheet.PropDesc("Cubic Curve End Y", cubicCurve.endYProperty(), 10d, 80d)
);
// END REMOVE ME
}
/**
* Returns an {@link IGeometry} that describes the geometric outline of the
* given {@link Shape}, i.e. excluding the stroke.
* <p>
* The conversion is supported for the following {@link Shape}s:
* <ul>
* <li>{@link Arc}
* <li>{@link Circle}
* <li>{@link CubicCurve}
* <li>{@link Ellipse}
* <li>{@link Line}
* <li>{@link Path}
* <li>{@link Polygon}
* <li>{@link Polyline}
* <li>{@link QuadCurve}
* <li>{@link Rectangle}
* </ul>
* The following {@link Shape}s cannot be converted, yet:
* <ul>
* <li>{@link Text}
* <li>{@link SVGPath}
* </ul>
*
* @param visual
* The {@link Shape} for which an {@link IGeometry} is
* determined.
* @return The newly created {@link IGeometry} that best describes the
* geometric outline of the given {@link Shape}.
* @throws IllegalStateException
* if the given {@link Shape} is not supported.
*/
public static IGeometry toGeometry(Shape visual) {
if (visual instanceof Arc) {
return toArc((Arc) visual);
} else if (visual instanceof Circle) {
return toEllipse((Circle) visual);
} else if (visual instanceof CubicCurve) {
return toCubicCurve((CubicCurve) visual);
} else if (visual instanceof Ellipse) {
return toEllipse((Ellipse) visual);
} else if (visual instanceof Line) {
return toLine((Line) visual);
} else if (visual instanceof Path) {
return toPath((Path) visual);
} else if (visual instanceof Polygon) {
return toPolygon((Polygon) visual);
} else if (visual instanceof Polyline) {
return toPolyline((Polyline) visual);
} else if (visual instanceof QuadCurve) {
QuadCurve quad = (QuadCurve) visual;
return toQuadraticCurve(quad);
} else if (visual instanceof Rectangle) {
Rectangle rect = (Rectangle) visual;
if (rect.getArcWidth() == 0 && rect.getArcHeight() == 0) {
// corners are not rounded => normal rectangle is sufficient
return toRectangle(rect);
}
return toRoundedRectangle((Rectangle) visual);
} else {
// Text and SVGPath shapes are currently not supported
throw new IllegalStateException(
"Cannot compute geometric outline for Shape of type <"
+ visual.getClass() + ">.");
}
}
public static String shapeToSvgString(final Shape SHAPE) {
final StringBuilder fxPath = new StringBuilder();
if (Line.class.equals(SHAPE.getClass())) {
fxPath.append(convertLine((Line) SHAPE));
} else if (Arc.class.equals(SHAPE.getClass())) {
fxPath.append(convertArc((Arc) SHAPE));
} else if (QuadCurve.class.equals(SHAPE.getClass())) {
fxPath.append(convertQuadCurve((QuadCurve) SHAPE));
} else if (CubicCurve.class.equals(SHAPE.getClass())) {
fxPath.append(convertCubicCurve((CubicCurve) SHAPE));
} else if (Rectangle.class.equals(SHAPE.getClass())) {
fxPath.append(convertRectangle((Rectangle) SHAPE));
} else if (Circle.class.equals(SHAPE.getClass())) {
fxPath.append(convertCircle((Circle) SHAPE));
} else if (Ellipse.class.equals(SHAPE.getClass())) {
fxPath.append(convertEllipse((Ellipse) SHAPE));
} else if (Text.class.equals(SHAPE.getClass())) {
Path path = (Path)(Shape.subtract(SHAPE, new Rectangle(0, 0)));
fxPath.append(convertPath(path));
} else if (Path.class.equals(SHAPE.getClass())) {
fxPath.append(convertPath((Path) SHAPE));
} else if (Polygon.class.equals(SHAPE.getClass())) {
fxPath.append(convertPolygon((Polygon) SHAPE));
} else if (Polyline.class.equals(SHAPE.getClass())) {
fxPath.append(convertPolyline((Polyline) SHAPE));
} else if (SVGPath.class.equals(SHAPE.getClass())) {
fxPath.append(((SVGPath) SHAPE).getContent());
}
return fxPath.toString();
}
public static String convertCubicCurve(final CubicCurve CUBIC_CURVE) {
final StringBuilder fxPath = new StringBuilder();
fxPath.append("M ").append(CUBIC_CURVE.getStartX()).append(" ").append(CUBIC_CURVE.getStartY()).append(" ")
.append("C ").append(CUBIC_CURVE.getControlX1()).append(" ").append(CUBIC_CURVE.getControlY1()).append(" ")
.append(CUBIC_CURVE.getControlX2()).append(" ").append(CUBIC_CURVE.getControlY2()).append(" ")
.append(CUBIC_CURVE.getEndX()).append(" ").append(CUBIC_CURVE.getEndY());
return fxPath.toString();
}
private void runTurn(List<Entity> atkCards, List<Entity> defCards) {
for (int i = 0; i < 5; i++) {
Entity cardEntity = atkCards.get(i);
var card = cardEntity.getComponent(CardComponent.class);
if (card.isAlive()) {
Entity cardEntity2 = defCards.get(i);
var card2 = cardEntity2.getComponent(CardComponent.class);
Entity targetEntity;
if (card2.isAlive()) {
targetEntity = cardEntity2;
} else {
targetEntity = defCards.stream()
.filter(e -> e.getComponent(CardComponent.class).isAlive())
.findAny()
.orElse(null);
}
// TODO: animations are delayed and start when targetEntity is alive
// we still need to check targetEntity's hp during animation
// TODO: add next turn button and disable while turn is being executed
if (targetEntity != null) {
animationBuilder()
.delay(Duration.seconds(i))
.duration(Duration.seconds(0.3))
.interpolator(Interpolators.EXPONENTIAL.EASE_IN())
.repeat(2)
.autoReverse(true)
.translate(cardEntity)
.alongPath(new CubicCurve(
cardEntity.getX(), cardEntity.getY(),
cardEntity.getX() - 100, (cardEntity.getY() + cardEntity2.getY()) / 3,
cardEntity.getX() - 150, (cardEntity.getY() + cardEntity2.getY()) / 3 * 2,
cardEntity2.getX(), cardEntity2.getY()
))
// .from(cardEntity.getPosition())
// .to(cardEntity2.getPosition().add(0, 0))
.buildAndPlay();
animationBuilder()
.delay(Duration.seconds(0.2 + i))
.duration(Duration.seconds(0.1))
.interpolator(Interpolators.ELASTIC.EASE_OUT())
.repeat(4)
.autoReverse(true)
.onFinished(() -> attack(cardEntity, targetEntity))
.translate(targetEntity)
.from(targetEntity.getPosition())
.to(targetEntity.getPosition().add(2.5, 0))
.buildAndPlay();
}
}
}
}
public void setType (DragIconType type) {
mType = type;
getStyleClass().clear();
getStyleClass().add("dragicon");
//added because the cubic curve will persist into other icons
if (this.getChildren().size() > 0)
getChildren().clear();
switch (mType) {
case cubic_curve:
getStyleClass().add("icon-yellow");
Pane pane = new Pane();
pane.setPrefWidth(64.0);
pane.setPrefHeight(64.0);
//pane.getStyleClass().add("icon-blue");
pane.setLayoutX(0.0);
pane.setLayoutY(0.0);
CubicCurve curve = new CubicCurve();
curve.setStartX(10.0);
curve.setStartY(20.0);
curve.setEndX(54.0);
curve.setEndY(44.0);
curve.setControlX1(64.0);
curve.setControlY1(20.0);
curve.setControlX2(0.0);
curve.setControlY2(44.0);
curve.getStyleClass().add("cubic-icon");
pane.getChildren().add(curve);
//r//oot_pane.
getChildren().add(pane);
break;
case blue:
getStyleClass().add("icon-blue");
break;
case red:
getStyleClass().add("icon-red");
break;
case green:
getStyleClass().add("icon-green");
break;
case grey:
getStyleClass().add("icon-grey");
break;
case purple:
getStyleClass().add("icon-purple");
break;
case yellow:
getStyleClass().add("icon-yellow");
break;
case black:
getStyleClass().add("icon-black");
break;
default:
break;
}
}
private void runTurn(List<Entity> atkCards, List<Entity> defCards) {
for (int i = 0; i < 5; i++) {
Entity cardEntity = atkCards.get(i);
var card = cardEntity.getComponent(CardComponent.class);
if (card.isAlive()) {
Entity cardEntity2 = defCards.get(i);
var card2 = cardEntity2.getComponent(CardComponent.class);
Entity targetEntity;
if (card2.isAlive()) {
targetEntity = cardEntity2;
} else {
targetEntity = defCards.stream()
.filter(e -> e.getComponent(CardComponent.class).isAlive())
.findAny()
.orElse(null);
}
// TODO: animations are delayed and start when targetEntity is alive
// we still need to check targetEntity's hp during animation
// TODO: add next turn button and disable while turn is being executed
if (targetEntity != null) {
animationBuilder()
.delay(Duration.seconds(i))
.duration(Duration.seconds(0.3))
.interpolator(Interpolators.EXPONENTIAL.EASE_IN())
.repeat(2)
.autoReverse(true)
.translate(cardEntity)
.alongPath(new CubicCurve(
cardEntity.getX(), cardEntity.getY(),
cardEntity.getX() - 100, (cardEntity.getY() + cardEntity2.getY()) / 3,
cardEntity.getX() - 150, (cardEntity.getY() + cardEntity2.getY()) / 3 * 2,
cardEntity2.getX(), cardEntity2.getY()
))
// .from(cardEntity.getPosition())
// .to(cardEntity2.getPosition().add(0, 0))
.buildAndPlay();
animationBuilder()
.delay(Duration.seconds(0.2 + i))
.duration(Duration.seconds(0.1))
.interpolator(Interpolators.ELASTIC.EASE_OUT())
.repeat(4)
.autoReverse(true)
.onFinished(() -> attack(cardEntity, targetEntity))
.translate(targetEntity)
.from(targetEntity.getPosition())
.to(targetEntity.getPosition().add(2.5, 0))
.buildAndPlay();
}
}
}
}
/**
* Converts the given JavaFX {@link CubicCurve} to a
* {@link org.eclipse.gef.geometry.planar.CubicCurve}.
*
* @param cubic
* The JavaFX {@link CubicCurve} to convert.
* @return The newly created
* {@link org.eclipse.gef.geometry.planar.CubicCurve} that
* describes the given {@link CubicCurve}.
*/
public static org.eclipse.gef.geometry.planar.CubicCurve toCubicCurve(
CubicCurve cubic) {
return new org.eclipse.gef.geometry.planar.CubicCurve(
cubic.getStartX(), cubic.getStartY(), cubic.getControlX1(),
cubic.getControlY1(), cubic.getControlX2(),
cubic.getControlY2(), cubic.getEndX(), cubic.getEndY());
}