Skip to content

Commit ad2393f

Browse files
Fix bug where the selection would be in a wrong position while moving or holding a handle, and confirming or canceling a transformation before letting go of the mouse
1 parent 90a7355 commit ad2393f

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/Tools/BaseSelectionTool.gd

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ var _add := false ## Shift + Mouse Click
1616
var _subtract := false ## Ctrl + Mouse Click
1717
var _intersect := false ## Shift + Ctrl + Mouse Click
1818

19+
## Used to check if the state of content transformation has been changed
20+
## while draw_move() is being called. For example, pressing Enter while still moving content
21+
var _transformation_status_changed := false
1922
var _skip_slider_logic := false
2023

2124
@onready var selection_node := Global.canvas.selection
@@ -28,14 +31,16 @@ var _skip_slider_logic := false
2831

2932

3033
func _ready() -> void:
31-
super._ready()
32-
algorithm_option_button.add_item("Nearest Neighbor")
34+
super()
35+
algorithm_option_button.add_item("Nearest neighbor")
3336
algorithm_option_button.add_item("cleanEdge", DrawingAlgos.RotationAlgorithm.CLEANEDGE)
3437
algorithm_option_button.add_item("OmniScale", DrawingAlgos.RotationAlgorithm.OMNISCALE)
3538
algorithm_option_button.select(0)
3639
set_confirm_buttons_visibility()
3740
set_spinbox_values()
3841
refresh_options()
42+
selection_node.transformation_confirmed.connect(func(): _transformation_status_changed = true)
43+
selection_node.transformation_canceled.connect(func(): _transformation_status_changed = true)
3944
transformation_handles.preview_transform_changed.connect(set_confirm_buttons_visibility)
4045

4146

@@ -91,7 +96,8 @@ func set_spinbox_values() -> void:
9196

9297
func draw_start(pos: Vector2i) -> void:
9398
pos = snap_position(pos)
94-
super.draw_start(pos)
99+
super(pos)
100+
_transformation_status_changed = false
95101
if transformation_handles.arrow_key_move:
96102
return
97103
var project := Global.current_project
@@ -136,9 +142,11 @@ func draw_start(pos: Vector2i) -> void:
136142

137143
func draw_move(pos: Vector2i) -> void:
138144
pos = snap_position(pos)
139-
super.draw_move(pos)
145+
super(pos)
140146
if transformation_handles.arrow_key_move:
141147
return
148+
if _transformation_status_changed:
149+
return
142150
if not _move:
143151
return
144152
var project := Global.current_project
@@ -173,7 +181,7 @@ func draw_move(pos: Vector2i) -> void:
173181

174182
func draw_end(pos: Vector2i) -> void:
175183
pos = snap_position(pos)
176-
super.draw_end(pos)
184+
super(pos)
177185
if transformation_handles.arrow_key_move:
178186
return
179187
if not _move:

src/UI/Canvas/Selection.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
class_name SelectionNode
22
extends Node2D
33

4+
signal transformation_confirmed
5+
signal transformation_canceled
6+
47
enum SelectionOperation { ADD, SUBTRACT, INTERSECT }
58
const CLIPBOARD_FILE_PATH := "user://clipboard.txt"
69

@@ -129,6 +132,7 @@ func transform_content_confirm() -> void:
129132
is_pasting = false
130133
queue_redraw()
131134
canvas.queue_redraw()
135+
transformation_confirmed.emit()
132136

133137

134138
func transform_content_cancel() -> void:
@@ -152,6 +156,7 @@ func transform_content_cancel() -> void:
152156
is_pasting = false
153157
queue_redraw()
154158
canvas.queue_redraw()
159+
transformation_canceled.emit()
155160

156161

157162
func commit_undo(action: String, undo_data_tmp: Dictionary) -> void:

src/UI/Canvas/TransformationHandles.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class TransformHandle:
102102

103103

104104
func _ready() -> void:
105+
selection_node.transformation_confirmed.connect(func(): active_handle = null)
106+
selection_node.transformation_canceled.connect(func(): active_handle = null)
105107
preview_transform_changed.connect(_on_preview_transform_changed)
106108
Global.camera.zoom_changed.connect(queue_redraw)
107109
set_process_input(false)

0 commit comments

Comments
 (0)