1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 01:29:49 +00:00

[Undo/Redo] Compress SelectionMaps stored in memory, get rid of a lot of selection_map_copy instances

This commit is contained in:
Emmanouil Papadeas 2023-11-15 03:53:52 +02:00
parent 2c5ece53dd
commit e6d5329254
10 changed files with 67 additions and 119 deletions

View file

@ -590,10 +590,6 @@ func general_do_scale(width: int, height: int) -> void:
var x_ratio := float(project.size.x) / width var x_ratio := float(project.size.x) / width
var y_ratio := float(project.size.y) / height var y_ratio := float(project.size.y) / height
var selection_map_copy := SelectionMap.new()
selection_map_copy.copy_from(project.selection_map)
selection_map_copy.crop(size.x, size.y)
var new_x_symmetry_point := project.x_symmetry_point / x_ratio var new_x_symmetry_point := project.x_symmetry_point / x_ratio
var new_y_symmetry_point := project.y_symmetry_point / y_ratio var new_y_symmetry_point := project.y_symmetry_point / y_ratio
var new_x_symmetry_axis_points := project.x_symmetry_axis.points var new_x_symmetry_axis_points := project.x_symmetry_axis.points
@ -606,7 +602,7 @@ func general_do_scale(width: int, height: int) -> void:
project.undos += 1 project.undos += 1
project.undo_redo.create_action("Scale") project.undo_redo.create_action("Scale")
project.undo_redo.add_do_property(project, "size", size) project.undo_redo.add_do_property(project, "size", size)
project.undo_redo.add_do_property(project, "selection_map", selection_map_copy) project.undo_redo.add_do_method(project.selection_map.crop.bind(size.x, size.y))
project.undo_redo.add_do_property(project, "x_symmetry_point", new_x_symmetry_point) project.undo_redo.add_do_property(project, "x_symmetry_point", new_x_symmetry_point)
project.undo_redo.add_do_property(project, "y_symmetry_point", new_y_symmetry_point) project.undo_redo.add_do_property(project, "y_symmetry_point", new_y_symmetry_point)
project.undo_redo.add_do_property(project.x_symmetry_axis, "points", new_x_symmetry_axis_points) project.undo_redo.add_do_property(project.x_symmetry_axis, "points", new_x_symmetry_axis_points)
@ -616,7 +612,9 @@ func general_do_scale(width: int, height: int) -> void:
func general_undo_scale() -> void: func general_undo_scale() -> void:
var project := Global.current_project var project := Global.current_project
project.undo_redo.add_undo_property(project, "size", project.size) project.undo_redo.add_undo_property(project, "size", project.size)
project.undo_redo.add_undo_property(project, "selection_map", project.selection_map) project.undo_redo.add_undo_method(
project.selection_map.crop.bind(project.size.x, project.size.y)
)
project.undo_redo.add_undo_property(project, "x_symmetry_point", project.x_symmetry_point) project.undo_redo.add_undo_property(project, "x_symmetry_point", project.x_symmetry_point)
project.undo_redo.add_undo_property(project, "y_symmetry_point", project.y_symmetry_point) project.undo_redo.add_undo_property(project, "y_symmetry_point", project.y_symmetry_point)
project.undo_redo.add_undo_property( project.undo_redo.add_undo_property(

View file

@ -49,8 +49,6 @@ func apply_selection(pos: Vector2i) -> void:
gen.generate_image(cel_image, shader, params, project.size) gen.generate_image(cel_image, shader, params, project.size)
cel_image.convert(Image.FORMAT_LA8) cel_image.convert(Image.FORMAT_LA8)
var selection_map_copy := SelectionMap.new() project.selection_map.copy_from(cel_image)
selection_map_copy.copy_from(cel_image)
project.selection_map = selection_map_copy
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
Global.canvas.selection.commit_undo("Select", undo_data) Global.canvas.selection.commit_undo("Select", undo_data)

View file

@ -77,9 +77,7 @@ func apply_selection(_position: Vector2i) -> void:
Global.canvas.selection.commit_undo("Select", undo_data) Global.canvas.selection.commit_undo("Select", undo_data)
if _rect.size != Vector2i.ZERO: if _rect.size != Vector2i.ZERO:
var selection_map_copy := SelectionMap.new() set_ellipse(project.selection_map, _rect.position)
selection_map_copy.copy_from(project.selection_map)
set_ellipse(selection_map_copy, _rect.position)
# Handle mirroring # Handle mirroring
if Tools.horizontal_mirror: if Tools.horizontal_mirror:
@ -88,23 +86,22 @@ func apply_selection(_position: Vector2i) -> void:
Global.current_project.x_symmetry_point - _rect.position.x + 1 Global.current_project.x_symmetry_point - _rect.position.x + 1
) )
mirror_x_rect.end.x = Global.current_project.x_symmetry_point - _rect.end.x + 1 mirror_x_rect.end.x = Global.current_project.x_symmetry_point - _rect.end.x + 1
set_ellipse(selection_map_copy, mirror_x_rect.abs().position) set_ellipse(project.selection_map, mirror_x_rect.abs().position)
if Tools.vertical_mirror: if Tools.vertical_mirror:
var mirror_xy_rect := mirror_x_rect var mirror_xy_rect := mirror_x_rect
mirror_xy_rect.position.y = ( mirror_xy_rect.position.y = (
Global.current_project.y_symmetry_point - _rect.position.y + 1 Global.current_project.y_symmetry_point - _rect.position.y + 1
) )
mirror_xy_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1 mirror_xy_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1
set_ellipse(selection_map_copy, mirror_xy_rect.abs().position) set_ellipse(project.selection_map, mirror_xy_rect.abs().position)
if Tools.vertical_mirror: if Tools.vertical_mirror:
var mirror_y_rect := _rect var mirror_y_rect := _rect
mirror_y_rect.position.y = ( mirror_y_rect.position.y = (
Global.current_project.y_symmetry_point - _rect.position.y + 1 Global.current_project.y_symmetry_point - _rect.position.y + 1
) )
mirror_y_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1 mirror_y_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1
set_ellipse(selection_map_copy, mirror_y_rect.abs().position) set_ellipse(project.selection_map, mirror_y_rect.abs().position)
project.selection_map = selection_map_copy
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
Global.canvas.selection.commit_undo("Select", undo_data) Global.canvas.selection.commit_undo("Select", undo_data)

