diff --git a/src/Classes/SelectionMap.gd b/src/Classes/SelectionMap.gd index 49c504343..08059b92e 100644 --- a/src/Classes/SelectionMap.gd +++ b/src/Classes/SelectionMap.gd @@ -85,6 +85,15 @@ func invert() -> void: self.convert(Image.FORMAT_LA8) +## Returns a copy of itself that is cropped to [param size]. +## Used for when the selection map is bigger than the [Project] size. +func return_cropped_copy(size: Vector2i) -> SelectionMap: + var selection_map_copy := SelectionMap.new() + selection_map_copy.copy_from(self) + selection_map_copy.crop(size.x, size.y) + return selection_map_copy + + func move_bitmap_values(project: Project, move_offset := true) -> void: var size := project.size var selection_node = Global.canvas.selection diff --git a/src/Tools/Bucket.gd b/src/Tools/Bucket.gd index 4e1bc1f62..6547b0553 100644 --- a/src/Tools/Bucket.gd +++ b/src/Tools/Bucket.gd @@ -257,10 +257,7 @@ func fill_in_selection() -> void: var filler := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8) filler.fill(tool_slot.color) var rect: Rect2i = Global.canvas.selection.big_bounding_rectangle - var selection_map_copy := SelectionMap.new() - selection_map_copy.copy_from(project.selection_map) - # In case the selection map is bigger than the canvas - selection_map_copy.crop(project.size.x, project.size.y) + var selection_map_copy := project.selection_map.return_cropped_copy(project.size) for image in images: image.blit_rect_mask(filler, selection_map_copy, rect, rect.position) else: diff --git a/src/UI/Canvas/Selection.gd b/src/UI/Canvas/Selection.gd index 0b5683280..70c03af17 100644 --- a/src/UI/Canvas/Selection.gd +++ b/src/UI/Canvas/Selection.gd @@ -813,10 +813,7 @@ func delete(selected_cels := true) -> void: if project.has_selection: var blank := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8) - var selection_map_copy := SelectionMap.new() - selection_map_copy.copy_from(project.selection_map) - # In case the selection map is bigger than the canvas - selection_map_copy.crop(project.size.x, project.size.y) + var selection_map_copy := project.selection_map.return_cropped_copy(project.size) for image in images: image.blit_rect_mask( blank, selection_map_copy, big_bounding_rectangle, big_bounding_rectangle.position @@ -885,8 +882,9 @@ func _get_preview_image() -> void: original_preview_image = Image.create( big_bounding_rectangle.size.x, big_bounding_rectangle.size.y, false, Image.FORMAT_RGBA8 ) + var selection_map_copy := project.selection_map.return_cropped_copy(project.size) original_preview_image.blit_rect_mask( - blended_image, project.selection_map, big_bounding_rectangle, Vector2i.ZERO + blended_image, selection_map_copy, big_bounding_rectangle, Vector2i.ZERO ) if original_preview_image.is_invisible(): original_preview_image = Image.new() @@ -919,5 +917,6 @@ func _get_selected_image(cel_image: Image) -> Image: var image := Image.create( big_bounding_rectangle.size.x, big_bounding_rectangle.size.y, false, Image.FORMAT_RGBA8 ) - image.blit_rect_mask(cel_image, project.selection_map, big_bounding_rectangle, Vector2i.ZERO) + var selection_map_copy := project.selection_map.return_cropped_copy(project.size) + image.blit_rect_mask(cel_image, selection_map_copy, big_bounding_rectangle, Vector2i.ZERO) return image