Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow clipping to selection during export #1113

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Autoload/Export.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/UI/Dialogs/ExportDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions src/UI/Dialogs/ExportDialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
Expand Down