mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Add a _snap_to_rectangular_grid_boundary() method to BaseTool
And rename _snap_to_grid_center() to _snap_to_rectangular_grid_center()
This commit is contained in:
parent
4d5eebc670
commit
7fb65c3136
|
@ -520,7 +520,7 @@ func draw_indicator(left: bool) -> void:
|
|||
if is_placing_tiles():
|
||||
var tileset := (Global.current_project.get_current_cel() as CelTileMap).tileset
|
||||
var grid_size := tileset.tile_size
|
||||
snapped_position = _snap_to_grid_center(snapped_position, grid_size, -1)
|
||||
snapped_position = _snap_to_rectangular_grid_center(snapped_position, grid_size, -1)
|
||||
draw_indicator_at(snapped_position, Vector2i.ZERO, color)
|
||||
if (
|
||||
Global.current_project.has_selection
|
||||
|
|
|
@ -145,31 +145,10 @@ func draw_preview() -> void:
|
|||
func snap_position(pos: Vector2) -> Vector2:
|
||||
var snapping_distance := Global.snapping_distance / Global.camera.zoom.x
|
||||
if Global.snap_to_rectangular_grid_boundary:
|
||||
var grid_pos := pos.snapped(Global.grids[0].grid_size)
|
||||
grid_pos += Vector2(Global.grids[0].grid_offset)
|
||||
# keeping grid_pos as is would have been fine but this adds extra accuracy as to
|
||||
# which snap point (from the list below) is closest to mouse and occupy THAT point
|
||||
# t_l is for "top left" and so on
|
||||
var t_l := grid_pos + Vector2(-Global.grids[0].grid_size.x, -Global.grids[0].grid_size.y)
|
||||
var t_c := grid_pos + Vector2(0, -Global.grids[0].grid_size.y)
|
||||
var t_r := grid_pos + Vector2(Global.grids[0].grid_size.x, -Global.grids[0].grid_size.y)
|
||||
var m_l := grid_pos + Vector2(-Global.grids[0].grid_size.x, 0)
|
||||
var m_c := grid_pos
|
||||
var m_r := grid_pos + Vector2(Global.grids[0].grid_size.x, 0)
|
||||
var b_l := grid_pos + Vector2(-Global.grids[0].grid_size.x, Global.grids[0].grid_size.y)
|
||||
var b_c := grid_pos + Vector2(0, Global.grids[0].grid_size.y)
|
||||
var b_r := grid_pos + Vector2(Global.grids[0].grid_size)
|
||||
var vec_arr: PackedVector2Array = [t_l, t_c, t_r, m_l, m_c, m_r, b_l, b_c, b_r]
|
||||
for vec in vec_arr:
|
||||
if vec.distance_to(pos) < grid_pos.distance_to(pos):
|
||||
grid_pos = vec
|
||||
|
||||
var grid_point := _get_closest_point_to_grid(pos, snapping_distance, grid_pos)
|
||||
if grid_point != Vector2.INF:
|
||||
pos = grid_point.floor()
|
||||
pos = _snap_to_rectangular_grid_boundary(pos, Global.grids[0].grid_size, snapping_distance)
|
||||
|
||||
if Global.snap_to_rectangular_grid_center:
|
||||
pos = _snap_to_grid_center(pos, Global.grids[0].grid_size, snapping_distance)
|
||||
pos = _snap_to_rectangular_grid_center(pos, Global.grids[0].grid_size, snapping_distance)
|
||||
|
||||
var snap_to := Vector2.INF
|
||||
if Global.snap_to_guides:
|
||||
|
@ -282,7 +261,37 @@ func _get_closest_point_to_segment(
|
|||
return closest_point
|
||||
|
||||
|
||||
func _snap_to_grid_center(pos: Vector2, grid_size: Vector2i, snapping_distance: float) -> Vector2:
|
||||
func _snap_to_rectangular_grid_boundary(
|
||||
pos: Vector2, grid_size: Vector2i, snapping_distance: float
|
||||
) -> Vector2:
|
||||
var grid_pos := pos.snapped(Global.grids[0].grid_size)
|
||||
grid_pos += Vector2(Global.grids[0].grid_offset)
|
||||
# keeping grid_pos as is would have been fine but this adds extra accuracy as to
|
||||
# which snap point (from the list below) is closest to mouse and occupy THAT point
|
||||
# t_l is for "top left" and so on
|
||||
var t_l := grid_pos + Vector2(-Global.grids[0].grid_size.x, -Global.grids[0].grid_size.y)
|
||||
var t_c := grid_pos + Vector2(0, -Global.grids[0].grid_size.y)
|
||||
var t_r := grid_pos + Vector2(Global.grids[0].grid_size.x, -Global.grids[0].grid_size.y)
|
||||
var m_l := grid_pos + Vector2(-Global.grids[0].grid_size.x, 0)
|
||||
var m_c := grid_pos
|
||||
var m_r := grid_pos + Vector2(Global.grids[0].grid_size.x, 0)
|
||||
var b_l := grid_pos + Vector2(-Global.grids[0].grid_size.x, Global.grids[0].grid_size.y)
|
||||
var b_c := grid_pos + Vector2(0, Global.grids[0].grid_size.y)
|
||||
var b_r := grid_pos + Vector2(Global.grids[0].grid_size)
|
||||
var vec_arr: PackedVector2Array = [t_l, t_c, t_r, m_l, m_c, m_r, b_l, b_c, b_r]
|
||||
for vec in vec_arr:
|
||||
if vec.distance_to(pos) < grid_pos.distance_to(pos):
|
||||
grid_pos = vec
|
||||
|
||||
var grid_point := _get_closest_point_to_grid(pos, snapping_distance, grid_pos)
|
||||
if grid_point != Vector2.INF:
|
||||
pos = grid_point.floor()
|
||||
return pos
|
||||
|
||||
|
||||
func _snap_to_rectangular_grid_center(
|
||||
pos: Vector2, grid_size: Vector2i, snapping_distance: float
|
||||
) -> Vector2:
|
||||
var grid_center := pos.snapped(grid_size) + Vector2(grid_size / 2)
|
||||
grid_center += Vector2(Global.grids[0].grid_offset)
|
||||
# keeping grid_center as is would have been fine but this adds extra accuracy as to
|
||||
|
|
Loading…
Reference in a new issue