Skip to content

Commit

Permalink
Shortcut for taking screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
garfieldnate committed Aug 4, 2024
1 parent da02e65 commit 76f0dff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/edu/umich/soar/svsviewer/SceneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ public void initialize() {
viewerScene.setOnKeyPressed(
event -> {
switch (event.getCode()) {
case W -> camera.translateZProperty().set(camera.getTranslateZ() - 10);
case S -> camera.translateZProperty().set(camera.getTranslateZ() + 10);
case UP -> camera.translateZProperty().set(camera.getTranslateZ() - 10);
case DOWN -> camera.translateZProperty().set(camera.getTranslateZ() + 10);
case L -> toggleSceneLabels();
case M -> toggleSceneDrawMode();
case S -> saveScreenshot();
}
});
viewerScene.setFocusTraversable(true);
Expand Down Expand Up @@ -216,11 +217,12 @@ private void initServer(Consumer<String> inputProcessor) {
/** Save an image file showing the current viewer scene */
public void saveScreenshot() {
File outputFile = getScreenshotFile();
WritableImage image = viewerScene.snapshot(new SnapshotParameters(), null);
WritableImage image = rootPane.snapshot(new SnapshotParameters(), null);
BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null);

try {
ImageIO.write(bufferedImage, "png", outputFile);
System.out.println("Saved screenshot to " + outputFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -243,7 +245,7 @@ private File getScreenshotFile() {

File outputFile;
do {
outputFile = new File(baseFileName + suffix + extension);
outputFile = new File(baseFileName + suffix + "." + extension);
screenshotCounter++;
suffix = Integer.toString(screenshotCounter);
} while (outputFile.exists());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package edu.umich.soar.svsviewer;

import javafx.application.Application;
import javafx.beans.NamedArg;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.stage.Stage;

import java.io.IOException;
Expand All @@ -15,6 +17,7 @@ public void start(Stage primaryStage) throws IOException {
new FXMLLoader(SvsViewerApplication.class.getResource("svs-viewer.fxml"));
Scene scene = new Scene(fxmlLoader.load());
primaryStage.setTitle("SVS Viewer");
// Scene scene = new Scene(fxmlLoader.load(), -1, -1, false, SceneAntialiasing.BALANCED);
primaryStage.setScene(scene);
primaryStage.show();
}
Expand Down

0 comments on commit 76f0dff

Please sign in to comment.