Search in sources :

Example 6 with Rectangle2D

use of javafx.geometry.Rectangle2D in project fx2048 by brunoborges.

the class Game2048 method start.

@Override
public void start(Stage primaryStage) {
    root = new GamePane();
    Scene scene = new Scene(root);
    scene.getStylesheets().add("game2048/game.css");
    if (isARMDevice()) {
        primaryStage.setFullScreen(true);
        primaryStage.setFullScreenExitHint("");
    }
    if (Platform.isSupported(ConditionalFeature.INPUT_TOUCH)) {
        scene.setCursor(Cursor.NONE);
    }
    Bounds gameBounds = root.getGameManager().getLayoutBounds();
    int MARGIN = GamePane.getMargin();
    Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
    double factor = Math.min(visualBounds.getWidth() / (gameBounds.getWidth() + MARGIN), visualBounds.getHeight() / (gameBounds.getHeight() + MARGIN));
    primaryStage.setTitle("2048FX");
    primaryStage.setScene(scene);
    primaryStage.setMinWidth(gameBounds.getWidth() / 2d);
    primaryStage.setMinHeight(gameBounds.getHeight() / 2d);
    primaryStage.setWidth((gameBounds.getWidth() + MARGIN) * factor);
    primaryStage.setHeight((gameBounds.getHeight() + MARGIN) * factor);
    primaryStage.setOnCloseRequest(t -> {
        t.consume();
        root.getGameManager().quitGame();
    });
    primaryStage.show();
}
Also used : Bounds(javafx.geometry.Bounds) Rectangle2D(javafx.geometry.Rectangle2D) Scene(javafx.scene.Scene)

Example 7 with Rectangle2D

use of javafx.geometry.Rectangle2D in project Board-Instrumentation-Framework by intel.

the class DynamicTransition method cube.

/**
 * Cube transition between front- and backimage
 *
 * @param FRONT_IMAGE
 * @param BACK_IMAGE
 * @param INTERPOLATOR spline that is used for the animation
 * @param DURATION oneSecond for the transition
 * @param DELAY delay in milliseconds between each tile animation
 */
private void cube(final Image FRONT_IMAGE, final Image BACK_IMAGE, final Interpolator INTERPOLATOR, final Duration DURATION, final int DELAY) {
    adjustTilesVisibility(1);
    viewPorts.clear();
    final Rectangle2D VIEW_PORT = new Rectangle2D(0, 0, FRONT_IMAGE.getWidth(), FRONT_IMAGE.getHeight());
    for (int i = 0; i < (noOfTilesX * noOfTilesY); i++) {
        imageViewsFront.get(i).setViewport(VIEW_PORT);
        imageViewsBack.get(i).setViewport(VIEW_PORT);
    }
    imageViewsFront.get(0).setImage(FRONT_IMAGE);
    imageViewsBack.get(0).setImage(BACK_IMAGE);
    imageViewsFront.get(0).setTranslateZ(-0.5 * FRONT_IMAGE.getWidth());
    imageViewsBack.get(0).setTranslateX(0.5 * FRONT_IMAGE.getWidth());
    imageViewsBack.get(0).setRotationAxis(Rotate.Y_AXIS);
    // imageViewsBack.get(0).setRotate(90);
    // to grid would be reversed if didn't do this
    imageViewsBack.get(0).setRotate(270);
    Rotate rotateY = new Rotate(0, Rotate.Y_AXIS);
    rotateY.setPivotX(FRONT_IMAGE.getWidth() * 0.5);
    rotateY.setPivotZ(FRONT_IMAGE.getWidth() * 0.5);
    rotateY.angleProperty().addListener((ov, oldAngle, newAngle) -> {
        if (73 < newAngle.intValue()) {
            imageViewsBack.get(0).toFront();
        }
    });
    Translate translateZ = new Translate(0, 0, FRONT_IMAGE.getWidth() * 0.5);
    tiles.get(0).getTransforms().setAll(rotateY, translateZ);
    KeyValue kvRotateBegin = new KeyValue(rotateY.angleProperty(), 0, INTERPOLATOR);
    KeyValue kvRotateEnd = new KeyValue(rotateY.angleProperty(), 90, INTERPOLATOR);
    KeyValue kvOpacityFrontBegin = new KeyValue(imageViewsFront.get(0).opacityProperty(), 1.0, INTERPOLATOR);
    KeyValue kvOpacityBackBegin = new KeyValue(imageViewsBack.get(0).opacityProperty(), 0.0, INTERPOLATOR);
    KeyValue kvScaleXBegin = new KeyValue(tiles.get(0).scaleXProperty(), 1.0, INTERPOLATOR);
    KeyValue kvScaleYBegin = new KeyValue(tiles.get(0).scaleYProperty(), 1.0, INTERPOLATOR);
    KeyValue kvScaleXMiddle = new KeyValue(tiles.get(0).scaleXProperty(), 0.85, INTERPOLATOR);
    KeyValue kvScaleYMiddle = new KeyValue(tiles.get(0).scaleYProperty(), 0.85, INTERPOLATOR);
    KeyValue kvOpacityFrontMiddle = new KeyValue(imageViewsFront.get(0).opacityProperty(), 1.0, INTERPOLATOR);
    KeyValue kvOpacityBackMiddle = new KeyValue(imageViewsBack.get(0).opacityProperty(), 1.0, INTERPOLATOR);
    KeyValue kvScaleXEnd = new KeyValue(tiles.get(0).scaleXProperty(), 1.0, INTERPOLATOR);
    KeyValue kvScaleYEnd = new KeyValue(tiles.get(0).scaleYProperty(), 1.0, INTERPOLATOR);
    KeyValue kvOpacityFrontEnd = new KeyValue(imageViewsFront.get(0).opacityProperty(), 0.0, INTERPOLATOR);
    KeyValue kvOpacityBackEnd = new KeyValue(imageViewsBack.get(0).opacityProperty(), 1.0, INTERPOLATOR);
    KeyFrame kf0 = new KeyFrame(Duration.ZERO, kvRotateBegin, kvScaleXBegin, kvScaleYBegin, kvOpacityFrontBegin, kvOpacityBackBegin);
    KeyFrame kf1 = new KeyFrame(DURATION.multiply(0.5), kvScaleXMiddle, kvScaleYMiddle, kvOpacityFrontMiddle, kvOpacityBackMiddle);
    KeyFrame kf2 = new KeyFrame(DURATION, kvRotateEnd, kvScaleXEnd, kvScaleYEnd, kvOpacityFrontEnd, kvOpacityBackEnd);
    timelines.get(0).setDelay(Duration.millis(DELAY));
    timelines.get(0).getKeyFrames().setAll(kf0, kf1, kf2);
    // Listen for the last timeline to finish and switch the images
    timelines.get(0).setOnFinished(observable -> transitionFinished());
}
Also used : KeyValue(javafx.animation.KeyValue) Rotate(javafx.scene.transform.Rotate) Rectangle2D(javafx.geometry.Rectangle2D) KeyFrame(javafx.animation.KeyFrame) Translate(javafx.scene.transform.Translate)