View file

@ -81,21 +81,18 @@ func apply_selection(_position) -> void:
cleared = true cleared = true
Global.canvas.selection.clear_selection() Global.canvas.selection.clear_selection()
if _draw_points.size() > 3: if _draw_points.size() > 3:
var selection_map_copy := SelectionMap.new()
selection_map_copy.copy_from(project.selection_map)
if _intersect: if _intersect:
selection_map_copy.clear() project.selection_map.clear()
lasso_selection(selection_map_copy, _draw_points) lasso_selection(project.selection_map, _draw_points)
# Handle mirroring # Handle mirroring
if Tools.horizontal_mirror: if Tools.horizontal_mirror:
lasso_selection(selection_map_copy, mirror_array(_draw_points, true, false)) lasso_selection(project.selection_map, mirror_array(_draw_points, true, false))
if Tools.vertical_mirror: if Tools.vertical_mirror:
lasso_selection(selection_map_copy, mirror_array(_draw_points, true, true)) lasso_selection(project.selection_map, mirror_array(_draw_points, true, true))
if Tools.vertical_mirror: if Tools.vertical_mirror:
lasso_selection(selection_map_copy, mirror_array(_draw_points, false, true)) lasso_selection(project.selection_map, mirror_array(_draw_points, false, true))
project.selection_map = selection_map_copy
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
else: else:
if !cleared: if !cleared:

View file

