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

Add virtual full HD screen

This commit is contained in:
Victor 2017-08-24 14:44:09 +03:00
parent d185e3ee68
commit 1df345c996
4 changed files with 55 additions and 5 deletions

View File

@ -11,6 +11,7 @@ repositories {
dependencies { dependencies {
compileOnly 'org.projectlombok:lombok:1.16.18' compileOnly 'org.projectlombok:lombok:1.16.18'
testCompileOnly 'org.projectlombok:lombok:1.16.18'
testRuntime 'org.junit.platform:junit-platform-launcher:1.0.0-RC2' testRuntime 'org.junit.platform:junit-platform-launcher:1.0.0-RC2'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.0-RC2' testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.0-RC2'
testRuntime 'org.junit.vintage:junit-vintage-engine:4.12.0-RC2' testRuntime 'org.junit.vintage:junit-vintage-engine:4.12.0-RC2'

View File

@ -1,9 +1,11 @@
package com.annimon.hotarufx; package com.annimon.hotarufx;
import com.annimon.hotarufx.visual.Composition; import com.annimon.hotarufx.visual.Composition;
import com.annimon.hotarufx.visual.objects.CircleNode;
import javafx.application.Application; import javafx.application.Application;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.stage.Stage; import javafx.stage.Stage;
import lombok.val; import lombok.val;
@ -13,6 +15,21 @@ public class Main extends Application {
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
val group = new Group(); val group = new Group();
val composition = new Composition(1280, 720, Color.WHITE, group); val composition = new Composition(1280, 720, Color.WHITE, group);
val colors = new Paint[] {Color.GREEN, Color.RED};
val halfWidth = composition.getVirtualWidth() / 2;
val halfHeight = composition.getVirtualHeight() / 2;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
val circle = new CircleNode();
circle.getCircle().setFill(colors[Math.abs(x * y)]);
circle.getCircle().setCenterX(x * halfWidth);
circle.getCircle().setCenterY(y * halfHeight);
circle.getCircle().setRadius(50);
circle.render(composition);
}
}
primaryStage.setTitle("HotaruFX"); primaryStage.setTitle("HotaruFX");
primaryStage.setScene(composition.getScene()); primaryStage.setScene(composition.getScene());
primaryStage.show(); primaryStage.show();

View File

@ -15,13 +15,24 @@ public class Composition {
private final Scene scene; private final Scene scene;
@Getter @Getter
private final int width, height; private final int
virtualWidth, virtualHeight,
sceneWidth, sceneHeight;
@Getter
private final double factor;
public Composition(int width, int height, Paint background, Group group) { public Composition(int sceneWidth, int sceneHeight, Paint background, Group group) {
this.width = width; this.sceneWidth = sceneWidth;
this.height = height; this.sceneHeight = sceneHeight;
virtualHeight = 1080;
factor = virtualHeight / (double) sceneHeight;
virtualWidth = (int) (sceneWidth * factor);
group.setScaleX(1d / factor);
group.setScaleY(1d / factor);
group.setTranslateX(sceneWidth / 2);
group.setTranslateY(sceneHeight / 2);
this.group = group; this.group = group;
this.scene = new Scene(group, width, height, background); this.scene = new Scene(group, sceneWidth, sceneHeight, background);
} }
public void add(Node node) { public void add(Node node) {

View File

@ -0,0 +1,21 @@
package com.annimon.hotarufx.visual;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.*;
class CompositionTest {
@Test
void testVirtualSize() {
Composition composition;
composition = new Composition(1280, 720, Color.WHITE, new Group());
assertThat(composition.getVirtualWidth(), is(1920));
composition = new Composition(1280, 1280, Color.WHITE, new Group());
assertThat(composition.getVirtualWidth(), is(1080));
}
}