From e42b02763af5aaf6e875e802a87463da71cd8599 Mon Sep 17 00:00:00 2001 From: "J. Neugebauer" Date: Wed, 6 Jul 2022 21:15:08 +0200 Subject: [PATCH] =?UTF-8?q?width=20/=20height=20umbenannt,=20damit=20Const?= =?UTF-8?q?ants=20nicht=20=C3=BCberschrieben=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dies ist ein generelles Problem. Wenn in Objekten die von Constants erben width und height als Objektvariablen genutzt werden sollen, ist die Größe der Zeichenleinwand nicht mehr direkt abrufbar. Ggf. sollten die Variablen in Constants spezifischer benannt werden (z.B. `zmwidth` oder `canvaWidth`). --- src/schule/ngb/zm/shapes/Picture.java | 28 ++++++++++++------------ src/schule/ngb/zm/shapes/ShapeGroup.java | 20 ++++++++--------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/schule/ngb/zm/shapes/Picture.java b/src/schule/ngb/zm/shapes/Picture.java index a760758..5141817 100644 --- a/src/schule/ngb/zm/shapes/Picture.java +++ b/src/schule/ngb/zm/shapes/Picture.java @@ -14,9 +14,9 @@ public class Picture extends Shape { private BufferedImage image; - private double width; + private double imgWidth; - private double height; + private double imgHeight; public Picture( String source ) { this(0, 0, source); @@ -30,8 +30,8 @@ public class Picture extends Shape { throw new IllegalArgumentException("Could not initialize image from source " + source); } - width = image.getWidth(); - height = image.getHeight(); + imgWidth = image.getWidth(); + imgHeight = image.getHeight(); this.anchor = Options.Direction.CENTER; } @@ -55,25 +55,25 @@ public class Picture extends Shape { g.drawImage(pic.image, 0, 0, null); g.dispose(); - width = image.getWidth(); - height = image.getHeight(); + imgWidth = image.getWidth(); + imgHeight = image.getHeight(); } } public double getWidth() { - return width; + return imgWidth; } public void setWidth( double width ) { - scale(width / this.width); + scale(width / this.imgWidth); } public double getHeight() { - return height; + return imgHeight; } public void setHeight( double height ) { - scale(height / this.height); + scale(height / this.imgHeight); } public BufferedImage getImage() { @@ -83,13 +83,13 @@ public class Picture extends Shape { @Override public void scale( double factor ) { super.scale(factor); - width *= factor; - height *= factor; + imgWidth *= factor; + imgHeight *= factor; } @Override public java.awt.Shape getShape() { - return new Rectangle2D.Double(0, 0, width, height); + return new Rectangle2D.Double(0, 0, imgWidth, imgHeight); } /* @@ -162,7 +162,7 @@ public class Picture extends Shape { AffineTransform current = graphics.getTransform(); graphics.transform(transform); - graphics.drawImage(image, 0, 0, (int) width, (int) height, null); + graphics.drawImage(image, 0, 0, (int) imgWidth, (int) imgHeight, null); graphics.setTransform(current); } diff --git a/src/schule/ngb/zm/shapes/ShapeGroup.java b/src/schule/ngb/zm/shapes/ShapeGroup.java index 100286b..46a56d5 100644 --- a/src/schule/ngb/zm/shapes/ShapeGroup.java +++ b/src/schule/ngb/zm/shapes/ShapeGroup.java @@ -33,9 +33,9 @@ public class ShapeGroup extends Shape { private List shapes; - private double width = -1.0; + private double groupWidth = -1.0; - private double height = -1.0; + private double groupHeight = -1.0; public ShapeGroup() { super(); @@ -118,23 +118,23 @@ public class ShapeGroup extends Shape { @Override public double getWidth() { - if( width < 0 ) { + if( groupWidth < 0 ) { calculateBounds(); } - return width; + return groupWidth; } @Override public double getHeight() { - if( height < 0 ) { + if( groupHeight < 0 ) { calculateBounds(); } - return height; + return groupHeight; } private void invalidateBounds() { - width = -1.0; - height = -1.0; + groupWidth = -1.0; + groupHeight = -1.0; } private void calculateBounds() { @@ -148,8 +148,8 @@ public class ShapeGroup extends Shape { maxy = Math.max(maxy, bounds.y + bounds.height); } - width = maxx - minx; - height = maxy - miny; + groupWidth = maxx - minx; + groupHeight = maxy - miny; } @Override