Search in sources :

Example 56 with Rectangle2D

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

the class MovablePane method loadPositionFromStorage.

public void loadPositionFromStorage() {
    try {
        final String key = getCurrentPositionStorageKey();
        if (key != null) {
            final String value = Main.getProperties().getString(key);
            if (value != null) {
                String[] coords = value.split(";");
                if (coords.length == 2) {
                    double x = Double.parseDouble(coords[0]);
                    double y = Double.parseDouble(coords[1]);
                    Rectangle2D desktop = OverlayStage.getDesktopSize();
                    if (desktop.getWidth() == 0 || desktop.getHeight() == 0)
                        return;
                    if (x + getHeight() > desktop.getMaxX() || x < -getHeight())
                        x = desktop.getMaxX() - getHeight();
                    if (y + getWidth() > desktop.getMaxY() || y < -getWidth())
                        y = desktop.getMaxY() - getWidth();
                    setPosition(new Point2D(x, y));
                    return;
                }
            }
        }
    } catch (Exception e) {
        Main.log(e);
    }
    setDefaultPosition();
}
Also used : Point2D(javafx.geometry.Point2D) Rectangle2D(javafx.geometry.Rectangle2D)

Example 57 with Rectangle2D

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

the class SeparateStage method getDesktopSize.

public static Rectangle2D getDesktopSize() {
    Rectangle2D rect = Screen.getPrimary().getBounds();
    double minX = rect.getMinX(), minY = rect.getMinY();
    double maxX = rect.getMaxX(), maxY = rect.getMaxY();
    for (Screen screen : Screen.getScreens()) {
        Rectangle2D screenRect = screen.getBounds();
        if (minX > screenRect.getMinX()) {
            minX = screenRect.getMinX();
        }
        if (minY > screenRect.getMinY()) {
            minY = screenRect.getMinY();
        }
        if (maxX < screenRect.getMaxX()) {
            maxX = screenRect.getMaxX();
        }
        if (maxY < screenRect.getMaxY()) {
            maxY = screenRect.getMaxY();
        }
    }
    return new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
}
Also used : Screen(javafx.stage.Screen) Rectangle2D(javafx.geometry.Rectangle2D)

Example 58 with Rectangle2D

use of javafx.geometry.Rectangle2D in project CapsLock by chrootRISCassembler.

the class MainFormController method onCreated.

void onCreated(MainHandler handler) {
    this.handler = handler;
    final double PanelImageSideLength;
    Logger.INST.debug("Start calculation of dynamic UI.");
    {
        final Rectangle2D ScreenRect = Screen.getPrimary().getVisualBounds();
        final double FullScreenWidth = ScreenRect.getWidth();
        final double FullScreenHeight = ScreenRect.getHeight();
        final double LeftSize = FullScreenWidth / 5 * 2;
        LeftScrollPane.setPrefViewportWidth(LeftSize);
        LeftScrollPane.setMinViewportWidth(LeftSize);
        PanelImageSideLength = LeftSize * PANEL_RATIO;
        final double Gap = LeftSize * PANEL_GAP_RATIO;
        PanelTilePane.setPadding(new Insets(LeftSize / 12));
        PanelTilePane.setVgap(Gap);
        PanelTilePane.setHgap(Gap);
        final double RightContentPadding = (FullScreenWidth - LeftSize) / 20;
        RightVBox.setPadding(new Insets(RightContentPadding));
        RightVBox.setMaxWidth(FullScreenWidth - LeftSize);
        NameLabel.setFont(Font.font(FullScreenHeight / 20));
        DescriptionLabel.setFont(Font.font(FullScreenHeight / 40));
    }
    Logger.INST.debug("Finished calculation of dynamic UI.");
    final ColorSequencer sequencer = new ColorSequencer();
    final Tooltip tooltip = new Tooltip("ダブルクリックでゲーム起動");
    for (final Game game : handler.getGameList()) {
        final Image panelImage;
        final Path panelPath = game.getPanel();
        if (panelPath == null) {
            panelImage = CharPanelGenerator.generate(game.getName().charAt(0), sequencer.get());
        } else {
            panelImage = new Image(panelPath.toUri().toString());
        }
        final ImageView view = new ImageView(panelImage);
        view.setPreserveRatio(false);
        view.setFitWidth(PanelImageSideLength);
        view.setFitHeight(PanelImageSideLength);
        view.setOnMouseClicked(eve -> onPanelClicked(eve));
        Tooltip.install(view, tooltip);
        view.setUserData(game);
        PanelTilePane.getChildren().add(view);
    }
    contentsAreaController = new ContentsAreaController(ViewStackPane, StackedMediaView, StackedImageView);
    Logger.INST.debug("MainForm window is displayed.");
    System.gc();
}
Also used : Path(java.nio.file.Path) Insets(javafx.geometry.Insets) Game(capslock.game_info.Game) Tooltip(javafx.scene.control.Tooltip) Rectangle2D(javafx.geometry.Rectangle2D) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 59 with Rectangle2D

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

the class CaptureSupportImplTest method capture_region.

@Test
public void capture_region() {
    // when:
    Image image = capturer.captureRegion(new Rectangle2D(0, 0, 100, 200));
    // then:
    assertThat(image.getWidth(), equalTo(100.0));
    assertThat(image.getHeight(), equalTo(200.0));
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) Image(javafx.scene.image.Image) Test(org.junit.Test)

Example 60 with Rectangle2D

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

the class AwtRobotAdapterTest method getCaptureRegion.

@Test
public void getCaptureRegion() {
    // given:
    assumeThat(System.getenv("TRAVIS_OS_NAME"), is(not(equalTo("osx"))));
    // when:
    Rectangle2D region = new Rectangle2D(regionPoint.getX(), regionPoint.getY(), 10, 20);
    Image regionImage = robotAdapter.getCaptureRegion(region);
    // then:
    assertThat(regionImage.getWidth(), is(10.0));
    assertThat(regionImage.getHeight(), is(20.0));
    assertThat(regionImage.getPixelReader().getColor(5, 10), is(Color.web("magenta")));
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) Image(javafx.scene.image.Image) Test(org.junit.Test)

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