Search in sources :

Example 21 with Rectangle2D

use of javafx.geometry.Rectangle2D in project TestFX by TestFX.

the class GlassRobotAdapterTest method getCaptureRegion.

@Test
public void getCaptureRegion() {
    // given:
    assumeThat(System.getenv("TRAVIS_OS_NAME"), is(not(equalTo("osx"))));
    // when:
    Bounds bounds = BoundsQueryUtils.boundsOnScreen(region);
    Image regionImage = robotAdapter.getCaptureRegion(new Rectangle2D(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()));
    assertThat(regionImage.getPixelReader().getColor((int) regionImage.getWidth() / 2, (int) regionImage.getHeight() / 2), is(Color.web("magenta")));
}
Also used : Bounds(javafx.geometry.Bounds) Rectangle2D(javafx.geometry.Rectangle2D) Image(javafx.scene.image.Image) Test(org.junit.Test)

Example 22 with Rectangle2D

use of javafx.geometry.Rectangle2D in project JavaFXLibrary by eficode.

the class TestMultipleWindowsController method openOtherWindows.

private void openOtherWindows() {
    Parent root;
    try {
        secondWindow = new Stage();
        thirdWindow = new Stage();
        Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
        // Load FXML for secondWindow
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/javafxlibrary/ui/MultipleWindowsSubUIs/SecondUI.fxml"));
        root = fxmlLoader.load();
        // Second window settings
        secondWindow.setScene(new Scene(root));
        secondWindow.setTitle("Second window");
        secondWindow.setX(screenBounds.getMinX() + 200);
        secondWindow.initStyle(StageStyle.DECORATED);
        secondWindow.getScene().setOnKeyPressed(event -> keyCombinationListener(event));
        secondWindow.getScene().setOnKeyReleased(event -> keyReleaseListener(event));
        secondWindow.show();
        // Load FXML for thirdWindow
        fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/javafxlibrary/ui/MultipleWindowsSubUIs/ThirdUI.fxml"));
        root = fxmlLoader.load();
        // Third window settings
        thirdWindow.setScene(new Scene(root));
        thirdWindow.setTitle("Third window");
        thirdWindow.setX(screenBounds.getMinX() + 600);
        thirdWindow.initStyle(StageStyle.DECORATED);
        thirdWindow.getScene().setOnKeyPressed(event -> keyCombinationListener(event));
        thirdWindow.getScene().setOnKeyReleased(event -> keyReleaseListener(event));
        thirdWindow.show();
    } catch (IOException | NullPointerException e) {
        e.printStackTrace();
    }
}
Also used : Parent(javafx.scene.Parent) Rectangle2D(javafx.geometry.Rectangle2D) Stage(javafx.stage.Stage) IOException(java.io.IOException) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader)

Example 23 with Rectangle2D

use of javafx.geometry.Rectangle2D in project JavaFXLibrary by eficode.

the class ConvenienceKeywords method getPrimaryScreenBounds.

@RobotKeyword("Returns the bounds of primary screen. \n")
public Object getPrimaryScreenBounds() {
    try {
        robotLog("INFO", "Getting the primary screen bounds");
        Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
        return mapObject(new BoundingBox(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()));
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Unable to get primary screen bounds.", e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) BoundingBox(javafx.geometry.BoundingBox) Rectangle2D(javafx.geometry.Rectangle2D) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword)

Example 24 with Rectangle2D

use of javafx.geometry.Rectangle2D in project FXGL by AlmasB.

the class NoiseSample method initGame.

@Override
protected void initGame() {
    Entities.builder().at(100, 100).viewFromNodeWithBBox(new Rectangle(40, 40)).with(new RandomMoveControl(100, 50, 350, new Rectangle2D(0, 0, X_MAX - 0, Y_MAX - 0))).buildAndAttach(getGameWorld());
    Entities.builder().at(50, 350).viewFromNode(new Rectangle(15, 15, Color.DARKCYAN)).buildAndAttach(getGameWorld());
}
Also used : RandomMoveControl(com.almasb.fxgl.entity.control.RandomMoveControl) Rectangle(javafx.scene.shape.Rectangle) Rectangle2D(javafx.geometry.Rectangle2D)

Example 25 with Rectangle2D

use of javafx.geometry.Rectangle2D in project FXGL by AlmasB.

the class BoundingBoxComponentTest method testRange.

@Test
public void testRange() throws Exception {
    bbox.addHitBox(new HitBox("ARM", new Point2D(15, 15), BoundingShape.box(40, 60)));
    Rectangle2D range = bbox.range(10, 10);
    assertThat(range.getMinX(), is(15.0 - 10));
    assertThat(range.getMinY(), is(15.0 - 10));
    assertThat(range.getMaxX(), is(15.0 + 40 + 10));
    assertThat(range.getMaxY(), is(15.0 + 60 + 10));
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) Point2D(javafx.geometry.Point2D) Rectangle2D(javafx.geometry.Rectangle2D) Test(org.junit.jupiter.api.Test)

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