Change default rectangle select behavior and ability to clip polygons using Control

This commit is contained in:
Manolis Papadeas 2021-02-16 01:07:39 +02:00
parent d8c78331f0
commit cc69730eff
2 changed files with 30 additions and 17 deletions

View file

@ -17,6 +17,11 @@ func draw_start(position : Vector2) -> void:
i += 1 i += 1
if current_selection_id == -1: if current_selection_id == -1:
if !Tools.shift and !Tools.control:
for selection in Global.current_project.selections:
selection.queue_free()
current_selection_id = 0
else:
current_selection_id = Global.current_project.selections.size() current_selection_id = Global.current_project.selections.size()
var selection_shape := preload("res://src/Tools/SelectionShape.tscn").instance() var selection_shape := preload("res://src/Tools/SelectionShape.tscn").instance()
Global.current_project.selections.append(selection_shape) Global.current_project.selections.append(selection_shape)
@ -70,7 +75,7 @@ func draw_end(position : Vector2) -> void:
_selection.move_polygon_end(position, start_position) _selection.move_polygon_end(position, start_position)
else: else:
var selection : SelectionShape = Global.current_project.selections[current_selection_id] var selection : SelectionShape = Global.current_project.selections[current_selection_id]
selection.select_rect() selection.select_rect(!Tools.control)
# _drag = false # _drag = false
_move = false _move = false
cursor_text = "" cursor_text = ""

View file

@ -181,7 +181,7 @@ func move_polygon_end(new_pos : Vector2, old_pos : Vector2) -> void:
self.local_selected_pixels = selected_pixels_copy self.local_selected_pixels = selected_pixels_copy
func select_rect() -> void: func select_rect(merge := true) -> void:
var project : Project = Global.current_project var project : Project = Global.current_project
self.local_selected_pixels = [] self.local_selected_pixels = []
var selected_pixels_copy = local_selected_pixels.duplicate() var selected_pixels_copy = local_selected_pixels.duplicate()
@ -201,20 +201,20 @@ func select_rect() -> void:
if local_selected_pixels.size() == 0: if local_selected_pixels.size() == 0:
queue_free() queue_free()
return return
merge_multiple_selections() merge_multiple_selections(merge)
# var undo_data = _get_undo_data(false) # var undo_data = _get_undo_data(false)
# Global.current_project.selected_rect = _selected_rect # Global.current_project.selected_rect = _selected_rect
# commit_undo("Rectangle Select", undo_data) # commit_undo("Rectangle Select", undo_data)
func merge_multiple_selections() -> void: func merge_multiple_selections(merge := true) -> void:
if Global.current_project.selections.size() < 2: if Global.current_project.selections.size() < 2:
return return
for selection in Global.current_project.selections: for selection in Global.current_project.selections:
if selection == self: if selection == self:
continue continue
if merge:
var arr = Geometry.merge_polygons_2d(polygon, selection.polygon) var arr = Geometry.merge_polygons_2d(polygon, selection.polygon)
# print(arr)
if arr.size() == 1: # if the selections intersect if arr.size() == 1: # if the selections intersect
set_polygon(arr[0]) set_polygon(arr[0])
_selected_rect = _selected_rect.merge(selection._selected_rect) _selected_rect = _selected_rect.merge(selection._selected_rect)
@ -224,7 +224,15 @@ func merge_multiple_selections() -> void:
selection.clear_selection_on_tree_exit = false selection.clear_selection_on_tree_exit = false
selection.queue_free() selection.queue_free()
self.local_selected_pixels = selected_pixels_copy self.local_selected_pixels = selected_pixels_copy
else:
var arr = Geometry.clip_polygons_2d(selection.polygon, polygon)
if arr.size() == 1: # if the selections intersect
selection.set_polygon(arr[0])
var selected_pixels_copy = selection.local_selected_pixels.duplicate()
for pixel in local_selected_pixels:
selected_pixels_copy.erase(pixel)
selection.local_selected_pixels = selected_pixels_copy
queue_free()
func move_start(move_pixel : bool) -> void: func move_start(move_pixel : bool) -> void:
if not move_pixel: if not move_pixel: