1
0
mirror of https://github.com/aNNiMON/HotaruFX.git synced 2024-09-19 14:14:21 +03:00

Add nodes hierarchy

This commit is contained in:
Victor 2017-08-25 11:33:44 +03:00
parent 0f67442d0a
commit cf21aef0ac
5 changed files with 64 additions and 5 deletions

View File

@ -24,7 +24,8 @@ public class Main extends Application {
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
val node = new CircleNode();
node.circle.setFill(colors[Math.abs(x * y)]);
val colorIndex = Math.abs(x * y);
node.circle.setFill(colors[colorIndex]);
node.circle.setCenterX(x * halfWidth);
node.circle.setCenterY(y * halfHeight);
node.circle.setRadius(50);
@ -32,6 +33,9 @@ public class Main extends Application {
.add(KeyFrame.of(30), 70)
.add(KeyFrame.of(90), 20)
.add(KeyFrame.of(300), 70);
node.fillProperty()
.add(KeyFrame.of(150), colors[1 - colorIndex])
.add(KeyFrame.of(300), colors[colorIndex]);
if (x == 0 && y == 0) {
node.centerXProperty()
.add(KeyFrame.of(60), 0)
@ -45,6 +49,9 @@ public class Main extends Application {
.add(KeyFrame.of(300), 0);
node.radiusProperty()
.add(KeyFrame.of(320), 180);
node.fillProperty()
.add(KeyFrame.of(300), node.circle.getFill())
.add(KeyFrame.of(320), Color.WHITE);
}
node.accept(renderVisitor, scene);
}

View File

@ -6,14 +6,19 @@ import com.annimon.hotarufx.visual.TimeLine;
import com.annimon.hotarufx.visual.visitors.NodeVisitor;
import javafx.scene.shape.Circle;
public class CircleNode extends ObjectNode {
public class CircleNode extends ShapeNode {
public final Circle circle;
private PropertyTimelineHolder<Number> centerX, centerY, radius;
public CircleNode() {
circle = new Circle();
this(new Circle());
}
private CircleNode(Circle circle) {
super(circle);
this.circle = circle;
centerX = PropertyTimelineHolder.empty();
centerY = PropertyTimelineHolder.empty();
radius = PropertyTimelineHolder.empty();

View File

@ -2,12 +2,19 @@ package com.annimon.hotarufx.visual.objects;
import com.annimon.hotarufx.visual.TimeLine;
import com.annimon.hotarufx.visual.visitors.NodeVisitor;
import javafx.scene.Node;
public abstract class ObjectNode {
public abstract <R, T> R accept(NodeVisitor<R, T> visitor, T input);
private final Node node;
public ObjectNode(Node node) {
this.node = node;
}
public void buildTimeline(TimeLine timeline) {
}
public abstract <R, T> R accept(NodeVisitor<R, T> visitor, T input);
}

View File

@ -4,6 +4,7 @@ import com.annimon.hotarufx.visual.PropertyTimeline;
import com.annimon.hotarufx.visual.TimeLine;
import java.util.function.Consumer;
import javafx.animation.KeyValue;
import javafx.scene.paint.Paint;
public class PropertyConsumers {
@ -11,6 +12,10 @@ public class PropertyConsumers {
return genericConsumer(timeline);
}
public static Consumer<PropertyTimeline<Paint>> paintConsumer(TimeLine timeline) {
return genericConsumer(timeline);
}
public static <T> Consumer<PropertyTimeline<T>> genericConsumer(TimeLine timeline) {
return t -> {
t.getKeyFrames().forEach((keyFrame, value) -> {

View File

@ -0,0 +1,35 @@
package com.annimon.hotarufx.visual.objects;
import com.annimon.hotarufx.visual.PropertyTimeline;
import com.annimon.hotarufx.visual.PropertyTimelineHolder;
import com.annimon.hotarufx.visual.TimeLine;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Shape;
public abstract class ShapeNode extends ObjectNode {
private final Shape shape;
private PropertyTimelineHolder<Paint> fill, stroke;
public ShapeNode(Shape shape) {
super(shape);
this.shape = shape;
fill = PropertyTimelineHolder.empty();
stroke = PropertyTimelineHolder.empty();
}
public PropertyTimeline<Paint> fillProperty() {
return fill.setIfEmptyThenGet(shape::fillProperty);
}
public PropertyTimeline<Paint> strokeProperty() {
return stroke.setIfEmptyThenGet(shape::strokeProperty);
}
public void buildTimeline(TimeLine timeline) {
super.buildTimeline(timeline);
fill.ifPresent(PropertyConsumers.paintConsumer(timeline));
stroke.ifPresent(PropertyConsumers.paintConsumer(timeline));
}
}