Skip to content

Commit

Permalink
add auto DPI scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-mauky committed Jun 7, 2015
1 parent 2009286 commit 77afdcf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Expand Up @@ -30,6 +30,8 @@ dependencies {

compile 'eu.lestard:advanced-bindings:0.4.0'

compile 'eu.lestard:fx-zeug:0.1-SNAPSHOT'

// testing
testCompile "junit:junit:4.12"
testCompile "org.assertj:assertj-core:1.6.1"
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/eu/lestard/snakefx/Launcher.java
Expand Up @@ -4,6 +4,7 @@
import de.saxsys.mvvmfx.MvvmFX;
import de.saxsys.mvvmfx.ViewTuple;
import eu.lestard.easydi.EasyDI;
import eu.lestard.fxzeug.usability.Scaling;
import eu.lestard.grid.GridModel;
import eu.lestard.snakefx.highscore.HighscoreDao;
import eu.lestard.snakefx.highscore.HighscoreJsonDao;
Expand Down Expand Up @@ -42,7 +43,16 @@ public void start(final Stage primaryStage) {

final ViewTuple<MainView, MainViewModel> viewTuple = FluentViewLoader.fxmlView(MainView.class).load();

Scene scene = new Scene(viewTuple.getView());


Scaling.detectDefaultScaling();

final int fontSize = Scaling.getFontSize();

Scene scene = new Scene(viewTuple.getView(), fontSize*60, fontSize*50);
Scaling.enableScaling(scene);


scene.setOnKeyPressed(easyDI.getInstance(KeyboardHandler.class));


Expand All @@ -55,8 +65,12 @@ public void start(final Stage primaryStage) {
newHighscorePopup = new TriggerablePopup(NewHighscoreView.class, highscorePopup.getStage());
newHighscorePopup.trigger().bindBidirectional(viewModel.newHighscoreWindowOpen);




primaryStage.setTitle("SnakeFX");
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.show();
}
}
7 changes: 6 additions & 1 deletion src/main/java/eu/lestard/snakefx/util/TriggerablePopup.java
Expand Up @@ -4,6 +4,7 @@
import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.ViewModel;
import de.saxsys.mvvmfx.ViewTuple;
import eu.lestard.fxzeug.usability.Scaling;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.scene.Scene;
Expand All @@ -27,7 +28,11 @@ public TriggerablePopup(Class<? extends FxmlView<? extends ViewModel>> contentVi

final ViewTuple<FxmlView<? extends ViewModel>, ViewModel> viewTuple = FluentViewLoader.fxmlView(contentViewType).load();

stage.setScene(new Scene(viewTuple.getView()));
final Scene scene = new Scene(viewTuple.getView());

Scaling.enableScaling(scene);

stage.setScene(scene);
stage.initModality(Modality.WINDOW_MODAL);

trigger.addListener((observable, oldValue, open) -> {
Expand Down
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<AnchorPane prefHeight="500.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="eu.lestard.snakefx.view.main.MainView">
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="eu.lestard.snakefx.view.main.MainView">
<children>
<BorderPane id="BorderPane" fx:id="rootBorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<left>
Expand Down

0 comments on commit 77afdcf

Please sign in to comment.