use of javafx.geometry.Rectangle2D in project Board-Instrumentation-Framework by intel.
the class DynamicTransition method splitImageX.
/**
* Split the given images into vertical tiles defined by noOfTilesX
*
* @param FRONT_IMAGE
* @param BACK_IMAGE
*/
private void splitImageX(final Image FRONT_IMAGE, final Image BACK_IMAGE) {
viewPorts.clear();
for (int i = 0; i < noOfTilesX; i++) {
// Create the viewports
viewPorts.add(new Rectangle2D(i * stepSizeX, 0, stepSizeX, FRONT_IMAGE.getHeight()));
// Update the frontside imageviews
imageViewsFront.get(i).getTransforms().clear();
imageViewsFront.get(i).toFront();
imageViewsFront.get(i).setImage(FRONT_IMAGE);
imageViewsFront.get(i).setViewport(viewPorts.get(i));
// Update the backside imageviews
imageViewsBack.get(i).getTransforms().clear();
imageViewsBack.get(i).setImage(BACK_IMAGE);
imageViewsBack.get(i).setViewport(viewPorts.get(i));
}
}
use of javafx.geometry.Rectangle2D in project FXGL by AlmasB.
the class RigidBodyPhysicsSample method spawnHorizontal.
private void spawnHorizontal(double x, double y) {
var physics = new PhysicsComponent();
physics.setFixtureDef(new FixtureDef().density(4.5f).friction(1.0f).restitution(0.05f));
physics.setBodyType(BodyType.DYNAMIC);
var t = texture("brick.png").subTexture(new Rectangle2D(0, 0, 64, 5));
entityBuilder().at(x, y).viewWithBBox(t).with(physics).buildAndAttach();
}
use of javafx.geometry.Rectangle2D in project FXGL by AlmasB.
the class ImageToParticlesAnimationSample method initGame.
@Override
protected void initGame() {
getGameScene().setBackgroundColor(Color.BLACK);
// based on your image size, you may want to remove the call to .subTexture()
var texture = texture("robot_stand.png").subTexture(new Rectangle2D(50, 30, 200, 220));
pixels = ImagesKt.toPixels(texture.getImage()).stream().filter(p -> !p.getColor().equals(Color.TRANSPARENT)).map(p -> {
var r = new Rectangle(1, 1, p.getColor());
r.setLayoutX(p.getX());
r.setLayoutY(p.getY());
addUINode(r, 250, 150);
return r;
}).collect(Collectors.toList());
}
use of javafx.geometry.Rectangle2D in project FXGL by AlmasB.
the class GraphVisSample method makeNode.
private Entity makeNode(int id) {
var e = entityBuilder().at(FXGLMath.randomPoint(new Rectangle2D(0, 0, getAppWidth(), getAppHeight()))).view(new Circle(NODE_RADIUS, NODE_RADIUS, NODE_RADIUS)).with("id", id).with(new DraggableComponent()).onClick(entity -> {
// here you can find out more info about the node in question
}).buildAndAttach();
nodes.put(id, e);
return e;
}
use of javafx.geometry.Rectangle2D in project FXGL by AlmasB.
the class UINineSliceSample method initUI.
@Override
protected void initUI() {
boolean fromSingleImage = true;
if (fromSingleImage) {
builder = new NineSliceTextureBuilder(texture("9SliceSprite.jpg")).topLeft(new Rectangle2D(0, 0, 53, 53)).top(new Rectangle2D(53, 0, 420, 53)).topRight(new Rectangle2D(473, 0, 52, 53)).left(new Rectangle2D(0, 52, 53, 420)).center(new Rectangle2D(53, 52, 420, 420)).right(new Rectangle2D(473, 52, 52, 420)).botLeft(new Rectangle2D(0, 473, 53, 52)).botRight(new Rectangle2D(473, 473, 52, 52)).bot(new Rectangle2D(53, 473, 473 - 53, 52));
} else {
builder = new NineSliceTextureBuilder(texture("ui_sheet.png")).topLeft(100, 100, 35, 35).topRight(165, 100, 35, 35).botLeft(100, 165, 35, 35).botRight(165, 165, 35, 35).center(135, 135, 30, 30).top(135, 100, 30, 35).bot(135, 165, 30, 35).left(100, 135, 35, 30).right(165, 135, 35, 30);
}
TextField fieldW = new TextField();
fieldW.setText("300");
fieldW.setPrefWidth(100);
TextField fieldH = new TextField();
fieldH.setText("300");
fieldH.setPrefWidth(100);
Button generateBtn = new Button("Generate");
generateBtn.setOnAction(e -> {
if (texture != null) {
getGameScene().removeUINode(texture);
texture.dispose();
}
try {
double w = Double.parseDouble(fieldW.getText());
double h = Double.parseDouble(fieldH.getText());
texture = builder.build((int) w, (int) h);
texture.setTranslateX(100);
getGameScene().addUINode(texture);
} catch (Exception ex) {
ex.printStackTrace();
}
});
Button exportBtn = new Button("Export");
exportBtn.setOnAction(e -> {
if (texture != null) {
var fileChooser = createImageSaverDialog();
var file = fileChooser.showSaveDialog(getGameScene().getRoot().getScene().getWindow());
if (file != null) {
saveImageToFile(texture.getImage(), file);
}
}
});
getGameScene().addUINodes(new VBox(5, fieldW, fieldH, generateBtn, exportBtn));
generateBtn.fire();
}
Aggregations