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

Implement snap to grid while moving selections and using the Move tool

Mouse click + Ctrl to snap to grid while moving.
This commit is contained in:
Manolis Papadeas 2021-05-04 02:45:14 +03:00
parent 7cbbf4399d
commit 0ba940c886
3 changed files with 21 additions and 0 deletions

View file

@ -19,6 +19,9 @@ func draw_move(position : Vector2) -> void:
position.y = _start_pos.y
else:
position.x = _start_pos.x
if Tools.control: # Snap to grid
position = position.snapped(Vector2(Global.grid_width, Global.grid_height))
if Global.current_project.has_selection:
Global.canvas.selection.move_content(position - _offset)
_offset = position

View file

@ -9,6 +9,7 @@ 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("shift"):
_square = true

View file

@ -9,6 +9,7 @@ var _offset := Vector2.ZERO
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
var undo_data : Dictionary
@ -27,6 +28,19 @@ func _ready() -> void:
hspinbox.value = select_rect.size.y
func _input(event : InputEvent) -> void:
if _move:
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)
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:
var project : Project = Global.current_project
undo_data = selection_node._get_undo_data(false)
@ -70,6 +84,8 @@ func draw_move(position : Vector2) -> void:
position.y = _start_pos.y
else:
position.x = _start_pos.x
if _snap_to_grid:
position = position.snapped(Vector2(Global.grid_width, Global.grid_height))
if _move_content:
selection_node.move_content(position - _offset)
@ -87,6 +103,7 @@ func draw_end(_position : Vector2) -> void:
apply_selection(_position)
_move = false
_snap_to_grid = false
cursor_text = ""