From 85b255032fde1ac1fba301c20a9ab365a26a2716 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Sun, 11 Feb 2024 18:44:22 +0200 Subject: [PATCH] Keep the aspect ratio correctly in the image effect dialog previews --- src/Classes/ImageEffect.gd | 20 +++----------------- src/UI/Dialogs/ImageEffects/ResizeCanvas.gd | 17 ++--------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/Classes/ImageEffect.gd b/src/Classes/ImageEffect.gd index 0cb8c6c5d..e6e58de16 100644 --- a/src/Classes/ImageEffect.gd +++ b/src/Classes/ImageEffect.gd @@ -9,6 +9,7 @@ var affect: int = SELECTED_CELS var selected_cels := Image.create(1, 1, false, Image.FORMAT_RGBA8) var current_frame := Image.create(1, 1, false, Image.FORMAT_RGBA8) var preview_image := Image.new() +var aspect_ratio_container: AspectRatioContainer var preview: TextureRect var selection_checkbox: CheckBox var affect_option_button: OptionButton @@ -38,7 +39,7 @@ func _about_to_popup() -> void: Global.canvas.selection.transform_content_confirm() prepare_animator(Global.current_project) set_and_update_preview_image(Global.current_project.current_frame) - update_transparent_background_size() + aspect_ratio_container.ratio = float(preview_image.get_width()) / preview_image.get_height() # prepares "animate_panel.frames" according to affect @@ -131,6 +132,7 @@ func commit_action(_cel: Image, _project := Global.current_project) -> void: func set_nodes() -> void: + aspect_ratio_container = $VBoxContainer/AspectRatioContainer preview = $VBoxContainer/AspectRatioContainer/Preview selection_checkbox = $VBoxContainer/OptionsContainer/SelectionCheckBox affect_option_button = $VBoxContainer/OptionsContainer/AffectOptionButton @@ -214,22 +216,6 @@ func update_preview() -> void: preview.texture = ImageTexture.create_from_image(preview_image) -func update_transparent_background_size() -> void: - if !preview: - return - var image_size_y := preview.size.y - var image_size_x := preview.size.x - if preview_image.get_size().x > preview_image.get_size().y: - var scale_ratio := preview_image.get_size().x / image_size_x - image_size_y = preview_image.get_size().y / scale_ratio - else: - var scale_ratio := preview_image.get_size().y / image_size_y - image_size_x = preview_image.get_size().x / scale_ratio - - preview.get_node("TransparentChecker").size.x = image_size_x - preview.get_node("TransparentChecker").size.y = image_size_y - - func _visibility_changed() -> void: if visible: return diff --git a/src/UI/Dialogs/ImageEffects/ResizeCanvas.gd b/src/UI/Dialogs/ImageEffects/ResizeCanvas.gd index 2993fa014..6b56dbd0c 100644 --- a/src/UI/Dialogs/ImageEffects/ResizeCanvas.gd +++ b/src/UI/Dialogs/ImageEffects/ResizeCanvas.gd @@ -10,6 +10,7 @@ var image := Image.create(1, 1, false, Image.FORMAT_RGBA8) @onready var height_spinbox: SpinBox = $VBoxContainer/OptionsContainer/HeightValue @onready var x_spinbox: SpinBox = $VBoxContainer/OptionsContainer/XSpinBox @onready var y_spinbox: SpinBox = $VBoxContainer/OptionsContainer/YSpinBox +@onready var aspect_ratio_container: AspectRatioContainer = $VBoxContainer/AspectRatioContainer @onready var preview_rect: TextureRect = $VBoxContainer/AspectRatioContainer/Preview @@ -82,21 +83,7 @@ func update_preview() -> void: image, Rect2i(Vector2i.ZERO, Global.current_project.size), Vector2i(offset_x, offset_y) ) preview_rect.texture = ImageTexture.create_from_image(preview_image) - update_transparent_background_size(preview_image) - - -func update_transparent_background_size(preview_image: Image) -> void: - var image_size_y := preview_rect.size.y - var image_size_x := preview_rect.size.x - if preview_image.get_size().x > preview_image.get_size().y: - var scale_ratio := preview_image.get_size().x / image_size_x - image_size_y = preview_image.get_size().y / scale_ratio - else: - var scale_ratio := preview_image.get_size().y / image_size_y - image_size_x = preview_image.get_size().x / scale_ratio - - preview_rect.get_node("TransparentChecker").size.x = image_size_x - preview_rect.get_node("TransparentChecker").size.y = image_size_y + aspect_ratio_container.ratio = float(preview_image.get_width()) / preview_image.get_height() func _on_visibility_changed() -> void: