Search in sources :

Example 71 with Rectangle

use of javafx.scene.shape.Rectangle in project JFoenix by jfoenixadmin.

the class JFXRippler method getMask.

// methods that can be changed by extending the rippler class
/**
 * generate the clipping mask
 *
 * @return the mask node
 */
protected Node getMask() {
    double borderWidth = ripplerPane.getBorder() != null ? ripplerPane.getBorder().getInsets().getTop() : 0;
    Bounds bounds = control.getBoundsInParent();
    double width = control.getLayoutBounds().getWidth();
    double height = control.getLayoutBounds().getHeight();
    double diffMinX = Math.abs(control.getBoundsInLocal().getMinX() - control.getLayoutBounds().getMinX());
    double diffMinY = Math.abs(control.getBoundsInLocal().getMinY() - control.getLayoutBounds().getMinY());
    double diffMaxX = Math.abs(control.getBoundsInLocal().getMaxX() - control.getLayoutBounds().getMaxX());
    double diffMaxY = Math.abs(control.getBoundsInLocal().getMaxY() - control.getLayoutBounds().getMaxY());
    Node mask;
    switch(getMaskType()) {
        case RECT:
            mask = new Rectangle(bounds.getMinX() + diffMinX - snappedLeftInset(), bounds.getMinY() + diffMinY - snappedTopInset(), width - 2 * borderWidth, // -0.1 to prevent resizing the anchor pane
            height - 2 * borderWidth);
            break;
        case CIRCLE:
            double radius = Math.min((width / 2) - 2 * borderWidth, (height / 2) - 2 * borderWidth);
            mask = new Circle((bounds.getMinX() + diffMinX + bounds.getMaxX() - diffMaxX) / 2 - snappedLeftInset(), (bounds.getMinY() + diffMinY + bounds.getMaxY() - diffMaxY) / 2 - snappedTopInset(), radius, Color.BLUE);
            break;
        case FIT:
            mask = new Region();
            if (control instanceof Shape) {
                ((Region) mask).setShape((Shape) control);
            } else if (control instanceof Region) {
                ((Region) mask).setShape(((Region) control).getShape());
                JFXNodeUtils.updateBackground(((Region) control).getBackground(), (Region) mask);
            }
            mask.resize(width, height);
            mask.relocate(bounds.getMinX() + diffMinX, bounds.getMinY() + diffMinY);
            break;
        default:
            mask = new Rectangle(bounds.getMinX() + diffMinX - snappedLeftInset(), bounds.getMinY() + diffMinY - snappedTopInset(), width - 2 * borderWidth, // -0.1 to prevent resizing the anchor pane
            height - 2 * borderWidth);
            break;
    }
    return mask;
}
Also used : Circle(javafx.scene.shape.Circle) Shape(javafx.scene.shape.Shape) Bounds(javafx.geometry.Bounds) Node(javafx.scene.Node) Rectangle(javafx.scene.shape.Rectangle) Region(javafx.scene.layout.Region)

Example 72 with Rectangle

use of javafx.scene.shape.Rectangle in project latexdraw by arnobl.

the class ViewShape method getActivatedGroupNodes.

