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

Fixed move offsets (#713)

* Fixed move offsets

* Formatting

* More formatting

* Some more Formatting
This commit is contained in:
Variable 2022-07-04 04:41:26 +05:00 committed by GitHub
parent 8a922a255c
commit feb68a21a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,13 @@ func _input(event: InputEvent) -> void:
if Global.current_project.has_selection:
var prev_pos = selection_node.big_bounding_rectangle.position
selection_node.big_bounding_rectangle.position = prev_pos.snapped(grid_size)
# The First time transform_snap_grid is enabled then _snap_position() is not called
# and selection had wrong offset so i chose to do selection offsetting here
var grid_offset = Vector2(Global.grid_offset_x, Global.grid_offset_y)
grid_offset = Vector2(
fmod(grid_offset.x, grid_size.x), fmod(grid_offset.y, grid_size.y)
)
selection_node.big_bounding_rectangle.position += grid_offset
selection_node.marching_ants_outline.offset += (
selection_node.big_bounding_rectangle.position
- prev_pos
@ -97,9 +104,19 @@ func _snap_position(position: Vector2) -> Vector2:
if _snap_to_grid: # Snap to grid
var grid_size := Vector2(Global.grid_width, Global.grid_height)
position = position.snapped(grid_size)
var grid_offset = Vector2(Global.grid_offset_x, Global.grid_offset_y)
grid_offset = Vector2(fmod(grid_offset.x, grid_size.x), fmod(grid_offset.y, grid_size.y))
position += grid_offset
# The part below only corrects the offset for situations when there is no selection
# Offsets when there is selection is controlled in _input() function
if !Global.current_project.has_selection:
var move_offset := Vector2.ZERO
move_offset.x = (
_start_pos.x
- int(_start_pos.x / Global.grid_width) * Global.grid_width
)
move_offset.y = (
_start_pos.y
- int(_start_pos.y / Global.grid_height) * Global.grid_height
)
position += move_offset
return position