mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Change "Crop Image" to "Trim Image" and add a new "Crop Image" that actually crops the image based on the active selection
This commit is contained in:
parent
866de8b6ae
commit
d36f89365c
|
@ -159,6 +159,9 @@ msgstr ""
|
|||
msgid "Crop Image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Trim Image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Resize Canvas"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -643,6 +643,10 @@ crop_image={
|
|||
"deadzone": 0.5,
|
||||
"events": []
|
||||
}
|
||||
trim_image={
|
||||
"deadzone": 0.5,
|
||||
"events": []
|
||||
}
|
||||
mirror_image={
|
||||
"deadzone": 0.5,
|
||||
"events": []
|
||||
|
|
|
@ -456,8 +456,6 @@ func color_distance(c1: Color, c2: Color) -> float:
|
|||
|
||||
|
||||
# Image effects
|
||||
|
||||
|
||||
func scale_image(width: int, height: int, interpolation: int) -> void:
|
||||
general_do_scale(width, height)
|
||||
|
||||
|
@ -519,7 +517,27 @@ func center(indices: Array) -> void:
|
|||
project.undo_redo.commit_action()
|
||||
|
||||
|
||||
## Sets the size of the project to be the same as the size of the active selection.
|
||||
func crop_image() -> void:
|
||||
if not Global.current_project.has_selection:
|
||||
return
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
var rect: Rect2i = Global.canvas.selection.big_bounding_rectangle
|
||||
general_do_scale(rect.size.x, rect.size.y)
|
||||
# Loop through all the cels to crop them
|
||||
for f in Global.current_project.frames:
|
||||
for cel in f.cels:
|
||||
if not cel is PixelCel:
|
||||
continue
|
||||
var sprite := cel.get_image().get_region(rect)
|
||||
Global.undo_redo_compress_images({cel.image: sprite.data}, {cel.image: cel.image.data})
|
||||
|
||||
general_undo_scale()
|
||||
|
||||
|
||||
## Automatically makes the project smaller by looping through all of the cels and
|
||||
## trimming out the pixels that are transparent in all cels.
|
||||
func trim_image() -> void:
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
var used_rect := Rect2i()
|
||||
for f in Global.current_project.frames:
|
||||
|
@ -542,7 +560,7 @@ func crop_image() -> void:
|
|||
var width := used_rect.size.x
|
||||
var height := used_rect.size.y
|
||||
general_do_scale(width, height)
|
||||
# Loop through all the cels to crop them
|
||||
# Loop through all the cels to trim them
|
||||
for f in Global.current_project.frames:
|
||||
for cel in f.cels:
|
||||
if not cel is PixelCel:
|
||||
|
|
|
@ -45,6 +45,7 @@ enum ImageMenu {
|
|||
OFFSET_IMAGE,
|
||||
SCALE_IMAGE,
|
||||
CROP_IMAGE,
|
||||
TRIM_IMAGE,
|
||||
FLIP,
|
||||
ROTATE,
|
||||
OUTLINE,
|
||||
|
@ -564,6 +565,7 @@ func _initialize_keychain() -> void:
|
|||
"preferences": Keychain.InputAction.new("", "Edit menu", true),
|
||||
"scale_image": Keychain.InputAction.new("", "Image menu", true),
|
||||
"crop_image": Keychain.InputAction.new("", "Image menu", true),
|
||||
"trim_image": Keychain.InputAction.new("", "Image menu", true),
|
||||
"resize_canvas": Keychain.InputAction.new("", "Image menu", true),
|
||||
"offset_image": Keychain.InputAction.new("", "Image menu", true),
|
||||
"mirror_image": Keychain.InputAction.new("", "Image menu", true),
|
||||
|
|
|
@ -175,8 +175,10 @@ func selection_map_changed() -> void:
|
|||
if has_selection:
|
||||
image_texture = ImageTexture.create_from_image(selection_map)
|
||||
Global.canvas.selection.marching_ants_outline.texture = image_texture
|
||||
var edit_menu_popup: PopupMenu = Global.top_menu_container.edit_menu
|
||||
edit_menu_popup.set_item_disabled(Global.EditMenu.NEW_BRUSH, !has_selection)
|
||||
Global.top_menu_container.edit_menu.set_item_disabled(Global.EditMenu.NEW_BRUSH, !has_selection)
|
||||
Global.top_menu_container.image_menu.set_item_disabled(
|
||||
Global.ImageMenu.CROP_IMAGE, !has_selection
|
||||
)
|
||||
|
||||
|
||||
func change_project() -> void:
|
||||
|
|
|
@ -279,6 +279,7 @@ func _setup_image_menu() -> void:
|
|||
"Offset Image": "offset_image",
|
||||
"Scale Image": "scale_image",
|
||||
"Crop Image": "crop_image",
|
||||
"Trim Image": "trim_image",
|
||||
"Mirror Image": "mirror_image",
|
||||
"Rotate Image": "rotate_image",
|
||||
"Outline": "outline",
|
||||
|
@ -295,7 +296,7 @@ func _setup_image_menu() -> void:
|
|||
for item in image_menu_items:
|
||||
_set_menu_shortcut(image_menu_items[item], image_menu, i, item)
|
||||
i += 1
|
||||
|
||||
image_menu.set_item_disabled(Global.ImageMenu.CROP_IMAGE, true)
|
||||
image_menu.id_pressed.connect(image_menu_id_pressed)
|
||||
|
||||
|
||||
|
@ -679,46 +680,34 @@ func image_menu_id_pressed(id: int) -> void:
|
|||
match id:
|
||||
Global.ImageMenu.SCALE_IMAGE:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/ScaleImage"))
|
||||
|
||||
Global.ImageMenu.OFFSET_IMAGE:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/OffsetImage"))
|
||||
|
||||
Global.ImageMenu.CROP_IMAGE:
|
||||
DrawingAlgos.crop_image()
|
||||
|
||||
Global.ImageMenu.TRIM_IMAGE:
|
||||
DrawingAlgos.trim_image()
|
||||
Global.ImageMenu.RESIZE_CANVAS:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/ResizeCanvas"))
|
||||
|
||||
Global.ImageMenu.FLIP:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/FlipImageDialog"))
|
||||
|
||||
Global.ImageMenu.ROTATE:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/RotateImage"))
|
||||
|
||||
Global.ImageMenu.INVERT_COLORS:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/InvertColorsDialog"))
|
||||
|
||||
Global.ImageMenu.DESATURATION:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/DesaturateDialog"))
|
||||
|
||||
Global.ImageMenu.OUTLINE:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/OutlineDialog"))
|
||||
|
||||
Global.ImageMenu.DROP_SHADOW:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/DropShadowDialog"))
|
||||
|
||||
Global.ImageMenu.HSV:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/HSVDialog"))
|
||||
|
||||
Global.ImageMenu.GRADIENT:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/GradientDialog"))
|
||||
|
||||
Global.ImageMenu.GRADIENT_MAP:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/GradientMapDialog"))
|
||||
|
||||
Global.ImageMenu.POSTERIZE:
|
||||
_popup_dialog(Global.control.get_node("Dialogs/ImageEffects/Posterize"))
|
||||
|
||||
# Global.ImageMenu.SHADER:
|
||||
# _popup_dialog(Global.control.get_node("Dialogs/ImageEffects/ShaderEffect"))
|
||||
|
||||
|
|
|
@ -310,11 +310,12 @@ camera_path = NodePath("SubViewport/Camera2D")
|
|||
[node name="SubViewport" type="SubViewport" parent="DockableContainer/Main Canvas/ViewportandVerticalRuler/SubViewportContainer"]
|
||||
handle_input_locally = false
|
||||
canvas_item_default_texture_filter = 0
|
||||
size = Vector2i(867, 513)
|
||||
size = Vector2i(2, 2)
|
||||
render_target_update_mode = 4
|
||||
|
||||
[node name="TransparentChecker" parent="DockableContainer/Main Canvas/ViewportandVerticalRuler/SubViewportContainer/SubViewport" instance=ExtResource("5")]
|
||||
material = SubResource("2")
|
||||
anchors_preset = 0
|
||||
|
||||
[node name="Canvas" parent="DockableContainer/Main Canvas/ViewportandVerticalRuler/SubViewportContainer/SubViewport" instance=ExtResource("19")]
|
||||
|
||||
|
@ -350,6 +351,7 @@ render_target_update_mode = 0
|
|||
|
||||
[node name="TransparentChecker" parent="DockableContainer/Second Canvas/SubViewport" instance=ExtResource("5")]
|
||||
material = SubResource("3")
|
||||
anchors_preset = 0
|
||||
|
||||
[node name="CanvasPreview" parent="DockableContainer/Second Canvas/SubViewport" instance=ExtResource("2")]
|
||||
|
||||
|
|
Loading…
Reference in a new issue