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:
parent
0f67442d0a
commit
cf21aef0ac
@ -24,7 +24,8 @@ public class Main extends Application {
|
|||||||
for (int y = -1; y <= 1; y++) {
|
for (int y = -1; y <= 1; y++) {
|
||||||
for (int x = -1; x <= 1; x++) {
|
for (int x = -1; x <= 1; x++) {
|
||||||
val node = new CircleNode();
|
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.setCenterX(x * halfWidth);
|
||||||
node.circle.setCenterY(y * halfHeight);
|
node.circle.setCenterY(y * halfHeight);
|
||||||
node.circle.setRadius(50);
|
node.circle.setRadius(50);
|
||||||
@ -32,6 +33,9 @@ public class Main extends Application {
|
|||||||
.add(KeyFrame.of(30), 70)
|
.add(KeyFrame.of(30), 70)
|
||||||
.add(KeyFrame.of(90), 20)
|
.add(KeyFrame.of(90), 20)
|
||||||
.add(KeyFrame.of(300), 70);
|
.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) {
|
if (x == 0 && y == 0) {
|
||||||
node.centerXProperty()
|
node.centerXProperty()
|
||||||
.add(KeyFrame.of(60), 0)
|
.add(KeyFrame.of(60), 0)
|
||||||
@ -45,6 +49,9 @@ public class Main extends Application {
|
|||||||
.add(KeyFrame.of(300), 0);
|
.add(KeyFrame.of(300), 0);
|
||||||
node.radiusProperty()
|
node.radiusProperty()
|
||||||
.add(KeyFrame.of(320), 180);
|
.add(KeyFrame.of(320), 180);
|
||||||
|
node.fillProperty()
|
||||||
|
.add(KeyFrame.of(300), node.circle.getFill())
|
||||||
|
.add(KeyFrame.of(320), Color.WHITE);
|
||||||
}
|
}
|
||||||
node.accept(renderVisitor, scene);
|
node.accept(renderVisitor, scene);
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,19 @@ import com.annimon.hotarufx.visual.TimeLine;
|
|||||||
import com.annimon.hotarufx.visual.visitors.NodeVisitor;
|
import com.annimon.hotarufx.visual.visitors.NodeVisitor;
|
||||||
import javafx.scene.shape.Circle;
|
import javafx.scene.shape.Circle;
|
||||||
|
|
||||||
public class CircleNode extends ObjectNode {
|
public class CircleNode extends ShapeNode {
|
||||||
|
|
||||||
public final Circle circle;
|
public final Circle circle;
|
||||||
|
|
||||||
private PropertyTimelineHolder<Number> centerX, centerY, radius;
|
private PropertyTimelineHolder<Number> centerX, centerY, radius;
|
||||||
|
|
||||||
public CircleNode() {
|
public CircleNode() {
|
||||||
circle = new Circle();
|
this(new Circle());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CircleNode(Circle circle) {
|
||||||
|
super(circle);
|
||||||
|
this.circle = circle;
|
||||||
centerX = PropertyTimelineHolder.empty();
|
centerX = PropertyTimelineHolder.empty();
|
||||||
centerY = PropertyTimelineHolder.empty();
|
centerY = PropertyTimelineHolder.empty();
|
||||||
radius = PropertyTimelineHolder.empty();
|
radius = PropertyTimelineHolder.empty();
|
||||||
|
@ -2,12 +2,19 @@ package com.annimon.hotarufx.visual.objects;
|
|||||||
|
|
||||||
import com.annimon.hotarufx.visual.TimeLine;
|
import com.annimon.hotarufx.visual.TimeLine;
|
||||||
import com.annimon.hotarufx.visual.visitors.NodeVisitor;
|
import com.annimon.hotarufx.visual.visitors.NodeVisitor;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
|
||||||
public abstract class ObjectNode {
|
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 void buildTimeline(TimeLine timeline) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract <R, T> R accept(NodeVisitor<R, T> visitor, T input);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.annimon.hotarufx.visual.PropertyTimeline;
|
|||||||
import com.annimon.hotarufx.visual.TimeLine;
|
import com.annimon.hotarufx.visual.TimeLine;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import javafx.animation.KeyValue;
|
import javafx.animation.KeyValue;
|
||||||
|
import javafx.scene.paint.Paint;
|
||||||
|
|
||||||
public class PropertyConsumers {
|
public class PropertyConsumers {
|
||||||
|
|
||||||
@ -11,6 +12,10 @@ public class PropertyConsumers {
|
|||||||
return genericConsumer(timeline);
|
return genericConsumer(timeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Consumer<PropertyTimeline<Paint>> paintConsumer(TimeLine timeline) {
|
||||||
|
return genericConsumer(timeline);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> Consumer<PropertyTimeline<T>> genericConsumer(TimeLine timeline) {
|
public static <T> Consumer<PropertyTimeline<T>> genericConsumer(TimeLine timeline) {
|
||||||
return t -> {
|
return t -> {
|
||||||
t.getKeyFrames().forEach((keyFrame, value) -> {
|
t.getKeyFrames().forEach((keyFrame, value) -> {
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user