Skip to content

Commit

Permalink
Merge pull request #45 from Starmapo/image-clipping-fix
Browse files Browse the repository at this point in the history
Fix resized images not being clipped correctly
  • Loading branch information
ianharrigan authored May 7, 2024
2 parents 0f218a5 + b9c6619 commit b17c771
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions haxe/ui/backend/ImageDisplayImpl.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package haxe.ui.backend;

import flixel.graphics.frames.FlxImageFrame;
import flixel.math.FlxRect;
import haxe.ui.Toolkit;

class ImageDisplayImpl extends ImageBase {
Expand All @@ -15,16 +16,25 @@ class ImageDisplayImpl extends ImageBase {
frames = FlxImageFrame.fromFrame(_imageInfo.data);

aspectRatio = _imageInfo.width / _imageInfo.height;

width = frameWidth = Std.int(_imageInfo.width * Toolkit.scaleX);
height = frameHeight = Std.int(_imageInfo.height * Toolkit.scaleY);

origin.set(0, 0);
}
}

private override function validateDisplay() {
var scaleX:Float = _imageWidth / (_imageInfo.width / Toolkit.scaleX);
var scaleY:Float = _imageHeight / (_imageInfo.height / Toolkit.scaleY);
origin.set(0, 0);
scale.set(scaleX, scaleY);

width = Math.abs(scaleX) * frameWidth;
height = Math.abs(scaleY) * frameHeight;
}

override function set_clipRect(rect:FlxRect):FlxRect {
if (rect != null) {
return super.set_clipRect(FlxRect.get(rect.x / scale.x, rect.y / scale.y, rect.width / scale.x, rect.height / scale.y));
} else {
return super.set_clipRect(null);
}
}
}

0 comments on commit b17c771

Please sign in to comment.