mirror of
https://github.com/aNNiMON/HotaruFX.git
synced 2024-09-19 14:14:21 +03:00
Ability to set composition background
This commit is contained in:
parent
378cc26d49
commit
e88a1d637d
@ -6,10 +6,12 @@ import com.annimon.hotarufx.lib.NodeValue;
|
||||
import com.annimon.hotarufx.lib.NumberValue;
|
||||
import com.annimon.hotarufx.lib.Types;
|
||||
import com.annimon.hotarufx.visual.Composition;
|
||||
import com.annimon.hotarufx.visual.PropertyType;
|
||||
import com.annimon.hotarufx.visual.visitors.RenderVisitor;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javafx.scene.paint.Paint;
|
||||
import lombok.val;
|
||||
import static com.annimon.hotarufx.bundles.FunctionInfo.of;
|
||||
import static com.annimon.hotarufx.bundles.FunctionType.COMMON;
|
||||
@ -30,32 +32,35 @@ public class CompositionBundle implements Bundle {
|
||||
|
||||
private static Function composition(Context context) {
|
||||
return args -> {
|
||||
final int width, height;
|
||||
final double frameRate;
|
||||
final Composition composition;
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
width = 1280;
|
||||
height = 720;
|
||||
frameRate = 30d;
|
||||
composition = new Composition();
|
||||
break;
|
||||
case 1:
|
||||
width = 1280;
|
||||
height = 720;
|
||||
frameRate = args[0].asNumber();
|
||||
double frameRate = args[0].asNumber();
|
||||
composition = new Composition(frameRate);
|
||||
break;
|
||||
case 2:
|
||||
width = args[0].asInt();
|
||||
height = args[1].asInt();
|
||||
frameRate = 30d;
|
||||
int width = args[0].asInt();
|
||||
int height = args[1].asInt();
|
||||
composition = new Composition(width, height);
|
||||
break;
|
||||
case 3:
|
||||
width = args[0].asInt();
|
||||
height = args[1].asInt();
|
||||
frameRate = args[2].asNumber();
|
||||
composition = new Composition(width, height, frameRate);
|
||||
break;
|
||||
case 4:
|
||||
default:
|
||||
width = args[0].asInt();
|
||||
height = args[1].asInt();
|
||||
frameRate = args[2].asNumber();
|
||||
val background = PropertyType.PAINT.<Paint>getFromHFX().apply(args[3]);
|
||||
composition = new Composition(width, height, frameRate, background);
|
||||
break;
|
||||
}
|
||||
val composition = new Composition(width, height, frameRate);
|
||||
val scene = composition.getScene();
|
||||
context.composition(composition);
|
||||
context.variables().put("Width", NumberValue.of(scene.getVirtualWidth()));
|
||||
|
@ -3,6 +3,7 @@ package com.annimon.hotarufx.visual;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
|
||||
@ -21,9 +22,29 @@ public class Composition {
|
||||
@Getter
|
||||
private final VirtualScene scene;
|
||||
|
||||
@Getter
|
||||
private final Paint background;
|
||||
|
||||
public Composition() {
|
||||
this(1280, 720);
|
||||
}
|
||||
|
||||
public Composition(double frameRate) {
|
||||
this(1280, 720, frameRate);
|
||||
}
|
||||
|
||||
public Composition(int sceneWidth, int sceneHeight) {
|
||||
this(sceneWidth, sceneHeight, 30);
|
||||
}
|
||||
|
||||
public Composition(int sceneWidth, int sceneHeight, double frameRate) {
|
||||
this(sceneWidth, sceneHeight, frameRate, Color.WHITE);
|
||||
}
|
||||
|
||||
public Composition(int sceneWidth, int sceneHeight, double frameRate, Paint background) {
|
||||
this.sceneWidth = sceneWidth;
|
||||
this.sceneHeight = sceneHeight;
|
||||
this.background = background;
|
||||
virtualHeight = 1080;
|
||||
factor = virtualHeight / (double) sceneHeight;
|
||||
virtualWidth = (int) (sceneWidth * factor);
|
||||
@ -41,6 +62,6 @@ public class Composition {
|
||||
}
|
||||
|
||||
public Scene produceAnimationScene() {
|
||||
return new Scene(scene.getGroup(), sceneWidth, sceneHeight);
|
||||
return new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user