mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Fix Move tool's snap to grid movement and take grid offset into account
This commit is contained in:
parent
6d2f02b782
commit
43e733fe65
|
@ -7,10 +7,25 @@ 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
|
||||
var _snap_to_grid := false # Mouse Click + Ctrl
|
||||
|
||||
onready var selection_node : Node2D = Global.canvas.selection
|
||||
|
||||
|
||||
func _input(event : InputEvent) -> void:
|
||||
if _start_pos != Vector2.INF:
|
||||
if event.is_action_pressed("ctrl"):
|
||||
_snap_to_grid = true
|
||||
var grid_size := Vector2(Global.grid_width, Global.grid_height)
|
||||
_offset = _offset.snapped(grid_size)
|
||||
if Global.current_project.has_selection:
|
||||
var prev_pos = selection_node.big_bounding_rectangle.position
|
||||
selection_node.big_bounding_rectangle.position = selection_node.big_bounding_rectangle.position.snapped(grid_size)
|
||||
selection_node.marching_ants_outline.offset += selection_node.big_bounding_rectangle.position - prev_pos
|
||||
elif event.is_action_released("ctrl"):
|
||||
_snap_to_grid = false
|
||||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
_start_pos = position
|
||||
_offset = position
|
||||
|
@ -30,12 +45,12 @@ func draw_move(position : Vector2) -> void:
|
|||
position.y = _start_pos.y
|
||||
else:
|
||||
position.x = _start_pos.x
|
||||
if Tools.control: # Snap to grid
|
||||
if _snap_to_grid: # Snap to grid
|
||||
position = position.snapped(Vector2(Global.grid_width, Global.grid_height))
|
||||
position += Vector2(Global.grid_offset_x, Global.grid_offset_y)
|
||||
|
||||
if Global.current_project.has_selection:
|
||||
selection_node.move_content(position - _offset)
|
||||
_offset = position
|
||||
else:
|
||||
Global.canvas.move_preview_location = position - _start_pos
|
||||
_offset = position
|
||||
|
@ -49,6 +64,12 @@ func draw_end(position : Vector2) -> void:
|
|||
position.y = _start_pos.y
|
||||
else:
|
||||
position.x = _start_pos.x
|
||||
|
||||
if _snap_to_grid: # Snap to grid
|
||||
position = position.snapped(Vector2(Global.grid_width, Global.grid_height))
|
||||
position += Vector2(Global.grid_offset_x, Global.grid_offset_y)
|
||||
|
||||
|
||||
var pixel_diff : Vector2 = position - _start_pos
|
||||
var project : Project = Global.current_project
|
||||
var image : Image = _get_draw_image()
|
||||
|
@ -66,3 +87,4 @@ func draw_end(position : Vector2) -> void:
|
|||
Global.canvas.handle_redo("Draw")
|
||||
|
||||
_start_pos = Vector2.INF
|
||||
_snap_to_grid = false
|
||||
|
|
|
@ -112,6 +112,7 @@ func draw_move(position : Vector2) -> void:
|
|||
position.x = _start_pos.x
|
||||
if _snap_to_grid:
|
||||
position = position.snapped(Vector2(Global.grid_width, Global.grid_height))
|
||||
position += Vector2(Global.grid_offset_x, Global.grid_offset_y)
|
||||
|
||||
if _move_content:
|
||||
selection_node.move_content(position - _offset)
|
||||
|
|
Loading…
Reference in a new issue