Search in sources :

Example 61 with Rectangle2D

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

the class JavafxRobotAdapterTest method getCaptureRegion.

@Test
public void getCaptureRegion() throws InterruptedException {
    assumeThat("skipping: screen capture on macOS uses configured display's color profile", System.getenv("TRAVIS_OS_NAME"), is(not(equalTo("osx"))));
    // given:
    CountDownLatch captureRegionLatch = new CountDownLatch(1);
    // when:
    Rectangle2D region = new Rectangle2D(regionPoint.getX(), regionPoint.getY(), 10, 20);
    CompletableFuture<Image> captureRegionFutureResult = new CompletableFuture<>();
    Platform.runLater(() -> captureRegionFutureResult.complete(robotAdapter.getCaptureRegion(region)));
    // then:
    captureRegionFutureResult.whenComplete((regionImage, throwable) -> {
        if (throwable != null) {
            fail("JavafxRobotAdapter.getCaptureRegion(..) should not have completed exceptionally");
        } else {
            assertThat(regionImage.getWidth(), is(10.0));
            assertThat(regionImage.getHeight(), is(20.0));
            assertThat(regionImage.getPixelReader().getColor(5, 10), is(Color.MAGENTA));
            captureRegionLatch.countDown();
        }
    });
    assertThat(captureRegionLatch.await(5, TimeUnit.SECONDS), is(true));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Rectangle2D(javafx.geometry.Rectangle2D) CountDownLatch(java.util.concurrent.CountDownLatch) Image(javafx.scene.image.Image) Test(org.junit.Test)

Example 62 with Rectangle2D

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

the class AwtRobotAdapter method getCapturePixelColor.

@Override
public Color getCapturePixelColor(Point2D location) {
    Rectangle2D region = new Rectangle2D(location.getX(), location.getY(), 1, 1);
    Image image = getCaptureRegion(region);
    return image.getPixelReader().getColor(0, 0);
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) BufferedImage(java.awt.image.BufferedImage) Image(javafx.scene.image.Image)

Example 63 with Rectangle2D

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

the class FxRobot method capture.

@Override
public Capture capture(Bounds bounds) {
    Rectangle2D region = new Rectangle2D(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
    Image image = context.getCaptureSupport().captureRegion(region);
    return () -> image;
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) Image(javafx.scene.image.Image)

Example 64 with Rectangle2D

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

the class QuadSample method initGame.

@Override
protected void initGame() {
    getGameScene().setBackgroundColor(Color.BLACK);
    Texture ship = texture("player2.png");
    double h = 7;
    System.out.println(h);
    for (int i = 0; i < 10; i++) {
        Texture quad = ship.subTexture(new Rectangle2D(0, i * h, ship.getImage().getWidth(), h));
        quad.setTranslateY(100 + i * h);
        originals.add(quad);
        textures.add(quad.copy());
        textures2.add(quad.toColor(Color.RED));
        getGameScene().addUINode(quad);
    }
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) Texture(com.almasb.fxgl.texture.Texture)

Example 65 with Rectangle2D

use of javafx.geometry.Rectangle2D in project loinc2hpo by monarch-initiative.

the class GitHubPopup method adjustStagePosition.

/**
 * Ensure that popup Stage will be displayed on the same monitor as the parent Stage
 *
 * @param childStage  reference to new window that will appear
 * @param parentStage reference to the primary stage
 * @return a new Stage to display a dialog.
 */
private static Stage adjustStagePosition(Stage childStage, Stage parentStage) {
    ObservableList<Screen> screensForParentWindow = Screen.getScreensForRectangle(parentStage.getX(), parentStage.getY(), parentStage.getWidth(), parentStage.getHeight());
    Screen actual = screensForParentWindow.get(0);
    Rectangle2D bounds = actual.getVisualBounds();
    // set top left position to 35%/25% of screen/monitor width & height
    childStage.setX(bounds.getWidth() * 0.35);
    childStage.setY(bounds.getHeight() * 0.25);
    return childStage;
}
Also used : Screen(javafx.stage.Screen) Rectangle2D(javafx.geometry.Rectangle2D)

Aggregations

Rectangle2D (javafx.geometry.Rectangle2D)96 Image (javafx.scene.image.Image)14 Point2D (javafx.geometry.Point2D)13 Scene (javafx.scene.Scene)11 Color (javafx.scene.paint.Color)11 Screen (javafx.stage.Screen)11 List (java.util.List)8 IOException (java.io.IOException)7 Rectangle (javafx.scene.shape.Rectangle)7 Stage (javafx.stage.Stage)7 GameApplication (com.almasb.fxgl.app.GameApplication)6 GameSettings (com.almasb.fxgl.app.GameSettings)6 FXGL (com.almasb.fxgl.dsl.FXGL)6 KeyCode (javafx.scene.input.KeyCode)6 Duration (javafx.util.Duration)6 Interpolators (com.almasb.fxgl.animation.Interpolators)4 FXGLMath (com.almasb.fxgl.core.math.FXGLMath)4 Entity (com.almasb.fxgl.entity.Entity)4 BufferedImage (java.awt.image.BufferedImage)4 Collectors (java.util.stream.Collectors)4