Search in sources :

Example 36 with Rectangle

use of javafx.scene.shape.Rectangle in project tilesfx by HanSolo.

the class StockTileSkin method resize.

@Override
protected void resize() {
    super.resize();
    graphBounds = new Rectangle(inset, size * 0.6, width - doubleInset, height - size * 0.71);
    referenceLine.setStartX(graphBounds.getX());
    referenceLine.setEndX(graphBounds.getX() + graphBounds.getWidth());
    handleCurrentValue(tile.getValue());
    if (tile.getAveragingPeriod() < 250) {
        sparkLine.setStrokeWidth(size * 0.01);
        dot.setRadius(size * 0.014);
    } else if (tile.getAveragingPeriod() < 500) {
        sparkLine.setStrokeWidth(size * 0.0075);
        dot.setRadius(size * 0.0105);
    } else {
        sparkLine.setStrokeWidth(size * 0.005);
        dot.setRadius(size * 0.007);
    }
    drawTriangle();
    indicatorPane.setPadding(new Insets(0, size * 0.0175, 0, 0));
    resizeStaticText();
    resizeDynamicText();
    changeText.setPrefWidth(0.6 * width - size * 0.1);
    changeText.relocate(width - changeText.getPrefWidth() - size * 0.05, graphBounds.getY() - size * 0.175);
    changePercentageFlow.setPrefWidth(0.6 * width - size * 0.1);
    changePercentageFlow.relocate(width - changePercentageFlow.getPrefWidth() - inset, graphBounds.getY() - size * 0.085);
    valueUnitFlow.setMaxWidth(contentBounds.getWidth());
    valueUnitFlow.setMinWidth(contentBounds.getWidth());
    valueUnitFlow.setPrefWidth(contentBounds.getWidth());
    valueUnitFlow.relocate(contentBounds.getX(), contentBounds.getY());
}
Also used : Insets(javafx.geometry.Insets) Rectangle(javafx.scene.shape.Rectangle)

Example 37 with Rectangle

use of javafx.scene.shape.Rectangle in project tilesfx by HanSolo.

the class SwitchSliderTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    mouseEventHandler = e -> {
        final EventType TYPE = e.getEventType();
        final Object SRC = e.getSource();
        if (MouseEvent.MOUSE_PRESSED == TYPE) {
            if (SRC.equals(thumb)) {
                dragStart = thumb.localToParent(e.getX(), e.getY());
                formerThumbPos = (tile.getCurrentValue() - minValue) / range;
                tile.fireTileEvent(VALUE_CHANGING);
            } else if (SRC.equals(switchBorder)) {
                tile.setActive(!tile.isActive());
                tile.fireEvent(SWITCH_PRESSED);
            }
        } else if (MouseEvent.MOUSE_DRAGGED == TYPE) {
            Point2D currentPos = thumb.localToParent(e.getX(), e.getY());
            double dragPos = currentPos.getX() - dragStart.getX();
            thumbDragged((formerThumbPos + dragPos / trackLength));
        } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
            if (SRC.equals(thumb)) {
                tile.fireTileEvent(VALUE_CHANGED);
            } else if (SRC.equals(switchBorder)) {
                tile.fireEvent(SWITCH_RELEASED);
            }
        }
    };
    selectedListener = o -> moveThumb();
    valueListener = o -> {
        if (tile.isActive() && tile.getValue() != tile.getMinValue()) {
            thumb.setFill(tile.getBarColor());
        } else {
            thumb.setFill(tile.getForegroundColor());
        }
    };
    timeline = new Timeline();
    timeline.setOnFinished(event -> thumb.setFill(tile.isActive() ? tile.getBarColor() : tile.getForegroundColor()));
    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());
    text = new Text(tile.getText());
    text.setFill(tile.getUnitColor());
    Helper.enableNode(text, tile.isTextVisible());
    valueText = new Text(String.format(locale, formatString, ((tile.getValue() - minValue) / range * 100)));
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible());
    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    Helper.enableNode(unitText, !tile.getUnit().isEmpty());
    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);
    description = new Label(tile.getDescription());
    description.setAlignment(tile.getDescriptionAlignment());
    description.setWrapText(true);
    description.setTextFill(tile.getTextColor());
    Helper.enableNode(description, !tile.getDescription().isEmpty());
    barBackground = new Rectangle(PREFERRED_WIDTH * 0.795, PREFERRED_HEIGHT * 0.0275);
    bar = new Rectangle(0, PREFERRED_HEIGHT * 0.0275);
    thumb = new Circle(PREFERRED_WIDTH * 0.09);
    thumb.setEffect(shadow);
    switchBorder = new Rectangle();
    switchBackground = new Rectangle();
    switchBackground.setMouseTransparent(true);
    switchBackground.setFill(tile.isActive() ? tile.getActiveColor() : tile.getBackgroundColor());
    switchThumb = new Circle();
    switchThumb.setMouseTransparent(true);
    switchThumb.setEffect(shadow);
    getPane().getChildren().addAll(titleText, text, valueUnitFlow, description, barBackground, bar, thumb, switchBorder, switchBackground, switchThumb);
}
Also used : Circle(javafx.scene.shape.Circle) Timeline(javafx.animation.Timeline) EventType(javafx.event.EventType) Point2D(javafx.geometry.Point2D) Label(javafx.scene.control.Label) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) TextFlow(javafx.scene.text.TextFlow)

