Search in sources :

Example 26 with Point2D

use of javafx.geometry.Point2D in project fxexperience2 by EricCanull.

the class RotatorControl method rotatorMouseDragged.

@FXML
void rotatorMouseDragged(MouseEvent e) {
    final Parent p = rotator_dial.getParent();
    final Bounds b = rotator_dial.getLayoutBounds();
    final Double centerX = b.getMinX() + (b.getWidth() / 2);
    final Double centerY = b.getMinY() + (b.getHeight() / 2);
    final Point2D center = p.localToParent(centerX, centerY);
    final Point2D mouse = p.localToParent(e.getX(), e.getY());
    final Double deltaX = mouse.getX() - center.getX();
    final Double deltaY = mouse.getY() - center.getY();
    final Double radians = Math.atan2(deltaY, deltaX);
    rotate(Math.toDegrees(radians));
}
Also used : Parent(javafx.scene.Parent) Point2D(javafx.geometry.Point2D) Bounds(javafx.geometry.Bounds) FXML(javafx.fxml.FXML)

Example 27 with Point2D

use of javafx.geometry.Point2D in project bitsquare by bitsquare.

the class InputTextField method getErrorPopupPosition.

private Point2D getErrorPopupPosition() {
    Window window = getScene().getWindow();
    Point2D point;
    point = layoutReference.localToScene(0, 0);
    double x = Math.floor(point.getX() + window.getX() + layoutReference.getWidth() + 20 - getPadding().getLeft() - getPadding().getRight());
    double y = Math.floor(point.getY() + window.getY() + getHeight() / 2 - getPadding().getTop() - getPadding().getBottom());
    return new Point2D(x, y);
}
Also used : Window(javafx.stage.Window) Point2D(javafx.geometry.Point2D)

Example 28 with Point2D

use of javafx.geometry.Point2D in project Gargoyle by callakrsos.

the class DockNode method setFloating.

/**
	 * Whether the node is currently floating.
	 *
	 * @param floating Whether the node is currently floating.
	 * @param translation null The offset of the node after being set floating. Used for aligning it
	 *        with its layout bounds inside the dock pane when it becomes detached. Can be null
	 *        indicating no translation.
	 *
	 *
	 *        tansalation param value is value set (screenX,screenY)
	 */