@ -27,29 +27,26 @@ func apply_selection(pos: Vector2i) -> void:
if !_add and !_subtract and !_intersect: if !_add and !_subtract and !_intersect:
Global.canvas.selection.clear_selection() Global.canvas.selection.clear_selection()
var selection_map_copy := SelectionMap.new()
selection_map_copy.copy_from(project.selection_map)
if _intersect: if _intersect:
selection_map_copy.clear() project.selection_map.clear()
var cel_image := Image.new() var cel_image := Image.new()
cel_image.copy_from(_get_draw_image()) cel_image.copy_from(_get_draw_image())
_flood_fill(pos, cel_image, selection_map_copy) _flood_fill(pos, cel_image, project.selection_map)
# Handle mirroring # Handle mirroring
if Tools.horizontal_mirror: if Tools.horizontal_mirror:
var mirror_x := pos var mirror_x := pos
mirror_x.x = Global.current_project.x_symmetry_point - pos.x mirror_x.x = Global.current_project.x_symmetry_point - pos.x
_flood_fill(mirror_x, cel_image, selection_map_copy) _flood_fill(mirror_x, cel_image, project.selection_map)
if Tools.vertical_mirror: if Tools.vertical_mirror:
var mirror_xy := mirror_x var mirror_xy := mirror_x
mirror_xy.y = Global.current_project.y_symmetry_point - pos.y mirror_xy.y = Global.current_project.y_symmetry_point - pos.y
_flood_fill(mirror_xy, cel_image, selection_map_copy) _flood_fill(mirror_xy, cel_image, project.selection_map)
if Tools.vertical_mirror: if Tools.vertical_mirror:
var mirror_y := pos var mirror_y := pos
mirror_y.y = Global.current_project.y_symmetry_point - pos.y mirror_y.y = Global.current_project.y_symmetry_point - pos.y
_flood_fill(mirror_y, cel_image, selection_map_copy) _flood_fill(mirror_y, cel_image, project.selection_map)
project.selection_map = selection_map_copy
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
Global.canvas.selection.commit_undo("Select", undo_data) Global.canvas.selection.commit_undo("Select", undo_data)

View file

@ -110,21 +110,18 @@ func apply_selection(pos: Vector2i) -> void:
Global.canvas.selection.clear_selection() Global.canvas.selection.clear_selection()
# This is paint selection so we've done >= 1 nstead of > 1 # This is paint selection so we've done >= 1 nstead of > 1
if _draw_points.size() >= 1: if _draw_points.size() >= 1:
var selection_map_copy := SelectionMap.new()
selection_map_copy.copy_from(project.selection_map)
if _intersect: if _intersect:
selection_map_copy.clear() project.selection_map.clear()
paint_selection(selection_map_copy, _draw_points) paint_selection(project.selection_map, _draw_points)
# Handle mirroring # Handle mirroring
if Tools.horizontal_mirror: if Tools.horizontal_mirror:
paint_selection(selection_map_copy, mirror_array(_draw_points, true, false)) paint_selection(project.selection_map, mirror_array(_draw_points, true, false))
if Tools.vertical_mirror: if Tools.vertical_mirror:
paint_selection(selection_map_copy, mirror_array(_draw_points, true, true)) paint_selection(project.selection_map, mirror_array(_draw_points, true, true))
if Tools.vertical_mirror: if Tools.vertical_mirror:
paint_selection(selection_map_copy, mirror_array(_draw_points, false, true)) paint_selection(project.selection_map, mirror_array(_draw_points, false, true))
project.selection_map = selection_map_copy
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
else: else:
if !cleared: if !cleared:

View file

@ -119,21 +119,18 @@ func apply_selection(pos: Vector2i) -> void:
cleared = true cleared = true
Global.canvas.selection.clear_selection() Global.canvas.selection.clear_selection()
if _draw_points.size() > 3: if _draw_points.size() > 3:
var selection_map_copy := SelectionMap.new()
selection_map_copy.copy_from(project.selection_map)
if _intersect: if _intersect:
selection_map_copy.clear() project.selection_map.clear()
lasso_selection(selection_map_copy, _draw_points) lasso_selection(project.selection_map, _draw_points)
# Handle mirroring # Handle mirroring
if Tools.horizontal_mirror: if Tools.horizontal_mirror:
lasso_selection(selection_map_copy, mirror_array(_draw_points, true, false)) lasso_selection(project.selection_map, mirror_array(_draw_points, true, false))
if Tools.vertical_mirror: if Tools.vertical_mirror:
lasso_selection(selection_map_copy, mirror_array(_draw_points, true, true)) lasso_selection(project.selection_map, mirror_array(_draw_points, true, true))
if Tools.vertical_mirror: if Tools.vertical_mirror:
lasso_selection(selection_map_copy, mirror_array(_draw_points, false, true)) lasso_selection(project.selection_map, mirror_array(_draw_points, false, true))
project.selection_map = selection_map_copy
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
else: else:
if !cleared: if !cleared:

