Search in sources :

Example 21 with Rectangle

use of javafx.scene.shape.Rectangle in project org.csstudio.display.builder by kasemir.

the class GroupVsPaneDemo method start.

@Override
public void start(Stage primaryStage) {
    Pane pane = new Pane();
    Group group = new Group();
    VBox.setVgrow(group, Priority.NEVER);
    VBox.setVgrow(pane, Priority.NEVER);
    VBox vbox = new VBox(group, pane);
    Rectangle rect1 = new Rectangle(100, 100, 100, 100);
    Rectangle rect2 = new Rectangle(100, 100, 100, 100);
    Rectangle rect3 = new Rectangle(200, 200, 100, 100);
    Rectangle rect4 = new Rectangle(200, 200, 100, 100);
    rect1.setFill(Color.BLUE);
    rect2.setFill(Color.BLUE);
    rect3.setFill(Color.GREEN);
    rect4.setFill(Color.GREEN);
    group.getChildren().addAll(rect1, rect3);
    pane.getChildren().addAll(rect2, rect4);
    Scene scene = new Scene(vbox, 800, 800);
    scene.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        double deltaX;
        switch(e.getCode()) {
            case LEFT:
                deltaX = -10;
                break;
            case RIGHT:
                deltaX = 10;
                break;
            default:
                deltaX = 0;
        }
        rect3.setX(rect3.getX() + deltaX);
        rect4.setX(rect4.getX() + deltaX);
    });
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : Group(javafx.scene.Group) Rectangle(javafx.scene.shape.Rectangle) Scene(javafx.scene.Scene) Pane(javafx.scene.layout.Pane) VBox(javafx.scene.layout.VBox)

Example 22 with Rectangle

use of javafx.scene.shape.Rectangle in project org.csstudio.display.builder by kasemir.

the class PopupDemo method start.

@Override
public void start(final Stage stage) {
    final Popup popup = new Popup();
    final BorderPane content = new BorderPane(new Label("Center"), new Label("Top"), new Label("Right"), new Label("Bottom"), new Label("Left"));
    final Rectangle background = new Rectangle(100, 100, Color.LIGHTGRAY);
    final InvalidationListener resize_background = p -> {
        background.setWidth(content.getWidth());
        background.setHeight(content.getHeight());
    };
    content.widthProperty().addListener(resize_background);
    content.heightProperty().addListener(resize_background);
    final StackPane stack = new StackPane(background, content);
    popup.getContent().addAll(stack);
    final Button toggle_popup = new Button("Popup");
    final ChangeListener<Number> track_moves = (p, old, current) -> {
        // Position popup just below button
        final Bounds bounds = toggle_popup.localToScreen(toggle_popup.getBoundsInLocal());
        popup.setX(bounds.getMinX());
        popup.setY(bounds.getMaxY());
    };
    toggle_popup.setOnAction(event -> {
        if (popup.isShowing()) {
            popup.hide();
            toggle_popup.getScene().getWindow().xProperty().removeListener(track_moves);
            toggle_popup.getScene().getWindow().yProperty().removeListener(track_moves);
        } else {
            toggle_popup.getScene().getWindow().xProperty().addListener(track_moves);
            toggle_popup.getScene().getWindow().yProperty().addListener(track_moves);
            track_moves.changed(null, null, null);
            popup.show(stage);
        }
    });
    final BorderPane layout = new BorderPane(toggle_popup);
    stage.setScene(new Scene(layout));
    stage.show();
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) Color(javafx.scene.paint.Color) Label(javafx.scene.control.Label) Rectangle(javafx.scene.shape.Rectangle) StackPane(javafx.scene.layout.StackPane) InvalidationListener(javafx.beans.InvalidationListener) Application(javafx.application.Application) Popup(javafx.stage.Popup) Stage(javafx.stage.Stage) BorderPane(javafx.scene.layout.BorderPane) ChangeListener(javafx.beans.value.ChangeListener) Bounds(javafx.geometry.Bounds) BorderPane(javafx.scene.layout.BorderPane) Button(javafx.scene.control.Button) Popup(javafx.stage.Popup) Bounds(javafx.geometry.Bounds) Label(javafx.scene.control.Label) Rectangle(javafx.scene.shape.Rectangle) InvalidationListener(javafx.beans.InvalidationListener) Scene(javafx.scene.Scene) StackPane(javafx.scene.layout.StackPane)

Example 23 with Rectangle

use of javafx.scene.shape.Rectangle in project blue by kunstmusik.

the class BSBObjectViewHolder method setupResizeHandles.

