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());
}
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);
}
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);
}
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);
});
}
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);
}
Aggregations