From b350f436c61bc381d0328f362d06567bc4e20632 Mon Sep 17 00:00:00 2001 From: Variable <77773850+Variable-ind@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:18:58 +0500 Subject: [PATCH] Allow clipping to selection during export (#1113) * Allow clipping to selection during export * linting * removed shader --- src/Autoload/Export.gd | 8 ++++++++ src/UI/Dialogs/ExportDialog.gd | 6 ++++++ src/UI/Dialogs/ExportDialog.tscn | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/src/Autoload/Export.gd b/src/Autoload/Export.gd index f20c95ab210..ecd1105af2b 100644 --- a/src/Autoload/Export.gd +++ b/src/Autoload/Export.gd @@ -52,6 +52,7 @@ var blended_frames := {} var export_json := false var split_layers := false var trim_images := false +var erase_unselected_area := false # Spritesheet options var orientation := Orientation.COLUMNS @@ -288,6 +289,13 @@ func process_animation(project := Global.current_project) -> void: else: var image := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8) image.copy_from(blended_frames[frame]) + if erase_unselected_area and project.has_selection: + var crop := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8) + var selection_image = project.selection_map.return_cropped_copy(project.size) + crop.blit_rect_mask( + image, selection_image, Rect2i(Vector2i.ZERO, image.get_size()), Vector2i.ZERO + ) + image.copy_from(crop) if trim_images: image = image.get_region(image.get_used_rect()) var duration := frame.duration * (1.0 / project.fps) diff --git a/src/UI/Dialogs/ExportDialog.gd b/src/UI/Dialogs/ExportDialog.gd index 9db80b27ddf..7f952fee745 100644 --- a/src/UI/Dialogs/ExportDialog.gd +++ b/src/UI/Dialogs/ExportDialog.gd @@ -464,6 +464,12 @@ func _on_trim_images_toggled(toggled_on: bool) -> void: set_preview() +func _on_clip_images_selection_toggled(toggled_on: bool) -> void: + Export.erase_unselected_area = toggled_on + Export.process_data() + set_preview() + + func _on_frames_item_selected(id: int) -> void: Export.frame_current_tag = id Export.process_data() diff --git a/src/UI/Dialogs/ExportDialog.tscn b/src/UI/Dialogs/ExportDialog.tscn index e98b6de2355..2e2457cf3e8 100644 --- a/src/UI/Dialogs/ExportDialog.tscn +++ b/src/UI/Dialogs/ExportDialog.tscn @@ -324,6 +324,12 @@ tooltip_text = "Trims the exported images to their visible portion, considering mouse_default_cursor_shape = 2 text = "Trim images" +[node name="ClipSelection" type="CheckBox" parent="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer" groups=["ExportImageOptions"]] +layout_mode = 2 +tooltip_text = "Only shows content that is within the bounds of a selected area." +mouse_default_cursor_shape = 2 +text = "Clip image content to selection" + [node name="PathDialog" type="FileDialog" parent="." groups=["FileDialogs"]] mode = 2 title = "Open a Directory" @@ -379,6 +385,7 @@ size_flags_horizontal = 3 [connection signal="toggled" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/IncludeTagsInFilename" to="." method="_on_include_tags_in_filename_toggled"] [connection signal="toggled" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/MultipleAnimationsDirectories" to="." method="_on_multiple_animations_directories_toggled"] [connection signal="toggled" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/TrimImages" to="." method="_on_trim_images_toggled"] +[connection signal="toggled" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/ClipSelection" to="." method="_on_clip_images_selection_toggled"] [connection signal="canceled" from="PathDialog" to="." method="_on_path_dialog_canceled"] [connection signal="dir_selected" from="PathDialog" to="." method="_on_path_dialog_dir_selected"] [connection signal="confirmed" from="FileExistsAlert" to="." method="_on_file_exists_alert_confirmed"]