Skip to content

Commit

Permalink
fix: correct aspect ratio calc for animated textures
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Jan 29, 2025
1 parent ea38fdb commit 5c3948f
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public final class ChapterImage implements Movable {
private double aspectRatio;
private boolean needAspectRecalc;
private int order;
private int animationFrames = 1;

public ChapterImage(Chapter c) {
chapter = c;
Expand All @@ -78,6 +79,7 @@ public Icon getImage() {
public ChapterImage setImage(Icon image) {
this.image = image;
needAspectRecalc = true;
animationFrames = image.getPixelBufferFrameCount();
return this;
}

Expand Down Expand Up @@ -308,7 +310,7 @@ public Component getTitle() {
}

public boolean isAspectRatioOff() {
return image.hasPixelBuffer() && !Mth.equal(getAspectRatio(), width / height);
return image.hasPixelBuffer() && !Mth.equal(getAspectRatio(), width / (height / animationFrames));
}

public void fixupAspectRatio(boolean adjustWidth) {
Expand All @@ -326,7 +328,7 @@ private double getAspectRatio() {
if (needAspectRecalc) {
PixelBuffer buffer = image.createPixelBuffer();
if (buffer != null) {
aspectRatio = (double) buffer.getWidth() / (double) buffer.getHeight();
aspectRatio = (double) buffer.getWidth() / ((double) buffer.getHeight() / animationFrames);
} else {
aspectRatio = 1d;
}
Expand Down

0 comments on commit 5c3948f

Please sign in to comment.