|
@@ -18,6 +18,10 @@
|
|
|
|
|
|
package io.github.palexdev.mfxeffects.enums;
|
|
|
|
|
|
+import io.github.palexdev.mfxeffects.animations.Animations.KeyFrames;
|
|
|
+import io.github.palexdev.mfxeffects.animations.Animations.TimelineBuilder;
|
|
|
+import javafx.animation.Interpolator;
|
|
|
+import javafx.scene.effect.BlurType;
|
|
|
import javafx.scene.effect.DropShadow;
|
|
|
import javafx.scene.paint.Color;
|
|
|
|
|
@@ -26,22 +30,37 @@ import java.util.Arrays;
|
|
|
/**
|
|
|
* Enumerator which defines 6 levels of {@code DropShadow} effects from {@code LEVEL0} to {@code LEVEL5}.
|
|
|
*/
|
|
|
-public enum DepthLevel {
|
|
|
+public enum ElevationLevel {
|
|
|
+ // 0dp
|
|
|
LEVEL0(Color.rgb(0, 0, 0, 0), 0, 0, 0, 0),
|
|
|
- LEVEL1(Color.rgb(0, 0, 0, 0.20), 10, 0.12, -1, 2),
|
|
|
- LEVEL2(Color.rgb(0, 0, 0, 0.20), 15, 0.16, 0, 4),
|
|
|
- LEVEL3(Color.rgb(0, 0, 0, 0.20), 20, 0.19, 0, 6),
|
|
|
- LEVEL4(Color.rgb(0, 0, 0, 0.20), 25, 0.25, 0, 8),
|
|
|
- LEVEL5(Color.rgb(0, 0, 0, 0.20), 30, 0.30, 0, 10);
|
|
|
+
|
|
|
+ // 1dp
|
|
|
+ LEVEL1(3, 0.12, 0, 2),
|
|
|
+
|
|
|
+ // 3dp
|
|
|
+ LEVEL2(8, 0.16, 0, 3),
|
|
|
+
|
|
|
+ // 6dp
|
|
|
+ LEVEL3(18, 0.19, 0, 3),
|
|
|
+
|
|
|
+ // 8dp
|
|
|
+ LEVEL4(14, 0.25, 0, 5),
|
|
|
+
|
|
|
+ // 12dp
|
|
|
+ LEVEL5(16, 0.30, 0, 7);
|
|
|
|
|
|
private final Color color;
|
|
|
private final double radius;
|
|
|
private final double spread;
|
|
|
private final double offsetX;
|
|
|
private final double offsetY;
|
|
|
- private static final DepthLevel[] valuesArr = values();
|
|
|
+ private static final ElevationLevel[] valuesArr = values();
|
|
|
|
|
|
- DepthLevel(Color color, double radius, double spread, double offsetX, double offsetY) {
|
|
|
+ ElevationLevel(double radius, double spread, double offsetX, double offsetY) {
|
|
|
+ this(Color.rgb(0, 0, 0, 0.20), radius, spread, offsetX, offsetY);
|
|
|
+ }
|
|
|
+
|
|
|
+ ElevationLevel(Color color, double radius, double spread, double offsetX, double offsetY) {
|
|
|
this.color = color;
|
|
|
this.radius = radius;
|
|
|
this.spread = spread;
|
|
@@ -74,17 +93,35 @@ public enum DepthLevel {
|
|
|
*
|
|
|
* @return The next {@code DepthLevel}
|
|
|
*/
|
|
|
- public DepthLevel next() {
|
|
|
+ public ElevationLevel next() {
|
|
|
return valuesArr[(this.ordinal() + 1) % valuesArr.length];
|
|
|
}
|
|
|
|
|
|
+ public void animateTo(DropShadow current, ElevationLevel next) {
|
|
|
+ Interpolator i = Interpolators.INTERPOLATOR_V2.toInterpolator();
|
|
|
+ TimelineBuilder.build()
|
|
|
+ .add(KeyFrames.of(200, current.radiusProperty(), next.getRadius(), i))
|
|
|
+ .add(KeyFrames.of(200, current.spreadProperty(), next.getSpread(), i))
|
|
|
+ .add(KeyFrames.of(150, current.offsetXProperty(), next.getOffsetX(), i))
|
|
|
+ .add(KeyFrames.of(150, current.offsetYProperty(), next.getOffsetY(), i))
|
|
|
+ .getAnimation().play();
|
|
|
+ }
|
|
|
+
|
|
|
+ public DropShadow toShadow() {
|
|
|
+ return new DropShadow(
|
|
|
+ BlurType.GAUSSIAN, getColor(),
|
|
|
+ getRadius(), getSpread(),
|
|
|
+ getOffsetX(), getOffsetY()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Attempts to get the corresponding {@code DepthLevel} of the given {@link DropShadow} effect.
|
|
|
* If the given effect is not recognized as being generated by this class the {@code null} is returned.
|
|
|
* <p>
|
|
|
- * Uses {@link #levelEqualsShadow(DepthLevel, DropShadow)} to check for equality.
|
|
|
+ * Uses {@link #levelEqualsShadow(ElevationLevel, DropShadow)} to check for equality.
|
|
|
*/
|
|
|
- public static DepthLevel from(DropShadow shadow) {
|
|
|
+ public static ElevationLevel from(DropShadow shadow) {
|
|
|
return Arrays.stream(values()).filter(depthLevel -> levelEqualsShadow(depthLevel, shadow))
|
|
|
.findFirst()
|
|
|
.orElse(null);
|
|
@@ -93,7 +130,7 @@ public enum DepthLevel {
|
|
|
/**
|
|
|
* Checks if the given {@link DropShadow} effect is equal to the given {@code DepthLevel}.
|
|
|
*/
|
|
|
- public static boolean levelEqualsShadow(DepthLevel level, DropShadow shadow) {
|
|
|
+ public static boolean levelEqualsShadow(ElevationLevel level, DropShadow shadow) {
|
|
|
return level.color.equals(shadow.getColor()) &&
|
|
|
level.offsetX == shadow.getOffsetX() &&
|
|
|
level.offsetY == shadow.getOffsetY() &&
|