From 094954794e0234a12d4f3b1a862bf8ccdcebb3f5 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 1 Sep 2017 18:45:37 +0300 Subject: [PATCH] Add visible property --- app/src/main/java/com/annimon/hotarufx/lib/NodeValue.java | 7 +++++++ .../main/java/com/annimon/hotarufx/lib/PropertyValue.java | 6 ++++++ .../java/com/annimon/hotarufx/visual/PropertyType.java | 2 ++ .../com/annimon/hotarufx/visual/objects/ObjectNode.java | 8 ++++++++ app/src/main/resources/main.hfx | 1 + 5 files changed, 24 insertions(+) diff --git a/app/src/main/java/com/annimon/hotarufx/lib/NodeValue.java b/app/src/main/java/com/annimon/hotarufx/lib/NodeValue.java index 9255f11..ee80358 100644 --- a/app/src/main/java/com/annimon/hotarufx/lib/NodeValue.java +++ b/app/src/main/java/com/annimon/hotarufx/lib/NodeValue.java @@ -48,6 +48,9 @@ public class NodeValue implements Value { val timeline = property.getProperty().get(); val type = property.getType(); switch (type) { + case BOOLEAN: + return type.getToHFX().apply( + ((PropertyTimeline) timeline).getProperty().getValue()); case NUMBER: return type.getToHFX().apply( ((PropertyTimeline) timeline).getProperty().getValue()); @@ -76,6 +79,10 @@ public class NodeValue implements Value { val timeline = property.getProperty().get(); val type = property.getType(); switch (type) { + case BOOLEAN: + ((PropertyTimeline) timeline).getProperty().setValue( + type.getFromHFX().apply(value)); + break; case NUMBER: ((PropertyTimeline) timeline).getProperty().setValue( type.getFromHFX().apply(value)); diff --git a/app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java b/app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java index 01d8635..8385645 100644 --- a/app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java +++ b/app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java @@ -44,6 +44,12 @@ public class PropertyValue implements Value { Validator.with(args).checkAtLeast(2); val type = property.getType(); switch (type) { + case BOOLEAN: + ((PropertyTimeline)property.getProperty().get()).add( + KeyFrame.of(args[0].asInt()), + type.getFromHFX().apply(args[1]) + ); + break; case NUMBER: ((PropertyTimeline)property.getProperty().get()).add( KeyFrame.of(args[0].asInt()), diff --git a/app/src/main/java/com/annimon/hotarufx/visual/PropertyType.java b/app/src/main/java/com/annimon/hotarufx/visual/PropertyType.java index f5db28f..b6fea60 100644 --- a/app/src/main/java/com/annimon/hotarufx/visual/PropertyType.java +++ b/app/src/main/java/com/annimon/hotarufx/visual/PropertyType.java @@ -19,9 +19,11 @@ import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.val; +@SuppressWarnings("ConstantConditions") @RequiredArgsConstructor(access = AccessLevel.PACKAGE) public enum PropertyType { + BOOLEAN(v -> v.asInt() != 0, o -> NumberValue.fromBoolean(Boolean.TRUE.equals(o))), NUMBER(toNumber(), o -> NumberValue.of((Number) o)), STRING(Value::asString, o -> new StringValue(String.valueOf(o))), NODE(toNode(), fromNode()), diff --git a/app/src/main/java/com/annimon/hotarufx/visual/objects/ObjectNode.java b/app/src/main/java/com/annimon/hotarufx/visual/objects/ObjectNode.java index 8abc009..f75df93 100644 --- a/app/src/main/java/com/annimon/hotarufx/visual/objects/ObjectNode.java +++ b/app/src/main/java/com/annimon/hotarufx/visual/objects/ObjectNode.java @@ -13,6 +13,7 @@ import static com.annimon.hotarufx.visual.PropertyType.*; public abstract class ObjectNode { private final Node node; + private PropertyTimelineHolder visible; private PropertyTimelineHolder clip; private PropertyTimelineHolder rotate; private PropertyTimelineHolder translateX, translateY, translateZ; @@ -23,6 +24,7 @@ public abstract class ObjectNode { public ObjectNode(Node node) { this.node = node; + visible = PropertyTimelineHolder.empty(); clip = PropertyTimelineHolder.empty(); rotate = PropertyTimelineHolder.empty(); translateX = PropertyTimelineHolder.empty(); @@ -40,6 +42,10 @@ public abstract class ObjectNode { return node; } + public PropertyTimeline visibleProperty() { + return visible.setIfEmptyThenGet(node::visibleProperty); + } + public PropertyTimeline clipProperty() { return clip.setIfEmptyThenGet(node::clipProperty); } @@ -81,6 +87,7 @@ public abstract class ObjectNode { } public void buildTimeline(TimeLine timeline) { + visible.applyIfPresent(timeline); clip.applyIfPresent(timeline); rotate.applyIfPresent(timeline); translateX.applyIfPresent(timeline); @@ -99,6 +106,7 @@ public abstract class ObjectNode { protected PropertyBindings propertyBindings(PropertyBindings bindings) { return bindings + .add("visible", BOOLEAN, this::visibleProperty) .add("clip", CLIP_NODE, this::clipProperty) .add("rotate", NUMBER, this::rotateProperty) .add("translateX", NUMBER, this::translateXProperty) diff --git a/app/src/main/resources/main.hfx b/app/src/main/resources/main.hfx index 04c67d0..b694cc9 100644 --- a/app/src/main/resources/main.hfx +++ b/app/src/main/resources/main.hfx @@ -16,6 +16,7 @@ A@fill B = rectangle({ x: -50, y: -50, + visible: 0, width: 100, height: 100, fill: "green"