mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 09:39:48 +00:00
Add a grid_offset parameter for the rectangular grid snap methods
This commit is contained in:
parent
7fb65c3136
commit
ad2fcf4891
|
@ -520,7 +520,9 @@ func draw_indicator(left: bool) -> void:
|
||||||
if is_placing_tiles():
|
if is_placing_tiles():
|
||||||
var tileset := (Global.current_project.get_current_cel() as CelTileMap).tileset
|
var tileset := (Global.current_project.get_current_cel() as CelTileMap).tileset
|
||||||
var grid_size := tileset.tile_size
|
var grid_size := tileset.tile_size
|
||||||
snapped_position = _snap_to_rectangular_grid_center(snapped_position, grid_size, -1)
|
snapped_position = _snap_to_rectangular_grid_center(
|
||||||
|
snapped_position, grid_size, Vector2i.ZERO, -1
|
||||||
|
)
|
||||||
draw_indicator_at(snapped_position, Vector2i.ZERO, color)
|
draw_indicator_at(snapped_position, Vector2i.ZERO, color)
|
||||||
if (
|
if (
|
||||||
Global.current_project.has_selection
|
Global.current_project.has_selection
|
||||||
|
|
|
@ -145,10 +145,14 @@ func draw_preview() -> void:
|
||||||
func snap_position(pos: Vector2) -> Vector2:
|
func snap_position(pos: Vector2) -> Vector2:
|
||||||
var snapping_distance := Global.snapping_distance / Global.camera.zoom.x
|
var snapping_distance := Global.snapping_distance / Global.camera.zoom.x
|
||||||
if Global.snap_to_rectangular_grid_boundary:
|
if Global.snap_to_rectangular_grid_boundary:
|
||||||
pos = _snap_to_rectangular_grid_boundary(pos, Global.grids[0].grid_size, snapping_distance)
|
pos = _snap_to_rectangular_grid_boundary(
|
||||||
|
pos, Global.grids[0].grid_size, Global.grids[0].grid_offset, snapping_distance
|
||||||
|
)
|
||||||
|
|
||||||
if Global.snap_to_rectangular_grid_center:
|
if Global.snap_to_rectangular_grid_center:
|
||||||
pos = _snap_to_rectangular_grid_center(pos, Global.grids[0].grid_size, snapping_distance)
|
pos = _snap_to_rectangular_grid_center(
|
||||||
|
pos, Global.grids[0].grid_size, Global.grids[0].grid_offset, snapping_distance
|
||||||
|
)
|
||||||
|
|
||||||
var snap_to := Vector2.INF
|
var snap_to := Vector2.INF
|
||||||
if Global.snap_to_guides:
|
if Global.snap_to_guides:
|
||||||
|
@ -262,22 +266,22 @@ func _get_closest_point_to_segment(
|
||||||
|
|
||||||
|
|
||||||
func _snap_to_rectangular_grid_boundary(
|
func _snap_to_rectangular_grid_boundary(
|
||||||
pos: Vector2, grid_size: Vector2i, snapping_distance: float
|
pos: Vector2, grid_size: Vector2i, grid_offset: Vector2i, snapping_distance: float
|
||||||
) -> Vector2:
|
) -> Vector2:
|
||||||
var grid_pos := pos.snapped(Global.grids[0].grid_size)
|
var grid_pos := pos.snapped(grid_size)
|
||||||
grid_pos += Vector2(Global.grids[0].grid_offset)
|
grid_pos += Vector2(grid_offset)
|
||||||
# keeping grid_pos as is would have been fine but this adds extra accuracy as to
|
# 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
|
# which snap point (from the list below) is closest to mouse and occupy THAT point
|
||||||
# t_l is for "top left" and so on
|
# 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_l := grid_pos + Vector2(-grid_size.x, -grid_size.y)
|
||||||
var t_c := grid_pos + Vector2(0, -Global.grids[0].grid_size.y)
|
var t_c := grid_pos + Vector2(0, -grid_size.y)
|
||||||
var t_r := grid_pos + Vector2(Global.grids[0].grid_size.x, -Global.grids[0].grid_size.y)
|
var t_r := grid_pos + Vector2(grid_size.x, -grid_size.y)
|
||||||
var m_l := grid_pos + Vector2(-Global.grids[0].grid_size.x, 0)
|
var m_l := grid_pos + Vector2(-grid_size.x, 0)
|
||||||
var m_c := grid_pos
|
var m_c := grid_pos
|
||||||
var m_r := grid_pos + Vector2(Global.grids[0].grid_size.x, 0)
|
var m_r := grid_pos + Vector2(grid_size.x, 0)
|
||||||
var b_l := grid_pos + Vector2(-Global.grids[0].grid_size.x, Global.grids[0].grid_size.y)
|
var b_l := grid_pos + Vector2(-grid_size.x, grid_size.y)
|
||||||
var b_c := grid_pos + Vector2(0, Global.grids[0].grid_size.y)
|
var b_c := grid_pos + Vector2(0, grid_size.y)
|
||||||
var b_r := grid_pos + Vector2(Global.grids[0].grid_size)
|
var b_r := grid_pos + Vector2(grid_size)
|
||||||
var vec_arr: PackedVector2Array = [t_l, t_c, t_r, m_l, m_c, m_r, b_l, b_c, b_r]
|
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:
|
for vec in vec_arr:
|
||||||
if vec.distance_to(pos) < grid_pos.distance_to(pos):
|
if vec.distance_to(pos) < grid_pos.distance_to(pos):
|
||||||
|
@ -290,10 +294,10 @@ func _snap_to_rectangular_grid_boundary(
|
||||||
|
|
||||||
|
|
||||||
func _snap_to_rectangular_grid_center(
|
func _snap_to_rectangular_grid_center(
|
||||||
pos: Vector2, grid_size: Vector2i, snapping_distance: float
|
pos: Vector2, grid_size: Vector2i, grid_offset: Vector2i, snapping_distance: float
|
||||||
) -> Vector2:
|
) -> Vector2:
|
||||||
var grid_center := pos.snapped(grid_size) + Vector2(grid_size / 2)
|
var grid_center := pos.snapped(grid_size) + Vector2(grid_size / 2)
|
||||||
grid_center += Vector2(Global.grids[0].grid_offset)
|
grid_center += Vector2(grid_offset)
|
||||||
# keeping grid_center as is would have been fine but this adds extra accuracy as to
|
# keeping grid_center 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
|
# which snap point (from the list below) is closest to mouse and occupy THAT point
|
||||||
# t_l is for "top left" and so on
|
# t_l is for "top left" and so on
|
||||||
|
|
Loading…
Reference in a new issue