mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Keep the aspect ratio correctly in the image effect dialog previews
This commit is contained in:
parent
2b4d85ac3e
commit
85b255032f
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue