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

Stop movement if content transformation has been confirmed while content is being moved

This commit is contained in:
Manolis Papadeas 2021-05-11 04:41:30 +03:00
parent 969b096efc
commit 1b80100588
2 changed files with 29 additions and 8 deletions

View file

@ -4,15 +4,26 @@ extends BaseTool
var _start_pos : Vector2 var _start_pos : Vector2
var _offset : Vector2 var _offset : Vector2
# 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
var _content_transformation_check := false
onready var selection_node : Node2D = Global.canvas.selection
func draw_start(position : Vector2) -> void: func draw_start(position : Vector2) -> void:
_start_pos = position _start_pos = position
_offset = position _offset = position
if Global.current_project.has_selection: if Global.current_project.has_selection:
Global.canvas.selection.transform_content_start() selection_node.transform_content_start()
_content_transformation_check = selection_node.is_moving_content
func draw_move(position : Vector2) -> void: func draw_move(position : Vector2) -> void:
# This is true if content transformation has been confirmed (pressed Enter for example)
# while the content is being moved
if _content_transformation_check != selection_node.is_moving_content:
return
if Tools.shift: # Snap to axis if Tools.shift: # Snap to axis
var angle := position.angle_to_point(_start_pos) var angle := position.angle_to_point(_start_pos)
if abs(angle) <= PI / 4 or abs(angle) >= 3*PI / 4: if abs(angle) <= PI / 4 or abs(angle) >= 3*PI / 4:
@ -23,7 +34,7 @@ func draw_move(position : Vector2) -> void:
position = position.snapped(Vector2(Global.grid_width, Global.grid_height)) position = position.snapped(Vector2(Global.grid_width, Global.grid_height))
if Global.current_project.has_selection: if Global.current_project.has_selection:
Global.canvas.selection.move_content(position - _offset) selection_node.move_content(position - _offset)
_offset = position _offset = position
else: else:
Global.canvas.move_preview_location = position - _start_pos Global.canvas.move_preview_location = position - _start_pos
@ -31,7 +42,7 @@ func draw_move(position : Vector2) -> void:
func draw_end(position : Vector2) -> void: func draw_end(position : Vector2) -> void:
if _start_pos != Vector2.INF: if _start_pos != Vector2.INF and _content_transformation_check == selection_node.is_moving_content:
if Tools.shift: # Snap to axis if Tools.shift: # Snap to axis
var angle := position.angle_to_point(_start_pos) var angle := position.angle_to_point(_start_pos)
if abs(angle) <= PI / 4 or abs(angle) >= 3*PI / 4: if abs(angle) <= PI / 4 or abs(angle) >= 3*PI / 4:
@ -43,7 +54,7 @@ func draw_end(position : Vector2) -> void:
var image : Image = _get_draw_image() var image : Image = _get_draw_image()
if project.has_selection: if project.has_selection:
Global.canvas.selection.move_borders_end() selection_node.move_borders_end()
else: else:
Global.canvas.move_preview_location = Vector2.ZERO Global.canvas.move_preview_location = Vector2.ZERO
var image_copy := Image.new() var image_copy := Image.new()

View file

@ -11,6 +11,9 @@ var _subtract := false # Ctrl + Mouse Click
var _intersect := false # Shift + Ctrl + Mouse Click var _intersect := false # Shift + Ctrl + Mouse Click
var _snap_to_grid := false # Mouse Click + Ctrl 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
var _content_transformation_check := false
var undo_data : Dictionary var undo_data : Dictionary
onready var selection_node : Node2D = Global.canvas.selection onready var selection_node : Node2D = Global.canvas.selection
@ -87,10 +90,16 @@ func draw_start(position : Vector2) -> void:
else: else:
selection_node.transform_content_confirm() selection_node.transform_content_confirm()
_content_transformation_check = selection_node.is_moving_content
func draw_move(position : Vector2) -> void: func draw_move(position : Vector2) -> void:
if selection_node.arrow_key_move: if selection_node.arrow_key_move:
return return
# This is true if content transformation has been confirmed (pressed Enter for example)
# while the content is being moved
if _content_transformation_check != selection_node.is_moving_content:
return
if _move: if _move:
if Tools.shift: # Snap to axis if Tools.shift: # Snap to axis
var angle := position.angle_to_point(_start_pos) var angle := position.angle_to_point(_start_pos)
@ -113,10 +122,11 @@ func draw_move(position : Vector2) -> void:
func draw_end(_position : Vector2) -> void: func draw_end(_position : Vector2) -> void:
if selection_node.arrow_key_move: if selection_node.arrow_key_move:
return return
if _move: if _content_transformation_check == selection_node.is_moving_content:
selection_node.move_borders_end() if _move:
else: selection_node.move_borders_end()
apply_selection(_position) else:
apply_selection(_position)
_move = false _move = false
_snap_to_grid = false _snap_to_grid = false