Example 8 with Rectangle2D

use of javafx.geometry.Rectangle2D in project Board-Instrumentation-Framework by intel.

the class DynamicTransition method splitImageXY.

/**
 * Split the given images into rectangular tiles defined by noOfTilesX and
 * noOfTilesY
 *
 * @param FRONT_IMAGE
 * @param BACK_IMAGE
 */
private void splitImageXY(final Image FRONT_IMAGE, final Image BACK_IMAGE) {
    int count = 0;
    viewPorts.clear();
    for (int y = 0; y < noOfTilesY; y++) {
        for (int x = 0; x < noOfTilesX; x++) {
            // Create the viewports
            viewPorts.add(new Rectangle2D(x * stepSizeX, y * stepSizeY, stepSizeX, stepSizeY));
            // Update the frontside imageviews
            imageViewsFront.get(count).getTransforms().clear();
            imageViewsFront.get(count).toFront();
            imageViewsFront.get(count).setImage(FRONT_IMAGE);
            imageViewsFront.get(count).setViewport(viewPorts.get(count));
            // Update the backside imageviews
            imageViewsBack.get(count).getTransforms().clear();
            imageViewsBack.get(count).setImage(BACK_IMAGE);
            imageViewsBack.get(count).setViewport(viewPorts.get(count));
            count++;
        }
    }
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D)

Example 9 with Rectangle2D

use of javafx.geometry.Rectangle2D in project Board-Instrumentation-Framework by intel.

the class AboutBox method SetupExtraInfoPane.

