package subsceneSnapshot;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.LightBase;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.SubScene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Box;
import javafx.stage.Stage;

public class SnapshotTest extends Application {

    private static final int LIGHT_DIST = 60;

    private static final LightBase SCENE_LIGHT = new PointLight(Color.BLUE);
    private static final LightBase SUBSCENE_LIGHT = new PointLight(Color.BLUE);

    private static final Box SCENE_BOX = new Box(150, 150, 1);
    private static final Box SUBSCENE_BOX = new Box(150, 150, 1);

    private static final Scene SCENE = new Scene(new Group(SCENE_LIGHT, SCENE_BOX), 200, 200);
    private static final SubScene SUBSCENE = new SubScene(new Group(SUBSCENE_LIGHT, SUBSCENE_BOX), 200, 200);

    @Override
    public void start(Stage mainStage) {
        SCENE_LIGHT.setTranslateZ(-LIGHT_DIST);
        SUBSCENE_LIGHT.setTranslateZ(-LIGHT_DIST);

        showBoxInScene();
        showBoxInSubScene();
        showScene();
        showSubScene();
    }

    private void showBoxInScene() {
       showStage("Box in scene", SCENE_BOX.snapshot(null, null));
    }

    private void showBoxInSubScene() {
        showStage("Box in subscene", SUBSCENE_BOX.snapshot(null, null)); 
    }

    private void showScene() {
        showStage("scene", SCENE.snapshot(null)); 
    }

    private void showSubScene() {
        showStage("subscene", SUBSCENE.snapshot(null, null)); 
    }

    private void showStage(String name, Image snapshot) {
        var scene = new Scene(new Pane(new ImageView(snapshot)));
        var stage = new Stage();
        stage.setTitle(name);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}