mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Rewrite the crop image method
Should be a bit faster, but I still get weird bugs at random
This commit is contained in:
parent
d0433bed6f
commit
28b8e000f9
|
@ -256,24 +256,21 @@ func centralize() -> void:
|
|||
general_undo_centralize()
|
||||
|
||||
|
||||
func crop_image(image : Image) -> void:
|
||||
func crop_image() -> void:
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
# Use first cel as a starting rectangle
|
||||
var used_rect : Rect2 = image.get_used_rect()
|
||||
var used_rect : Rect2 = Global.current_project.frames[0].cels[0].image.get_used_rect()
|
||||
|
||||
for f in Global.current_project.frames:
|
||||
# However, if first cel is empty, loop through all cels until we find one that isn't
|
||||
for cel in f.cels:
|
||||
if used_rect != Rect2(0, 0, 0, 0):
|
||||
break
|
||||
else:
|
||||
if cel.image.get_used_rect() != Rect2(0, 0, 0, 0):
|
||||
used_rect = cel.image.get_used_rect()
|
||||
var cel_used_rect : Rect2 = cel.image.get_used_rect()
|
||||
if cel_used_rect == Rect2(0, 0, 0, 0): # If the cel has no content
|
||||
continue
|
||||
|
||||
# Merge all layers with content
|
||||
for cel in f.cels:
|
||||
if cel.image.get_used_rect() != Rect2(0, 0, 0, 0):
|
||||
used_rect = used_rect.merge(cel.image.get_used_rect())
|
||||
if used_rect == Rect2(0, 0, 0, 0): # If we still haven't found the first cel with content
|
||||
used_rect = cel_used_rect
|
||||
else:
|
||||
used_rect = used_rect.merge(cel_used_rect)
|
||||
|
||||
# If no layer has any content, just return
|
||||
if used_rect == Rect2(0, 0, 0, 0):
|
||||
|
@ -282,12 +279,12 @@ func crop_image(image : 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
|
||||
for f in Global.current_project.frames:
|
||||
# Loop through all the layers to crop them
|
||||
for j in range(Global.current_project.layers.size() - 1, -1, -1):
|
||||
var sprite : Image = f.cels[j].image.get_rect(used_rect)
|
||||
Global.current_project.undo_redo.add_do_property(f.cels[j].image, "data", sprite.data)
|
||||
Global.current_project.undo_redo.add_undo_property(f.cels[j].image, "data", f.cels[j].image.data)
|
||||
for cel in f.cels:
|
||||
var sprite : Image = cel.image.get_rect(used_rect)
|
||||
Global.current_project.undo_redo.add_do_property(cel.image, "data", sprite.data)
|
||||
Global.current_project.undo_redo.add_undo_property(cel.image, "data", cel.image.data)
|
||||
|
||||
general_undo_scale()
|
||||
|
||||
|
|
|
@ -445,7 +445,6 @@ func toggle_fullscreen() -> void:
|
|||
|
||||
|
||||
func image_menu_id_pressed(id : int) -> void:
|
||||
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
|
||||
match id:
|
||||
ImageMenuId.SCALE_IMAGE:
|
||||
show_scale_image_popup()
|
||||
|
@ -454,7 +453,7 @@ func image_menu_id_pressed(id : int) -> void:
|
|||
DrawingAlgos.centralize()
|
||||
|
||||
ImageMenuId.CROP_IMAGE:
|
||||
DrawingAlgos.crop_image(image)
|
||||
DrawingAlgos.crop_image()
|
||||
|
||||
ImageMenuId.RESIZE_CANVAS:
|
||||
show_resize_canvas_popup()
|
||||
|
|
Loading…
Reference in a new issue