View file

@ -119,11 +119,7 @@ func draw_start(pos: Vector2i) -> void:
selection_node.big_bounding_rectangle.position selection_node.big_bounding_rectangle.position
) )
var selection_map_copy := SelectionMap.new() project.selection_map.move_bitmap_values(project)
selection_map_copy.copy_from(project.selection_map)
selection_map_copy.move_bitmap_values(project)
project.selection_map = selection_map_copy
selection_node.commit_undo("Move Selection", selection_node.undo_data) selection_node.commit_undo("Move Selection", selection_node.undo_data)
selection_node.undo_data = selection_node.get_undo_data(true) selection_node.undo_data = selection_node.get_undo_data(true)
else: else:
@ -244,10 +240,7 @@ func _on_Position_value_changed(value: Vector2i) -> void:
timer.start() timer.start()
selection_node.big_bounding_rectangle.position = value selection_node.big_bounding_rectangle.position = value
var selection_map_copy := SelectionMap.new() project.selection_map.move_bitmap_values(project)
selection_map_copy.copy_from(project.selection_map)
selection_map_copy.move_bitmap_values(project)
project.selection_map = selection_map_copy
project.selection_map_changed() project.selection_map_changed()

View file

@ -381,12 +381,9 @@ func resize_selection() -> void:
preview_image.flip_y() preview_image.flip_y()
preview_image_texture = ImageTexture.create_from_image(preview_image) preview_image_texture = ImageTexture.create_from_image(preview_image)
var selection_map_copy := SelectionMap.new() Global.current_project.selection_map.resize_bitmap_values(
selection_map_copy.copy_from(selection_map)
selection_map_copy.resize_bitmap_values(
Global.current_project, size, temp_rect.size.x < 0, temp_rect.size.y < 0 Global.current_project, size, temp_rect.size.x < 0, temp_rect.size.y < 0
) )
Global.current_project.selection_map = selection_map_copy
Global.current_project.selection_map_changed() Global.current_project.selection_map_changed()
queue_redraw() queue_redraw()
Global.canvas.queue_redraw() Global.canvas.queue_redraw()
@ -429,8 +426,6 @@ func _gizmo_rotate() -> void: # Does not work properly yet
func select_rect(rect: Rect2i, operation: int = SelectionOperation.ADD) -> void: func select_rect(rect: Rect2i, operation: int = SelectionOperation.ADD) -> void:
var project := Global.current_project var project := Global.current_project
var selection_map_copy := SelectionMap.new()
selection_map_copy.copy_from(project.selection_map)
# Used only if the selection is outside of the canvas boundaries, # Used only if the selection is outside of the canvas boundaries,
# on the left and/or above (negative coords) # on the left and/or above (negative coords)
var offset_position := Vector2i.ZERO var offset_position := Vector2i.ZERO
@ -443,27 +438,28 @@ func select_rect(rect: Rect2i, operation: int = SelectionOperation.ADD) -> void:
if offset_position != Vector2i.ZERO: if offset_position != Vector2i.ZERO:
big_bounding_rectangle.position -= offset_position big_bounding_rectangle.position -= offset_position
selection_map_copy.move_bitmap_values(project) project.selection_map.move_bitmap_values(project)
if operation == SelectionOperation.ADD: if operation == SelectionOperation.ADD:
selection_map_copy.fill_rect(rect, Color(1, 1, 1, 1)) project.selection_map.fill_rect(rect, Color(1, 1, 1, 1))
elif operation == SelectionOperation.SUBTRACT: elif operation == SelectionOperation.SUBTRACT:
selection_map_copy.fill_rect(rect, Color(0)) project.selection_map.fill_rect(rect, Color(0))
elif operation == SelectionOperation.INTERSECT: elif operation == SelectionOperation.INTERSECT:
selection_map_copy.clear() project.selection_map.clear()
for x in range(rect.position.x, rect.end.x): for x in range(rect.position.x, rect.end.x):
for y in range(rect.position.y, rect.end.y): for y in range(rect.position.y, rect.end.y):
var pos := Vector2i(x, y) var pos := Vector2i(x, y)
if !Rect2i(Vector2i.ZERO, selection_map_copy.get_size()).has_point(pos): if !Rect2i(Vector2i.ZERO, project.selection_map.get_size()).has_point(pos):
continue continue
selection_map_copy.select_pixel(pos, project.selection_map.is_pixel_selected(pos)) project.selection_map.select_pixel(
big_bounding_rectangle = selection_map_copy.get_used_rect() pos, project.selection_map.is_pixel_selected(pos)
)
big_bounding_rectangle = project.selection_map.get_used_rect()
if offset_position != Vector2i.ZERO: if offset_position != Vector2i.ZERO:
big_bounding_rectangle.position += offset_position big_bounding_rectangle.position += offset_position
selection_map_copy.move_bitmap_values(project) project.selection_map.move_bitmap_values(project)
project.selection_map = selection_map_copy
big_bounding_rectangle = big_bounding_rectangle # call getter method big_bounding_rectangle = big_bounding_rectangle # call getter method
@ -481,10 +477,7 @@ func move_borders(move: Vector2i) -> void:
func move_borders_end() -> void: func move_borders_end() -> void:
var selection_map_copy := SelectionMap.new() Global.current_project.selection_map.move_bitmap_values(Global.current_project)
selection_map_copy.copy_from(Global.current_project.selection_map)
selection_map_copy.move_bitmap_values(Global.current_project)
Global.current_project.selection_map = selection_map_copy
if not is_moving_content: if not is_moving_content:
commit_undo("Select", undo_data) commit_undo("Select", undo_data)
else: else:
@ -540,10 +533,7 @@ func transform_content_confirm() -> void:
Rect2(Vector2.ZERO, project.selection_map.get_size()), Rect2(Vector2.ZERO, project.selection_map.get_size()),
big_bounding_rectangle.position big_bounding_rectangle.position
) )
var selection_map_copy := SelectionMap.new() project.selection_map.move_bitmap_values(project)
selection_map_copy.copy_from(project.selection_map)
selection_map_copy.move_bitmap_values(project)
project.selection_map = selection_map_copy
commit_undo("Move Selection", undo_data) commit_undo("Move Selection", undo_data)
original_preview_image = Image.new() original_preview_image = Image.new()
@ -563,16 +553,16 @@ func transform_content_cancel() -> void:
is_moving_content = false is_moving_content = false
big_bounding_rectangle = original_big_bounding_rectangle big_bounding_rectangle = original_big_bounding_rectangle
project.selection_map = original_bitmap project.selection_map.copy_from(original_bitmap)
project.selection_map_changed() project.selection_map_changed()
preview_image = original_preview_image preview_image = original_preview_image
for cel in _get_selected_draw_cels(): for cel in _get_selected_draw_cels():
var cel_image: Image = cel.get_image() var cel_image := cel.get_image()
if !is_pasting: if !is_pasting:
cel_image.blit_rect_mask( cel_image.blit_rect_mask(
cel.transformed_content, cel.transformed_content,
cel.transformed_content, cel.transformed_content,
Rect2(Vector2.ZERO, Global.current_project.selection_map.get_size()), Rect2i(Vector2i.ZERO, Global.current_project.selection_map.get_size()),
big_bounding_rectangle.position big_bounding_rectangle.position
) )
cel.transformed_content = null cel.transformed_content = null
@ -595,13 +585,14 @@ func commit_undo(action: String, undo_data_tmp: Dictionary) -> void:
project.undos += 1 project.undos += 1
project.undo_redo.create_action(action) project.undo_redo.create_action(action)
project.undo_redo.add_do_property(project, "selection_map", redo_data["selection_map"]) Global.undo_redo_compress_images(redo_data, undo_data_tmp, project)
# project.undo_redo.add_do_property(project, "selection_map", redo_data["selection_map"])
project.undo_redo.add_do_property( project.undo_redo.add_do_property(
self, "big_bounding_rectangle", redo_data["big_bounding_rectangle"] self, "big_bounding_rectangle", redo_data["big_bounding_rectangle"]
) )
project.undo_redo.add_do_property(project, "selection_offset", redo_data["outline_offset"]) project.undo_redo.add_do_property(project, "selection_offset", redo_data["outline_offset"])
project.undo_redo.add_undo_property(project, "selection_map", undo_data_tmp["selection_map"]) # project.undo_redo.add_undo_property(project, "selection_map", undo_data_tmp["selection_map"])
project.undo_redo.add_undo_property( project.undo_redo.add_undo_property(
self, "big_bounding_rectangle", undo_data_tmp["big_bounding_rectangle"] self, "big_bounding_rectangle", undo_data_tmp["big_bounding_rectangle"]
) )
@ -609,8 +600,7 @@ func commit_undo(action: String, undo_data_tmp: Dictionary) -> void:
project, "selection_offset", undo_data_tmp["outline_offset"] project, "selection_offset", undo_data_tmp["outline_offset"]
) )
if undo_data_tmp["undo_image"]: # if undo_data_tmp["undo_image"]:
Global.undo_redo_compress_images(redo_data, undo_data_tmp, project)
project.undo_redo.add_do_method(Global.undo_or_redo.bind(false)) project.undo_redo.add_do_method(Global.undo_or_redo.bind(false))
project.undo_redo.add_do_method(project.selection_map_changed) project.undo_redo.add_do_method(project.selection_map_changed)
project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true)) project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true))
@ -623,7 +613,7 @@ func commit_undo(action: String, undo_data_tmp: Dictionary) -> void:
func get_undo_data(undo_image: bool) -> Dictionary: func get_undo_data(undo_image: bool) -> Dictionary:
var data := {} var data := {}
var project := Global.current_project var project := Global.current_project
data["selection_map"] = project.selection_map data[project.selection_map] = project.selection_map.data
data["big_bounding_rectangle"] = big_bounding_rectangle data["big_bounding_rectangle"] = big_bounding_rectangle
data["outline_offset"] = Global.current_project.selection_offset data["outline_offset"] = Global.current_project.selection_offset
data["undo_image"] = undo_image data["undo_image"] = undo_image
@ -685,10 +675,8 @@ func copy() -> void:
else: else:
if is_moving_content: if is_moving_content:
to_copy.copy_from(preview_image) to_copy.copy_from(preview_image)
var selection_map_copy := SelectionMap.new() project.selection_map.move_bitmap_values(project, false)
selection_map_copy.copy_from(project.selection_map) cl_selection_map = project.selection_map
selection_map_copy.move_bitmap_values(project, false)
cl_selection_map = selection_map_copy
else: else:
to_copy = image.get_region(big_bounding_rectangle) to_copy = image.get_region(big_bounding_rectangle)
# Remove unincluded pixels if the selection is not a single rectangle # Remove unincluded pixels if the selection is not a single rectangle
@ -754,7 +742,7 @@ func paste(in_place := false) -> void:
max(clip_map.get_size().y, project.selection_map.get_size().y) max(clip_map.get_size().y, project.selection_map.get_size().y)
) )
project.selection_map = clip_map project.selection_map.copy_from(clip_map)
project.selection_map.crop(max_size.x, max_size.y) project.selection_map.crop(max_size.x, max_size.y)
project.selection_offset = clipboard.selection_offset project.selection_offset = clipboard.selection_offset
big_bounding_rectangle = clipboard.big_bounding_rectangle big_bounding_rectangle = clipboard.big_bounding_rectangle
@ -874,13 +862,10 @@ func invert() -> void:
transform_content_confirm() transform_content_confirm()
var project := Global.current_project var project := Global.current_project
var undo_data_tmp := get_undo_data(false) var undo_data_tmp := get_undo_data(false)
var selection_map_copy := SelectionMap.new() project.selection_map.crop(project.size.x, project.size.y)
selection_map_copy.copy_from(project.selection_map) project.selection_map.invert()
selection_map_copy.crop(project.size.x, project.size.y)
selection_map_copy.invert()
project.selection_map = selection_map_copy
project.selection_map_changed() project.selection_map_changed()
big_bounding_rectangle = selection_map_copy.get_used_rect() big_bounding_rectangle = project.selection_map.get_used_rect()
project.selection_offset = Vector2.ZERO project.selection_offset = Vector2.ZERO
commit_undo("Select", undo_data_tmp) commit_undo("Select", undo_data_tmp)
@ -891,11 +876,8 @@ func clear_selection(use_undo := false) -> void:
return return
transform_content_confirm() transform_content_confirm()
var undo_data_tmp := get_undo_data(false) var undo_data_tmp := get_undo_data(false)
var selection_map_copy := SelectionMap.new() project.selection_map.crop(project.size.x, project.size.y)
selection_map_copy.copy_from(project.selection_map) project.selection_map.clear()
selection_map_copy.crop(project.size.x, project.size.y)
selection_map_copy.clear()
project.selection_map = selection_map_copy
big_bounding_rectangle = Rect2() big_bounding_rectangle = Rect2()
project.selection_offset = Vector2.ZERO project.selection_offset = Vector2.ZERO