private static int SetupExtraInfoPane(GridPane grid, int iStartRow, int column) {
    TaskManager TASKMAN = TaskManager.getTaskManager();
    ConfigurationReader CONFIG = ConfigurationReader.GetConfigReader();
    // ConfigurationReader CONFIG = GetConfigReader();
    Label lblScaling;
    Label lblAppDimensions;
    Label lblVersionJVM;
    Label lblTabCount;
    Rectangle2D visualBounds = CONFIG.getConfiguration().getPrimaryScreen().getVisualBounds();
    int appWidth = (int) visualBounds.getWidth();
    int appHeight = (int) visualBounds.getHeight();
    String rtv = System.getProperty("java.runtime.version");
    if (null == rtv) {
        // bogus one - should NEVER happen
        rtv = "1.1.0_11-b32";
    }
    lblTabCount = new Label("Number of Tabs: " + Integer.toString(CONFIG.getTabs().size()));
    String scalingString = "Scaling: ";
    if (CONFIG.getConfiguration().isAutoScale()) {
        scalingString += "[AutoScale] ";
    }
    scalingString += String.format("%.2f", CONFIG.getConfiguration().getScaleFactor());
    lblScaling = new Label(scalingString);
    CONFIG.getConfiguration().getScaleProperty().addListener(new // when the scale changes
    ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number number, Number number2) {
            String scalingString = "Scaling: ";
            if (CONFIG.getConfiguration().isAutoScale()) {
                scalingString += "[AutoScale] ";
            }
            scalingString += String.format("%.2f", CONFIG.getConfiguration().getScaleFactor());
            lblScaling.setText(scalingString);
        }
    });
    lblAppDimensions = new Label("Screen Size: " + Integer.toString(appWidth) + "x" + Integer.toString(appHeight));
    lblVersionJVM = new Label("JVM Version - " + rtv);
    grid.add(lblTabCount, column, iStartRow++);
    grid.add(lblScaling, column, iStartRow++);
    grid.add(lblAppDimensions, column, iStartRow++);
    grid.add(lblVersionJVM, column, iStartRow++);
    return iStartRow;
}
Also used : TaskManager(kutch.biff.marvin.task.TaskManager) Label(javafx.scene.control.Label) Rectangle2D(javafx.geometry.Rectangle2D) ConfigurationReader(kutch.biff.marvin.configuration.ConfigurationReader)

Example 10 with Rectangle2D

use of javafx.geometry.Rectangle2D in project Board-Instrumentation-Framework by intel.

the class Marvin method FinishLoad.

