Search in sources :

Example 46 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 47 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 48 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 49 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)

Example 50 with Rectangle

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

the class PhysicsSample method initGame.

@Override
protected void initGame() {
    playerControl = new PlayerControl();
    player = Entities.builder().type(Type.PLAYER).at(100, 100).bbox(new HitBox("PLAYER_BODY", BoundingShape.box(40, 40))).viewFromNode(new Rectangle(40, 40, Color.BLUE)).with(playerControl).build();
    enemy = Entities.builder().type(Type.ENEMY).at(200, 100).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).build();
    // 2. we need to add Collidable component and set its value to true
    // so that collision system can 'see' our entities
    player.addComponent(new CollidableComponent(true));
    enemy.addComponent(new CollidableComponent(true));
    getGameWorld().addEntities(player, enemy);
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle) PlayerControl(common.PlayerControl)

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