private static Collection<javafx.scene.shape.Shape> getActivatedGroupNodes(final Group gp) {
    // Adding all the shape children
    final Collection<javafx.scene.shape.Shape> shapes = gp.getChildren().stream().filter(node -> node instanceof javafx.scene.shape.Shape && node.isVisible() && !node.isDisable()).map(node -> (javafx.scene.shape.Shape) node).collect(Collectors.toList());
    // Adding all the view shape children
    shapes.addAll(gp.getChildren().stream().filter(node -> node instanceof ViewShape<?> && node.isVisible() && !node.isDisable()).map(vs -> ((ViewShape<?>) vs).getActivatedShapes()).flatMap(st -> st.stream()).collect(Collectors.toList()));
    // Adding the shapes contained in groups that are not view shapes
    shapes.addAll(gp.getChildren().stream().filter(node -> node instanceof Group && !(node instanceof ViewShape<?>)).map(node -> getActivatedGroupNodes((Group) node)).flatMap(st -> st.stream()).collect(Collectors.toList()));
    // Adding the images contained in the group
    shapes.addAll(gp.getChildren().stream().filter(node -> node instanceof ImageView && node.isVisible() && !node.isDisable()).map(node -> {
        final Bounds bounds = node.getBoundsInParent();
        final Rectangle rec = new Rectangle(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
        rec.setFill(Color.WHITE);
        rec.getTransforms().setAll(gp.getLocalToSceneTransform());
        return rec;
    }).collect(Collectors.toList()));
    return shapes;
}
Also used : Parent(javafx.scene.Parent) Color(javafx.scene.paint.Color) Shape(net.sf.latexdraw.model.api.shape.Shape) Flushable(net.sf.latexdraw.util.Flushable) ImageView(javafx.scene.image.ImageView) Collection(java.util.Collection) Optional(java.util.Optional) Rectangle(javafx.scene.shape.Rectangle) Group(javafx.scene.Group) Collectors(java.util.stream.Collectors) Bounds(javafx.geometry.Bounds) Group(javafx.scene.Group) Shape(net.sf.latexdraw.model.api.shape.Shape) Bounds(javafx.geometry.Bounds) Rectangle(javafx.scene.shape.Rectangle) ImageView(javafx.scene.image.ImageView)

Example 73 with Rectangle

use of javafx.scene.shape.Rectangle in project latexdraw by arnobl.

the class Canvas method setVisibleSelectionBorder.

private void setVisibleSelectionBorder(final double x, final double y, final double w, final double h, final boolean ongoing) {
    final Rectangle rec = ongoing ? ongoingSelectionBorder : selectionBorder;
    rec.setLayoutX(x);
    rec.setLayoutY(y);
    rec.setWidth(w);
    rec.setHeight(h);
    rec.setVisible(true);
}
Also used : Rectangle(javafx.scene.shape.Rectangle)

Example 74 with Rectangle

use of javafx.scene.shape.Rectangle in project sis by apache.

the class ColorCell method createRectangle.

/**
 * Creates the graphic to draw in a table cell or combo box cell for showing color(s).
 * This method is invoked for building an editor in {@link #showControlButton()} or for
 * rendering the {@link ColorRamp} in the table.
 *
 * @param  adjust  amount of space (in pixels) to add on the right size.
 *                 Can be a negative number for removing space.
 * @return graphic to draw in a table cell or combo box cell.
 *
 * @see #setColorItem(ColorRamp)
 */
private Rectangle createRectangle(final double adjust) {
    final Rectangle gr = new Rectangle();
    gr.setHeight(HEIGHT);
    gr.widthProperty().bind(widthProperty().add(adjust));
    return gr;
}
Also used : Rectangle(javafx.scene.shape.Rectangle)

Example 75 with Rectangle

use of javafx.scene.shape.Rectangle in project sis by apache.

the class ColorCell method setColorItem.

/**
 * Sets the color representation when no editing is under way. It is caller responsibility to ensure
 * that the current graphic is not a combo box, or that it is safe to remove that combo box from the
 * scene (i.e. that combo box does not have focus anymore).
 *
 * @param  colors  current value of {@link #getItem()}.
 */
private void setColorItem(final ColorRamp colors) {
    assert controlNotFocused();
    Rectangle view = null;
    if (colors != null) {
        final Paint paint = colors.paint();
        if (paint != null) {
            if (colorView == null) {
                colorView = createRectangle(WIDTH_ADJUST);
            }
            view = colorView;
            view.setFill(paint);
        }
    }
    setGraphic(view);
}
Also used : Rectangle(javafx.scene.shape.Rectangle) Paint(javafx.scene.paint.Paint)

Aggregations

Rectangle (javafx.scene.shape.Rectangle)190 Point2D (javafx.geometry.Point2D)33 Text (javafx.scene.text.Text)28 Entity (com.almasb.fxgl.entity.Entity)27 Circle (javafx.scene.shape.Circle)20 Color (javafx.scene.paint.Color)18 HitBox (com.almasb.fxgl.physics.HitBox)16 Pane (javafx.scene.layout.Pane)16 Group (javafx.scene.Group)15 Node (javafx.scene.Node)14 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)12 Scene (javafx.scene.Scene)12 EntityView (com.almasb.fxgl.entity.view.EntityView)10 Label (javafx.scene.control.Label)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 TextFlow (javafx.scene.text.TextFlow)8 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)7 Bounds (javafx.geometry.Bounds)7 KeyCode (javafx.scene.input.KeyCode)7