width / height umbenannt, damit Constants nicht überschrieben werden

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`).
This commit is contained in:
ngb
2022-07-06 21:15:08 +02:00
parent df335c8ff2
commit e42b02763a
2 changed files with 24 additions and 24 deletions

View File

@@ -14,9 +14,9 @@ public class Picture extends Shape {
private BufferedImage image; private BufferedImage image;
private double width; private double imgWidth;
private double height; private double imgHeight;
public Picture( String source ) { public Picture( String source ) {
this(0, 0, source); this(0, 0, source);
@@ -30,8 +30,8 @@ public class Picture extends Shape {
throw new IllegalArgumentException("Could not initialize image from source " + source); throw new IllegalArgumentException("Could not initialize image from source " + source);
} }
width = image.getWidth(); imgWidth = image.getWidth();
height = image.getHeight(); imgHeight = image.getHeight();
this.anchor = Options.Direction.CENTER; this.anchor = Options.Direction.CENTER;
} }
@@ -55,25 +55,25 @@ public class Picture extends Shape {
g.drawImage(pic.image, 0, 0, null); g.drawImage(pic.image, 0, 0, null);
g.dispose(); g.dispose();
width = image.getWidth(); imgWidth = image.getWidth();
height = image.getHeight(); imgHeight = image.getHeight();
} }
} }
public double getWidth() { public double getWidth() {
return width; return imgWidth;
} }
public void setWidth( double width ) { public void setWidth( double width ) {
scale(width / this.width); scale(width / this.imgWidth);
} }
public double getHeight() { public double getHeight() {
return height; return imgHeight;
} }
public void setHeight( double height ) { public void setHeight( double height ) {
scale(height / this.height); scale(height / this.imgHeight);
} }
public BufferedImage getImage() { public BufferedImage getImage() {
@@ -83,13 +83,13 @@ public class Picture extends Shape {
@Override @Override
public void scale( double factor ) { public void scale( double factor ) {
super.scale(factor); super.scale(factor);
width *= factor; imgWidth *= factor;
height *= factor; imgHeight *= factor;
} }
@Override @Override
public java.awt.Shape getShape() { 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(); AffineTransform current = graphics.getTransform();
graphics.transform(transform); 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); graphics.setTransform(current);
} }

View File

@@ -33,9 +33,9 @@ public class ShapeGroup extends Shape {
private List<Shape> shapes; private List<Shape> shapes;
private double width = -1.0; private double groupWidth = -1.0;
private double height = -1.0; private double groupHeight = -1.0;
public ShapeGroup() { public ShapeGroup() {
super(); super();
@@ -118,23 +118,23 @@ public class ShapeGroup extends Shape {
@Override @Override
public double getWidth() { public double getWidth() {
if( width < 0 ) { if( groupWidth < 0 ) {
calculateBounds(); calculateBounds();
} }
return width; return groupWidth;
} }
@Override @Override
public double getHeight() { public double getHeight() {
if( height < 0 ) { if( groupHeight < 0 ) {
calculateBounds(); calculateBounds();
} }
return height; return groupHeight;
} }
private void invalidateBounds() { private void invalidateBounds() {
width = -1.0; groupWidth = -1.0;
height = -1.0; groupHeight = -1.0;
} }
private void calculateBounds() { private void calculateBounds() {
@@ -148,8 +148,8 @@ public class ShapeGroup extends Shape {
maxy = Math.max(maxy, bounds.y + bounds.height); maxy = Math.max(maxy, bounds.y + bounds.height);
} }
width = maxx - minx; groupWidth = maxx - minx;
height = maxy - miny; groupHeight = maxy - miny;
} }
@Override @Override