public void setFloating(boolean floating, Point2D translation) {
    if (floating && !this.isFloating()) {
        // position the new stage relative to the old scene offset
        Point2D floatScene = this.localToScene(0, 0);
        Point2D floatScreen = this.localToScreen(0, 0);
        // setup window stage
        dockTitleBar.setVisible(this.isCustomTitleBar());
        dockTitleBar.setManaged(this.isCustomTitleBar());
        if (this.isDocked()) {
            this.undock();
        }
        stage = new Stage();
        stage.initStyle(stageStyle);
        stage.titleProperty().bind(titleProperty);
        if (dockPane != null && dockPane.getScene() != null && dockPane.getScene().getWindow() != null) {
            stage.initOwner(dockPane.getScene().getWindow());
        }
        if (null == stage.getOwner() && null != this.owner)
            stage.initOwner(this.owner);
        /* append close handler. 2017-05-29 by kyj.*/
        EventHandler<WindowEvent> closeHandler = ev -> {
            try {
                ObservableList<Node> childrenUnmodifiable = null;
                if (dockPane != null)
                    dockPane.getChildrenUnmodifiable();
                else
                    childrenUnmodifiable = FXCollections.observableArrayList(getContents());
                Consumer<Closeable> clo = n -> {
                    try {
                        n.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                };
                childrenUnmodifiable.stream().filter(n -> n instanceof Closeable).map(n -> (Closeable) n).forEach(clo);
            } catch (Exception e) {
                e.printStackTrace();
            }
        };
        //			stage.setOnCloseRequest(value);
        stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, closeHandler);
        // offset the new stage to cover exactly the area the dock was local to the scene
        // this is useful for when the user presses the + sign and we have no information
        // on where the mouse was clicked
        // the border pane allows the dock node to
        // have a drop shadow effect on the border
        // but also maintain the layout of contents
        // such as a tab that has no content
        borderPane = new BorderPane();
        borderPane.getStyleClass().add("dock-node-border");
        borderPane.setCenter(this);
        borderPane.applyCss();
        Scene scene = new Scene(borderPane);
        scene.getStylesheets().add(SkinManager.getInstance().getSkin());
        // apply the floating property so we can get its padding size
        // while it is floating to offset it by the drop shadow
        // this way it pops out above exactly where it was when docked
        this.floatingProperty.set(floating);
        this.applyCss();
        /*
			 * 2016-10-26 apply default value by kyj
			 * tanslation param value is empty , i call api that stage will be located center
			 */
        if (translation != null) {
            Point2D stagePosition = new Point2D(0, 0);
            if (this.isDecorated()) {
                Window owner = this.owner;
                if (null != owner)
                    stagePosition = floatScene.add(new Point2D(owner.getX(), owner.getY()));
                else
                    stagePosition = floatScene.add(new Point2D(0, 0));
            } else {
                if (floatScreen != null)
                    stagePosition = floatScreen;
            }
            if (translation != null) {
                stagePosition = stagePosition.add(translation);
            }
            //				Insets insetsDelta = borderPane.getInsets();
            stage.setX(/*stagePosition.getX() - insetsDelta.getLeft()*/
            translation.getX());
            stage.setY(/*stagePosition.getY() - insetsDelta.getTop()*/
            translation.getY());
        } else
            stage.centerOnScreen();
        if (stageStyle == StageStyle.TRANSPARENT) {
            scene.setFill(null);
        }
        stage.setResizable(this.isStageResizable());
        if (this.isStageResizable()) {
            stage.addEventFilter(MouseEvent.MOUSE_PRESSED, this);
            stage.addEventFilter(MouseEvent.MOUSE_MOVED, this);
            stage.addEventFilter(MouseEvent.MOUSE_DRAGGED, this);
        }
        // we want to set the client area size
        // without this it subtracts the native border sizes from the scene
        // size
        stage.sizeToScene();
        stage.setScene(scene);
        stage.show();
    } else if (!floating && this.isFloating()) {
        this.floatingProperty.set(floating);
        stage.removeEventFilter(MouseEvent.MOUSE_PRESSED, this);
        stage.removeEventFilter(MouseEvent.MOUSE_MOVED, this);
        stage.removeEventFilter(MouseEvent.MOUSE_DRAGGED, this);
        stage.close();
    }
}
Also used : EventHandler(javafx.event.EventHandler) StageStyle(javafx.stage.StageStyle) Scene(javafx.scene.Scene) PseudoClass(javafx.css.PseudoClass) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) VBox(javafx.scene.layout.VBox) Insets(javafx.geometry.Insets) Point2D(javafx.geometry.Point2D) WindowEvent(javafx.stage.WindowEvent) ObjectProperty(javafx.beans.property.ObjectProperty) Rectangle2D(javafx.geometry.Rectangle2D) Node(javafx.scene.Node) Screen(javafx.stage.Screen) Consumer(java.util.function.Consumer) Cursor(javafx.scene.Cursor) Priority(javafx.scene.layout.Priority) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Closeable(java.io.Closeable) Window(javafx.stage.Window) SkinManager(com.kyj.fx.voeditor.visual.momory.SkinManager) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) StringProperty(javafx.beans.property.StringProperty) Window(javafx.stage.Window) BorderPane(javafx.scene.layout.BorderPane) Consumer(java.util.function.Consumer) Point2D(javafx.geometry.Point2D) ObservableList(javafx.collections.ObservableList) Closeable(java.io.Closeable) WindowEvent(javafx.stage.WindowEvent) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene)

Example 29 with Point2D

use of javafx.geometry.Point2D in project Gargoyle by callakrsos.

the class CaptureScreenController method addItemEvent.

protected void addItemEvent(Node newNode) {
    //		newNode.getTransforms().add(new Scale(1.3, 1.3));
    initLocation.put(newNode, new Location());
    newNode.getTransforms().add(scale);
    newNode.setOnMouseDragged(ev -> {
        Location location = initLocation.get(newNode);
        Point2D dragAnchor = location.getDragAnchor();
        double dragX = ev.getSceneX() - dragAnchor.getX();
        double dragY = ev.getSceneY() - dragAnchor.getY();
        double newXPosition = location.getInitX() + dragX;
        double newYPosition = location.getInitY() + dragY;
        newNode.setTranslateX(newXPosition);
        newNode.setTranslateY(newYPosition);
        ev.consume();
    });
    newNode.setOnMousePressed(ev -> {
        Location location = initLocation.get(newNode);
        location.setInitX(newNode.getTranslateX());
        location.setInitY(newNode.getTranslateY());
        location.setDragAnchor(new Point2D(ev.getSceneX(), ev.getSceneY()));
        ev.consume();
    });
}
Also used : Point2D(javafx.geometry.Point2D)

Aggregations

Point2D (javafx.geometry.Point2D)29 Point3D (org.fxyz.geometry.Point3D)8 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Collectors (java.util.stream.Collectors)7 IntStream (java.util.stream.IntStream)7 TriangleMesh (javafx.scene.shape.TriangleMesh)7 Face3 (org.fxyz.geometry.Face3)7 HashMap (java.util.HashMap)6 DoubleStream (java.util.stream.DoubleStream)6 IntegerProperty (javafx.beans.property.IntegerProperty)6 ObjectProperty (javafx.beans.property.ObjectProperty)6 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)6 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)6 DepthTest (javafx.scene.DepthTest)6 CullFace (javafx.scene.shape.CullFace)6 DrawMode (javafx.scene.shape.DrawMode)6 FloatCollector (org.fxyz.utils.FloatCollector)6 DoubleProperty (javafx.beans.property.DoubleProperty)5 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)5