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

Add image node

This commit is contained in:
Victor 2017-09-16 13:48:34 +03:00
parent 738e93d9ef
commit 0c912fcca7
4 changed files with 107 additions and 0 deletions

View File

@ -25,6 +25,7 @@ public class NodesBundle implements Bundle {
FUNCTIONS.put("circle", of(NODE, node(CircleNode::new)));
FUNCTIONS.put("ellipse", of(NODE, node(EllipseNode::new)));
FUNCTIONS.put("group", of(NODE, group()));
FUNCTIONS.put("image", of(NODE, image()));
FUNCTIONS.put("line", of(NODE, node(LineNode::new)));
FUNCTIONS.put("polygon", of(NODE, poly(PolygonNode::new)));
FUNCTIONS.put("polyline", of(NODE, poly(PolylineNode::new)));
@ -60,6 +61,17 @@ public class NodesBundle implements Bundle {
};
}
private static Function image() {
return args -> {
val validator = Validator.with(args);
val map = validator.requireMapAt(1);
val url = args[0].asString();
val node = new NodeValue(new ImageNode(url));
node.fill(map);
return node;
};
}
private static Function group() {
return args -> {
val nodes = Arrays.stream(args)

View File

@ -0,0 +1,89 @@
package com.annimon.hotarufx.visual.objects;
import com.annimon.hotarufx.visual.PropertyBindings;
import com.annimon.hotarufx.visual.PropertyTimeline;
import com.annimon.hotarufx.visual.PropertyTimelineHolder;
import com.annimon.hotarufx.visual.TimeLine;
import com.annimon.hotarufx.visual.visitors.NodeVisitor;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import static com.annimon.hotarufx.visual.PropertyType.BOOLEAN;
import static com.annimon.hotarufx.visual.PropertyType.NUMBER;
public class ImageNode extends ObjectNode {
public final ImageView imageView;
private PropertyTimelineHolder<Number> x, y, fitWidth, fitHeight;
private PropertyTimelineHolder<Boolean> preserveRatio, smooth;
public ImageNode(String url) {
this(url, new ImageView());
}
private ImageNode(String url, ImageView imageView) {
super(imageView);
this.imageView = imageView;
imageView.imageProperty().setValue(new Image(url));
x = PropertyTimelineHolder.empty();
y = PropertyTimelineHolder.empty();
fitWidth = PropertyTimelineHolder.empty();
fitHeight = PropertyTimelineHolder.empty();
preserveRatio = PropertyTimelineHolder.empty();
smooth = PropertyTimelineHolder.empty();
}
public PropertyTimeline<Number> xProperty() {
return x.setIfEmptyThenGet(imageView::xProperty);
}
public PropertyTimeline<Number> yProperty() {
return y.setIfEmptyThenGet(imageView::yProperty);
}
public PropertyTimeline<Number> fitWidthProperty() {
return fitWidth.setIfEmptyThenGet(imageView::fitWidthProperty);
}
public PropertyTimeline<Number> fitHeightProperty() {
return fitHeight.setIfEmptyThenGet(imageView::fitHeightProperty);
}
public PropertyTimeline<Boolean> preserveRatioProperty() {
return preserveRatio.setIfEmptyThenGet(imageView::preserveRatioProperty);
}
public PropertyTimeline<Boolean> smoothProperty() {
return smooth.setIfEmptyThenGet(imageView::smoothProperty);
}
@Override
public void buildTimeline(TimeLine timeline) {
super.buildTimeline(timeline);
x.applyIfPresent(timeline);
y.applyIfPresent(timeline);
fitWidth.applyIfPresent(timeline);
fitHeight.applyIfPresent(timeline);
preserveRatio.applyIfPresent(timeline);
smooth.applyIfPresent(timeline);
}
@Override
public PropertyBindings propertyBindings(PropertyBindings bindings) {
return super.propertyBindings(bindings)
.add("x", NUMBER, this::xProperty)
.add("y", NUMBER, this::yProperty)
.add("width", NUMBER, this::fitWidthProperty)
.add("fitWidth", NUMBER, this::fitWidthProperty)
.add("height", NUMBER, this::fitHeightProperty)
.add("fitHeight", NUMBER, this::fitHeightProperty)
.add("ratio", BOOLEAN, this::preserveRatioProperty)
.add("preserveRatio", BOOLEAN, this::preserveRatioProperty)
.add("smooth", BOOLEAN, this::smoothProperty);
}
@Override
public <R, T> R accept(NodeVisitor<R, T> visitor, T input) {
return visitor.visit(this, input);
}
}

View File

@ -8,6 +8,7 @@ public interface NodeVisitor<R, T> {
R visit(CircleNode node, T input);
R visit(EllipseNode node, T input);
R visit(GroupNode node, T input);
R visit(ImageNode node, T input);
R visit(LineNode node, T input);
R visit(PolygonNode node, T input);
R visit(PolylineNode node, T input);

View File

@ -35,6 +35,11 @@ public class RenderVisitor implements NodeVisitor<Void, VirtualScene> {
return null;
}
@Override
public Void visit(ImageNode node, VirtualScene scene) {
return render(node, scene);
}
@Override
public Void visit(LineNode node, VirtualScene scene) {
return render(node, scene);