package space.m0e.quga.oop.lab56maven.entities.common; import javafx.scene.SnapshotParameters; import javafx.scene.image.Image; import javafx.scene.Group; import javafx.scene.paint.Color; import javafx.scene.paint.ImagePattern; import javafx.scene.shape.Rectangle; public class MiniMap extends Rectangle { private final Group mainGroup; public Rectangle rect = new Rectangle(); public MiniMap(double width, double height,double selectionWidth,double selectionHeight, Group mainGroup) { setHeight(height); setWidth(width); this.mainGroup = mainGroup; setFill(Color.GREY); setStroke(Color.YELLOW); setStrokeWidth(2); rect.setWidth(selectionWidth); rect.setHeight(selectionHeight); rect.setFill(Color.TRANSPARENT); rect.setStroke(Color.BLACK); rect.setStrokeWidth(1); rect.setMouseTransparent(true); updateMap(); } public void updateMap() { Image image = createSnapshot(mainGroup); ImagePattern imagePatternmagePattern = new ImagePattern(image); this.setFill(imagePatternmagePattern); } private Image createSnapshot(Group group) { SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT); return group.snapshot(params, null); } }