From b9c66194665eeb7e98267479da35411b5d7e29e4 Mon Sep 17 00:00:00 2001 From: Starmapo Date: Mon, 6 May 2024 17:12:10 -0400 Subject: [PATCH] Fix resized images not being clipped correctly - `width` and `height` are now set properly for resized image displays - Prevent unnecessary `origin` resets (only needed when the frames change) --- haxe/ui/backend/ImageDisplayImpl.hx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/haxe/ui/backend/ImageDisplayImpl.hx b/haxe/ui/backend/ImageDisplayImpl.hx index 5092a3e..c31ecec 100644 --- a/haxe/ui/backend/ImageDisplayImpl.hx +++ b/haxe/ui/backend/ImageDisplayImpl.hx @@ -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 { @@ -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); + } } }