From 081ce90a083107bce36626727d710c15575d23da Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Sun, 29 May 2022 14:10:18 +0300 Subject: [PATCH] Internal changes in SelectionTool regarding snap to grid transformation These changes allow users to set the left (or right) mouse buttons as mapped shortcuts to the transform snap grid action, in order to automatically snap to grid while moving a selection. --- src/Tools/SelectionTools/EllipseSelect.gd | 1 - src/Tools/SelectionTools/PolygonSelect.gd | 1 - src/Tools/SelectionTools/RectSelect.gd | 1 - src/Tools/SelectionTools/SelectionTool.gd | 34 ++++++++--------------- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/Tools/SelectionTools/EllipseSelect.gd b/src/Tools/SelectionTools/EllipseSelect.gd index d4bab8da2..440e959ca 100644 --- a/src/Tools/SelectionTools/EllipseSelect.gd +++ b/src/Tools/SelectionTools/EllipseSelect.gd @@ -8,7 +8,6 @@ var _displace_origin = false # Mouse Click + Alt func _input(event: InputEvent) -> void: - ._input(event) if !_move and !_rect.has_no_area(): if event.is_action_pressed("shape_perfect"): _square = true diff --git a/src/Tools/SelectionTools/PolygonSelect.gd b/src/Tools/SelectionTools/PolygonSelect.gd index d5d722b58..961cf354f 100644 --- a/src/Tools/SelectionTools/PolygonSelect.gd +++ b/src/Tools/SelectionTools/PolygonSelect.gd @@ -6,7 +6,6 @@ var _ready_to_apply := false func _input(event: InputEvent) -> void: - ._input(event) if _move: return if event is InputEventMouseMotion: diff --git a/src/Tools/SelectionTools/RectSelect.gd b/src/Tools/SelectionTools/RectSelect.gd index a89f8cbc5..18097f75e 100644 --- a/src/Tools/SelectionTools/RectSelect.gd +++ b/src/Tools/SelectionTools/RectSelect.gd @@ -8,7 +8,6 @@ var _displace_origin = false # Mouse Click + Alt func _input(event: InputEvent) -> void: - ._input(event) if !_move and !_rect.has_no_area(): if event.is_action_pressed("shape_perfect"): _square = true diff --git a/src/Tools/SelectionTools/SelectionTool.gd b/src/Tools/SelectionTools/SelectionTool.gd index afda880d5..cae720ca7 100644 --- a/src/Tools/SelectionTools/SelectionTool.gd +++ b/src/Tools/SelectionTools/SelectionTool.gd @@ -13,7 +13,6 @@ var _ongoing_selection := false var _add := false # Shift + Mouse Click var _subtract := false # Ctrl + Mouse Click var _intersect := false # Shift + Ctrl + Mouse Click -var _snap_to_grid := false # Mouse Click + Ctrl # Used to check if the state of content transformation has been changed # while draw_move() is being called. For example, pressing Enter while still moving content @@ -31,28 +30,12 @@ func _ready() -> void: set_spinbox_values() -func _input(event: InputEvent) -> void: - if _move: - if event.is_action_pressed("transform_snap_grid"): - _snap_to_grid = true - var grid_size := Vector2(Global.grid_width, Global.grid_height) - _offset = _offset.snapped(grid_size) - var prev_pos = selection_node.big_bounding_rectangle.position - selection_node.big_bounding_rectangle.position = prev_pos.snapped(grid_size) - selection_node.marching_ants_outline.offset += ( - selection_node.big_bounding_rectangle.position - - prev_pos - ) - elif event.is_action_released("transform_snap_grid"): - _snap_to_grid = false - - func set_spinbox_values() -> void: var select_rect: Rect2 = selection_node.big_bounding_rectangle xspinbox.editable = !select_rect.has_no_area() - yspinbox.editable = !select_rect.has_no_area() - wspinbox.editable = !select_rect.has_no_area() - hspinbox.editable = !select_rect.has_no_area() + yspinbox.editable = xspinbox.editable + wspinbox.editable = xspinbox.editable + hspinbox.editable = xspinbox.editable xspinbox.value = select_rect.position.x yspinbox.value = select_rect.position.y @@ -149,7 +132,15 @@ func draw_move(position: Vector2) -> void: position.y = _start_pos.y else: position.x = _start_pos.x - if _snap_to_grid: + if Input.is_action_pressed("transform_snap_grid"): + var grid_size := Vector2(Global.grid_width, Global.grid_height) + _offset = _offset.snapped(grid_size) + var prev_pos = selection_node.big_bounding_rectangle.position + selection_node.big_bounding_rectangle.position = prev_pos.snapped(grid_size) + selection_node.marching_ants_outline.offset += ( + selection_node.big_bounding_rectangle.position + - prev_pos + ) position = position.snapped(Vector2(Global.grid_width, Global.grid_height)) position += Vector2(Global.grid_offset_x, Global.grid_offset_y) @@ -173,7 +164,6 @@ func draw_end(position: Vector2) -> void: apply_selection(position) _move = false - _snap_to_grid = false cursor_text = ""