diff --git a/src/main/java/org/example/petshopdesktop/ui/SvgNodeLoader.java b/src/main/java/org/example/petshopdesktop/ui/SvgNodeLoader.java index d9b4c535..a8bda054 100644 --- a/src/main/java/org/example/petshopdesktop/ui/SvgNodeLoader.java +++ b/src/main/java/org/example/petshopdesktop/ui/SvgNodeLoader.java @@ -1,7 +1,7 @@ package org.example.petshopdesktop.ui; import javafx.scene.Group; -import javafx.scene.layout.StackPane; +import javafx.scene.layout.Pane; import javafx.scene.paint.Paint; import javafx.scene.shape.Circle; import javafx.scene.shape.FillRule; @@ -24,18 +24,20 @@ public final class SvgNodeLoader { private SvgNodeLoader() { } - public static StackPane loadSquare(String resourcePath, double size) { + public static Pane loadSquare(String resourcePath, double size) { Group content = readSvg(resourcePath); var bounds = content.getLayoutBounds(); - Group translated = new Group(content); - translated.setTranslateX(-bounds.getMinX()); - translated.setTranslateY(-bounds.getMinY()); - double scale = Math.min(size / bounds.getWidth(), size / bounds.getHeight()); - translated.setScaleX(scale); - translated.setScaleY(scale); - StackPane pane = new StackPane(translated); + Group graphic = new Group(content); + graphic.setScaleX(scale); + graphic.setScaleY(scale); + graphic.relocate( + (size - (bounds.getWidth() * scale)) / 2 - (bounds.getMinX() * scale), + (size - (bounds.getHeight() * scale)) / 2 - (bounds.getMinY() * scale) + ); + + Pane pane = new Pane(graphic); pane.setMinSize(size, size); pane.setPrefSize(size, size); pane.setMaxSize(size, size); @@ -176,6 +178,4 @@ public final class SvgNodeLoader { styleMap.put(attribute, value); } } - - }