private void setupResizeHandles(Rectangle rect, BSBEditSelection selection) {
    if (!(bsbObjectView instanceof ResizeableView)) {
        return;
    }
    BooleanBinding visibleBinding = Bindings.createBooleanBinding(() -> rect.isVisible() && selection.selection.size() == 1, rect.visibleProperty(), selection.selection);
    rView = (ResizeableView) bsbObjectView;
    if (rView.canResizeWidgetWidth()) {
        Rectangle resizeLeftHandle = new Rectangle(5, 5);
        resizeLeftHandle.setManaged(false);
        resizeLeftHandle.setFill(Color.rgb(0, 255, 0));
        resizeLeftHandle.setLayoutX(-2);
        resizeLeftHandle.yProperty().bind(rect.heightProperty().divide(2).subtract(2));
        resizeLeftHandle.visibleProperty().bind(visibleBinding);
        resizeLeftHandle.setCursor(Cursor.W_RESIZE);
        resizeLeftHandle.setOnMousePressed(evt -> recordMouseOrigin(evt));
        resizeLeftHandle.setOnMouseDragged(evt -> resizeLeft(evt));
        Rectangle resizeRightHandle = new Rectangle(5, 5);
        resizeRightHandle.setManaged(false);
        resizeRightHandle.setFill(Color.rgb(0, 255, 0));
        resizeRightHandle.xProperty().bind(rect.widthProperty().subtract(2));
        resizeRightHandle.yProperty().bind(rect.heightProperty().divide(2).subtract(2));
        resizeRightHandle.visibleProperty().bind(visibleBinding);
        resizeRightHandle.setCursor(Cursor.E_RESIZE);
        resizeRightHandle.setOnMousePressed(evt -> recordMouseOrigin(evt));
        resizeRightHandle.setOnMouseDragged(evt -> resizeRight(evt));
        getChildren().addAll(resizeLeftHandle, resizeRightHandle);
    }
    if (rView.canResizeWidgetHeight()) {
        Rectangle resizeTopHandle = new Rectangle(5, 5);
        resizeTopHandle.setManaged(false);
        resizeTopHandle.setFill(Color.rgb(0, 255, 0));
        resizeTopHandle.setLayoutY(-2);
        resizeTopHandle.xProperty().bind(rect.widthProperty().divide(2).subtract(2));
        resizeTopHandle.visibleProperty().bind(visibleBinding);
        resizeTopHandle.setCursor(Cursor.N_RESIZE);
        resizeTopHandle.setOnMousePressed(evt -> recordMouseOrigin(evt));
        resizeTopHandle.setOnMouseDragged(evt -> resizeUp(evt));
        Rectangle resizeBottomHandle = new Rectangle(5, 5);
        resizeBottomHandle.setManaged(false);
        resizeBottomHandle.setFill(Color.rgb(0, 255, 0));
        resizeBottomHandle.yProperty().bind(rect.heightProperty().subtract(2));
        resizeBottomHandle.xProperty().bind(rect.widthProperty().divide(2).subtract(2));
        resizeBottomHandle.visibleProperty().bind(visibleBinding);
        resizeBottomHandle.setCursor(Cursor.S_RESIZE);
        resizeBottomHandle.setOnMousePressed(evt -> recordMouseOrigin(evt));
        resizeBottomHandle.setOnMouseDragged(evt -> resizeDown(evt));
        getChildren().addAll(resizeTopHandle, resizeBottomHandle);
    }
}
Also used : BooleanBinding(javafx.beans.binding.BooleanBinding) Rectangle(javafx.scene.shape.Rectangle)

Example 24 with Rectangle

use of javafx.scene.shape.Rectangle in project blue by kunstmusik.

the class BSBObjectViewHolder method resizeDown.

protected void resizeDown(MouseEvent evt) {
    Rectangle r = (Rectangle) evt.getSource();
    Point2D curPoint = r.localToParent(evt.getX(), evt.getY());
    curPoint = localToParent(curPoint);
    GridSettings grid = selection.getGridSettings();
    int diff = (int) (curPoint.getY() - mouseOrigin.getY());
    int newHeight = (int) originBounds.getHeight() + diff;
    if (grid.isSnapEnabled()) {
        double top = getLayoutY();
        double bottom = top + newHeight;
        int h = grid.getHeight();
        newHeight = (int) ((Math.round(bottom / h) * h) - top);
    }
    newHeight = Math.max(newHeight, rView.getWidgetMinimumHeight());
    if (newHeight != rView.getWidgetHeight()) {
        rView.setWidgetHeight(newHeight);
    }
    evt.consume();
}
Also used : Point2D(javafx.geometry.Point2D) Rectangle(javafx.scene.shape.Rectangle) GridSettings(blue.orchestra.blueSynthBuilder.GridSettings)

Example 25 with Rectangle

use of javafx.scene.shape.Rectangle in project blue by kunstmusik.

the class BSBObjectViewHolder method resizeRight.

protected void resizeRight(MouseEvent evt) {
    Rectangle r = (Rectangle) evt.getSource();
    Point2D curPoint = r.localToParent(evt.getX(), evt.getY());
    curPoint = localToParent(curPoint);
    GridSettings grid = selection.getGridSettings();
    int diff = (int) (curPoint.getX() - mouseOrigin.getX());
    int newWidth = (int) originBounds.getWidth() + diff;
    if (grid.isSnapEnabled()) {
        double left = getLayoutX();
        double right = left + newWidth;
        int w = grid.getWidth();
        newWidth = (int) ((Math.round(right / w) * w) - left);
    }
    newWidth = Math.max(newWidth, rView.getWidgetMinimumWidth());
    if (newWidth != rView.getWidgetWidth()) {
        rView.setWidgetWidth(newWidth);
    }
    evt.consume();
}
Also used : Point2D(javafx.geometry.Point2D) Rectangle(javafx.scene.shape.Rectangle) GridSettings(blue.orchestra.blueSynthBuilder.GridSettings)

Aggregations

Rectangle (javafx.scene.shape.Rectangle)135 Text (javafx.scene.text.Text)23 Entity (com.almasb.fxgl.entity.Entity)21 Point2D (javafx.geometry.Point2D)17 Circle (javafx.scene.shape.Circle)16 Group (javafx.scene.Group)13 Pane (javafx.scene.layout.Pane)13 Scene (javafx.scene.Scene)11 Color (javafx.scene.paint.Color)11 EntityView (com.almasb.fxgl.entity.view.EntityView)10 Label (javafx.scene.control.Label)10 HitBox (com.almasb.fxgl.physics.HitBox)8 TextFlow (javafx.scene.text.TextFlow)8 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)7 Node (javafx.scene.Node)7 PlayerControl (common.PlayerControl)6 Timeline (javafx.animation.Timeline)6 StackPane (javafx.scene.layout.StackPane)6 Stage (javafx.stage.Stage)6 Region (javafx.scene.layout.Region)5