From ff54d2db8e6d567c8d2ec6ce74b039151d075f4b Mon Sep 17 00:00:00 2001 From: OverloadedOrama Date: Sun, 16 Aug 2020 00:07:56 +0300 Subject: [PATCH] Add a transparent background for flip image dialog preview Seems to be working fine, will do the same for the remaining dialogs. --- .../Dialogs/ImageEffects/FlipImageDialog.gd | 16 ++++++++++++++- .../Dialogs/ImageEffects/FlipImageDialog.tscn | 20 ++++++++++++++----- src/UI/Dialogs/ImageEffects/ImageEffects.tscn | 2 -- src/UI/Dialogs/ImageEffects/ResizeCanvas.gd | 2 +- src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn | 1 + 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/UI/Dialogs/ImageEffects/FlipImageDialog.gd b/src/UI/Dialogs/ImageEffects/FlipImageDialog.gd index 63e7f41b3..0d3c249ef 100644 --- a/src/UI/Dialogs/ImageEffects/FlipImageDialog.gd +++ b/src/UI/Dialogs/ImageEffects/FlipImageDialog.gd @@ -24,6 +24,7 @@ func _ready() -> void: func _on_FlipImageDialog_about_to_show() -> void: current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image _on_SelectionCheckBox_toggled(selection_checkbox.pressed) + update_transparent_background_size() func _on_FlipImageDialog_confirmed() -> void: @@ -118,6 +119,19 @@ func flip_image(image : Image, _pixels : Array, project : Project = Global.curre image.blit_rect_mask(selected_image, selected_image, Rect2(Vector2.ZERO, selected_image.get_size()), Vector2.ZERO) +func update_transparent_background_size() -> 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.get_node("TransparentChecker").rect_size.x = image_size_x + preview.get_node("TransparentChecker").rect_size.y = image_size_y + + func _on_FlipImageDialog_popup_hide() -> void: Global.dialog_open(false) - diff --git a/src/UI/Dialogs/ImageEffects/FlipImageDialog.tscn b/src/UI/Dialogs/ImageEffects/FlipImageDialog.tscn index 7ce17e2e3..7c52126c3 100644 --- a/src/UI/Dialogs/ImageEffects/FlipImageDialog.tscn +++ b/src/UI/Dialogs/ImageEffects/FlipImageDialog.tscn @@ -1,11 +1,13 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://src/UI/Dialogs/ImageEffects/FlipImageDialog.gd" type="Script" id=1] +[ext_resource path="res://src/UI/TransparentChecker.tscn" type="PackedScene" id=2] [node name="FlipImageDialog" type="ConfirmationDialog"] -margin_right = 200.0 -margin_bottom = 70.0 +margin_right = 283.0 +margin_bottom = 300.0 window_title = "Flip" +resizable = true script = ExtResource( 1 ) [node name="VBoxContainer" type="VBoxContainer" parent="."] @@ -13,13 +15,21 @@ margin_left = 8.0 margin_top = 8.0 margin_right = 275.0 margin_bottom = 264.0 +__meta__ = { +"_edit_use_anchors_": false +} [node name="Preview" type="TextureRect" parent="VBoxContainer"] -margin_right = 267.0 +margin_left = 33.0 +margin_right = 233.0 margin_bottom = 200.0 rect_min_size = Vector2( 200, 200 ) +size_flags_horizontal = 4 expand = true -stretch_mode = 6 +stretch_mode = 5 + +[node name="TransparentChecker" parent="VBoxContainer/Preview" instance=ExtResource( 2 )] +show_behind_parent = true [node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"] margin_top = 204.0 diff --git a/src/UI/Dialogs/ImageEffects/ImageEffects.tscn b/src/UI/Dialogs/ImageEffects/ImageEffects.tscn index 1ee6d1651..fb3d68453 100644 --- a/src/UI/Dialogs/ImageEffects/ImageEffects.tscn +++ b/src/UI/Dialogs/ImageEffects/ImageEffects.tscn @@ -27,8 +27,6 @@ margin_bottom = 392.0 [node name="RotateImage" parent="." instance=ExtResource( 9 )] [node name="FlipImageDialog" parent="." instance=ExtResource( 1 )] -margin_right = 283.0 -margin_bottom = 300.0 [node name="InvertColorsDialog" parent="." instance=ExtResource( 2 )] diff --git a/src/UI/Dialogs/ImageEffects/ResizeCanvas.gd b/src/UI/Dialogs/ImageEffects/ResizeCanvas.gd index f6f474b96..b0496f652 100644 --- a/src/UI/Dialogs/ImageEffects/ResizeCanvas.gd +++ b/src/UI/Dialogs/ImageEffects/ResizeCanvas.gd @@ -39,7 +39,6 @@ func _on_ResizeCanvas_about_to_show() -> void: layer_i += 1 image.unlock() - preview_rect.get_node("TransparentChecker").rect_size = preview_rect.rect_size update_preview() @@ -80,6 +79,7 @@ func _on_CenterButton_pressed() -> void: func update_preview() -> void: + # preview_image is the same as image but offsetted var preview_image := Image.new() preview_image.create(width, height, false, Image.FORMAT_RGBA8) preview_image.blend_rect(image, Rect2(Vector2.ZERO, Global.current_project.size), Vector2(offset_x, offset_y)) diff --git a/src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn b/src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn index 6f60c717a..11bf81dca 100644 --- a/src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn +++ b/src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn @@ -111,6 +111,7 @@ suffix = "px" margin_top = 130.0 margin_right = 54.0 margin_bottom = 150.0 +mouse_default_cursor_shape = 2 text = "Center" [node name="Preview" type="TextureRect" parent="VBoxContainer"]