public void FinishLoad(Stage stage) {
    stage.setIconified(true);
    long elapsedTime = BeginLoadProcess();
    LOGGER.info("Time taken to load Configuration: " + Long.toString(elapsedTime) + "ms.");
    if (null == this.appConfig) {
        Platform.exit();
        return;
    }
    _Config.getConfiguration().setAppStage(stage);
    if (null == _objTabPane) {
        _objTabPane = new TabPane();
        _objTabPane.setSide(_Config.getConfiguration().getSide());
    }
    GridPane sceneGrid = new GridPane();
    Scene scene = null;
    Rectangle2D visualBounds = _Config.getConfiguration().getPrimaryScreen().getVisualBounds();
    int appWidth = (int) visualBounds.getWidth();
    int appHeight = (int) visualBounds.getHeight();
    if (appConfig.getWidth() > 0) {
        appWidth = appConfig.getWidth();
    } else {
        appConfig.setWidth(appWidth);
    }
    if (appConfig.getHeight() > 0) {
        appHeight = appConfig.getHeight();
    } else {
        appConfig.setHeight(appHeight);
    }
    sceneGrid.add(_objTabPane, 0, 1);
    // sceneGrid.setStyle("-fx-background-color:red;");
    SetupSizeCheckPane(sceneGrid);
    // sceneGrid.setMaxHeight(340);
    if (null != _Config.getConfiguration().getMenuBar() && true == _Config.getConfiguration().getShowMenuBar()) {
        // vbox.getChildren().add(_Config.getConfiguration().getMenuBar());
        GridPane.setHalignment(_Config.getConfiguration().getMenuBar(), HPos.LEFT);
        GridPane.setValignment(_Config.getConfiguration().getMenuBar(), VPos.TOP);
        sceneGrid.add(_Config.getConfiguration().getMenuBar(), 0, 0);
    }
    scene = new Scene(sceneGrid);
    _Config.getConfiguration().getCurrentHeightProperty().bind(scene.heightProperty());
    _Config.getConfiguration().getCurrentWidthProperty().bind(scene.widthProperty());
    _objTabPane.prefWidthProperty().bind(scene.widthProperty());
    _objTabPane.prefHeightProperty().bind(scene.heightProperty());
    SetAppStyle(scene.getStylesheets());
    if (false == SetupGoodies(_objTabPane)) {
        JOptionPane.showMessageDialog(null, "Error loading Configuation. \nCheck log file.", "Configuration Error", JOptionPane.ERROR_MESSAGE);
        Platform.exit();
        return;
    }
    if (false == _receiveServer.Setup(_Config.getConfiguration().getAddress(), _Config.getConfiguration().getPort())) {
        JOptionPane.showMessageDialog(null, "Error setting up Network Configuation. \nCheck log file.", "Configuration Error", JOptionPane.ERROR_MESSAGE);
        Platform.exit();
        return;
    }
    // go resize based upon scaling
    checkSize(stage, scene, sceneGrid);
    stage.setTitle(_Config.getConfiguration().getAppTitle());
    stage.setIconified(false);
    stage.setScene(scene);
    stage.setHeight(appHeight);
    stage.setWidth(appWidth);
    if (_Config.getConfiguration().getKioskMode()) {
        stage.initStyle(StageStyle.UNDECORATED);
    }
    if (true == ShowHelp) {
        DisplayHelp();
    }
    if (_Config.getConfiguration().getIgnoreWebCerts()) {
        DisableWebCerts();
    }
    _stage = stage;
    TimerInterval = _Config.getConfiguration().getTimerInterval();
    lastTimerCall = System.currentTimeMillis() + TimerInterval;
    LastMemoryUsageReportingTime = lastTimerCall;
    strOldSuffix = "dummy";
    _animationTimer = new // can't update the Widgets outside of GUI thread, so this is a little worker to do so
    AnimationTimer() {

        boolean Showing = false;

        @Override
        public void handle(long now) {
            if (Configuration.getConfig().terminating()) {
                return;
            }
            if (!Showing && _Splash.isSplashClosed()) {
                // will only happen once
                try {
                    Showing = true;
                    Thread.currentThread().setName("Animation Timer Thread");
                    SetupDebugToolTips();
                    BeginServerEtc();
                    _Splash.appVisible();
                } catch (Exception e) {
                    StringWriter strWriter = new StringWriter();
                    PrintWriter pntWriter = new PrintWriter(strWriter);
                    e.printStackTrace(pntWriter);
                    LOGGER.severe(strWriter.toString());
                    JOptionPane.showMessageDialog(null, "Error trying to launch application. \nCheck log file.", "Error", JOptionPane.ERROR_MESSAGE);
                    Platform.exit();
                }
                Showing = true;
                return;
            }
            if (System.currentTimeMillis() > lastTimerCall + TimerInterval) {
                _DataMgr.PerformUpdates();
                _Config.getConfiguration().DetermineMemorex();
                if (// title could be 'recorded' 'lived'
                !strOldSuffix.equals(_Config.getConfiguration().TitleSuffix)) {
                    _stage.setTitle(_Config.getConfiguration().getAppTitle() + _Config.getConfiguration().TitleSuffix);
                    strOldSuffix = _Config.getConfiguration().TitleSuffix;
                }
                // for remote marvin admin updates, can't update gui outside of gui thread
                TaskManager.getTaskManager().PerformDeferredTasks();
                lastTimerCall = System.currentTimeMillis();
            } else if (ReportMemoryUsage && System.currentTimeMillis() > LastMemoryUsageReportingTime + MemoryUsageReportingInterval) {
                LastMemoryUsageReportingTime = System.currentTimeMillis();
                long freeMem = Runtime.getRuntime().freeMemory();
                long totalMem = Runtime.getRuntime().maxMemory();
                long usedMem = totalMem - freeMem;
                usedMem /= 1024.0;
                String MBMemStr = NumberFormat.getNumberInstance(Locale.US).format(usedMem / 1024);
                // String BytesStr = NumberFormat.getNumberInstance(Locale.US).format(usedMem);
                LOGGER.info("Used Memory: " + MBMemStr + " MB.");
            }
        }
    };
    int waitBeforeRun = ShowSplash ? SplashWait : NoSplashWait;
    // Start goodies in a few seconds
    new java.util.Timer().schedule(new java.util.TimerTask() {

        @Override
        public void run() {
            _animationTimer.start();
            this.cancel();
        }
    }, waitBeforeRun);
    DumpAllWidgetsInformation();
    stage.setX(_Config.getConfiguration().getPrimaryScreen().getVisualBounds().getMinX());
    stage.setY(_Config.getConfiguration().getPrimaryScreen().getVisualBounds().getMinY());
}
Also used : TabPane(javafx.scene.control.TabPane) GridPane(javafx.scene.layout.GridPane) Rectangle2D(javafx.geometry.Rectangle2D) Scene(javafx.scene.Scene) IOException(java.io.IOException) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Aggregations

Rectangle2D (javafx.geometry.Rectangle2D)76 Image (javafx.scene.image.Image)14 Scene (javafx.scene.Scene)10 Screen (javafx.stage.Screen)10 Stage (javafx.stage.Stage)7 Point2D (javafx.geometry.Point2D)6 IOException (java.io.IOException)5 ImageView (javafx.scene.image.ImageView)5 BufferedImage (java.awt.image.BufferedImage)4 File (java.io.File)4 List (java.util.List)4 Color (javafx.scene.paint.Color)4 Optional (java.util.Optional)3 Level (java.util.logging.Level)3 Application (javafx.application.Application)3 Platform (javafx.application.Platform)3 Menu (javafx.scene.control.Menu)3 MenuBar (javafx.scene.control.MenuBar)3 MenuItem (javafx.scene.control.MenuItem)3 Pane (javafx.scene.layout.Pane)3