View file

@ -51,17 +51,14 @@ func _commit_undo(action: String, undo_data: Dictionary, project: Project) -> vo
var redo_data := _get_undo_data(project) var redo_data := _get_undo_data(project)
project.undos += 1 project.undos += 1
project.undo_redo.create_action(action) project.undo_redo.create_action(action)
if redo_data.has("selection_map"): Global.undo_redo_compress_images(redo_data, undo_data, project)
project.undo_redo.add_do_property(project, "selection_map", redo_data["selection_map"]) if redo_data.has("outline_offset"):
project.undo_redo.add_do_property(project, "selection_offset", redo_data["outline_offset"]) project.undo_redo.add_do_property(project, "selection_offset", redo_data["outline_offset"])
project.undo_redo.add_undo_property(project, "selection_map", undo_data["selection_map"])
project.undo_redo.add_undo_property( project.undo_redo.add_undo_property(
project, "selection_offset", undo_data["outline_offset"] project, "selection_offset", undo_data["outline_offset"]
) )
project.undo_redo.add_do_method(project.selection_map_changed) project.undo_redo.add_do_method(project.selection_map_changed)
project.undo_redo.add_undo_method(project.selection_map_changed) project.undo_redo.add_undo_method(project.selection_map_changed)
Global.undo_redo_compress_images(redo_data, undo_data, project)
project.undo_redo.add_do_method(Global.undo_or_redo.bind(false, -1, -1, project)) project.undo_redo.add_do_method(Global.undo_or_redo.bind(false, -1, -1, project))
project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true, -1, -1, project)) project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true, -1, -1, project))
project.undo_redo.commit_action() project.undo_redo.commit_action()
@ -71,9 +68,7 @@ func _get_undo_data(project: Project) -> Dictionary:
var affect_selection := selection_checkbox.button_pressed and project.has_selection var affect_selection := selection_checkbox.button_pressed and project.has_selection
var data := {} var data := {}
if affect_selection: if affect_selection:
var bitmap_image := SelectionMap.new() data[project.selection_map] = project.selection_map.data
bitmap_image.copy_from(project.selection_map)
data["selection_map"] = bitmap_image
data["outline_offset"] = project.selection_offset data["outline_offset"] = project.selection_offset
var images := _get_selected_draw_images(project) var images := _get_selected_draw_images(project)
@ -86,20 +81,17 @@ func _flip_selection(project := Global.current_project) -> void:
if !(selection_checkbox.button_pressed and project.has_selection): if !(selection_checkbox.button_pressed and project.has_selection):
return return
var bitmap_image := SelectionMap.new() var selection_rect := project.selection_map.get_used_rect()
bitmap_image.copy_from(project.selection_map) var smaller_bitmap_image := project.selection_map.get_region(selection_rect)
var selection_rect := bitmap_image.get_used_rect()
var smaller_bitmap_image := bitmap_image.get_region(selection_rect)
if flip_h.button_pressed: if flip_h.button_pressed:
smaller_bitmap_image.flip_x() smaller_bitmap_image.flip_x()
if flip_v.button_pressed: if flip_v.button_pressed:
smaller_bitmap_image.flip_y() smaller_bitmap_image.flip_y()
bitmap_image.fill(Color(0, 0, 0, 0)) project.selection_map.fill(Color(0, 0, 0, 0))
bitmap_image.blend_rect( project.selection_map.blend_rect(
smaller_bitmap_image, smaller_bitmap_image,
Rect2i(Vector2.ZERO, smaller_bitmap_image.get_size()), Rect2i(Vector2.ZERO, smaller_bitmap_image.get_size()),
selection_rect.position selection_rect.position
) )
project.selection_map = bitmap_image