Example 38 with Rectangle

use of javafx.scene.shape.Rectangle in project tilesfx by HanSolo.

the class SwitchTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    mouseEventHandler = e -> {
        final EventType TYPE = e.getEventType();
        if (MouseEvent.MOUSE_PRESSED == TYPE) {
            tile.setActive(!tile.isActive());
            tile.fireEvent(SWITCH_PRESSED);
        } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
            tile.fireEvent(SWITCH_RELEASED);
        }
    };
    selectedListener = o -> moveThumb();
    timeline = new Timeline();
    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());
    text = new Text(tile.getText());
    text.setFill(tile.getUnitColor());
    Helper.enableNode(text, tile.isTextVisible());
    description = new Label(tile.getDescription());
    description.setAlignment(tile.getDescriptionAlignment());
    description.setWrapText(true);
    description.setTextFill(tile.getTextColor());
    Helper.enableNode(description, !tile.getDescription().isEmpty());
    switchBorder = new Rectangle();
    switchBackground = new Rectangle();
    switchBackground.setMouseTransparent(true);
    switchBackground.setFill(tile.isActive() ? tile.getActiveColor() : tile.getBackgroundColor());
    thumb = new Circle();
    thumb.setMouseTransparent(true);
    thumb.setEffect(shadow);
    getPane().getChildren().addAll(titleText, text, description, switchBorder, switchBackground, thumb);
}
Also used : Circle(javafx.scene.shape.Circle) Timeline(javafx.animation.Timeline) EventType(javafx.event.EventType) Label(javafx.scene.control.Label) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text)

Example 39 with Rectangle

use of javafx.scene.shape.Rectangle in project TestFX by TestFX.

the class BoundsQueryUtilsTest method setupShape.

private static void setupShape() {
    // nodeBounds()
    shape = new Rectangle(0, 0, SHAPE_WIDTH, 0);
    // nodeBoundsInLocal()
    shape.setClip(new Rectangle(0, 0, CLIP_WIDTH, 0));
    // nodeBoundsInParent()
    shape.getTransforms().add(new Translate(TRANSLATE_X, 0));
    // nodeBounds()
    Shape altShape = new Rectangle(0, 0, SHAPE_WIDTH, 0);
    altShape.setFill(Color.GREEN);
    altShape.setStroke(Color.BLACK);
    altShape.setStrokeType(StrokeType.OUTSIDE);
    // nodeBounds(), nodeBoundsInParent()
    altShape.setStrokeWidth(5);
    // nodeBoundsInLocal()
    altShape.setEffect(new BoxBlur(10, 10, 1));
}
Also used : Shape(javafx.scene.shape.Shape) Rectangle(javafx.scene.shape.Rectangle) Translate(javafx.scene.transform.Translate) BoxBlur(javafx.scene.effect.BoxBlur)

Example 40 with Rectangle

use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.

the class SelectedEntitySample method initGame.

@Override
protected void initGame() {
    player = Entities.builder().type(Type.PLAYER).at(100, 100).viewFromNode(new Rectangle(40, 40)).with(new SelectableComponent(true)).buildAndAttach(getGameWorld());
    enemy = Entities.builder().type(Type.ENEMY).at(200, 100).viewFromNode(new Rectangle(40, 40, Color.RED)).with(new SelectableComponent(true)).buildAndAttach(getGameWorld());
    // 2. click on entity and see it being selected
    getGameWorld().selectedEntityProperty().addListener((o, oldEntity, newEntity) -> {
        System.out.println(oldEntity);
        System.out.println(newEntity);
    });
}
Also used : Rectangle(javafx.scene.shape.Rectangle) SelectableComponent(com.almasb.fxgl.entity.component.SelectableComponent)

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