Skip to content

Commit

Permalink
Allow clipping to selection during export (#1113)
Browse files Browse the repository at this point in the history
* Allow clipping to selection during export

* linting

* removed shader
  • Loading branch information
Variable-ind authored Oct 1, 2024
1 parent 564b199 commit b350f43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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

0 comments on commit b350f43

Please sign in to comment.