mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 09:39:48 +00:00
Support draw tiles mode in lasso and polygon select tools
This commit is contained in:
parent
4365ed8a3a
commit
58ab5b7083
|
@ -70,9 +70,9 @@ func apply_selection(_position) -> void:
|
||||||
if _draw_points.size() > 3:
|
if _draw_points.size() > 3:
|
||||||
if _intersect:
|
if _intersect:
|
||||||
project.selection_map.clear()
|
project.selection_map.clear()
|
||||||
lasso_selection(_draw_points, project.selection_map, previous_selection_map)
|
lasso_selection(_draw_points, project, previous_selection_map)
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
var callable := lasso_selection.bind(project.selection_map, previous_selection_map)
|
var callable := lasso_selection.bind(project, previous_selection_map)
|
||||||
mirror_array(_draw_points, callable)
|
mirror_array(_draw_points, callable)
|
||||||
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
|
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
|
||||||
else:
|
else:
|
||||||
|
@ -85,8 +85,9 @@ func apply_selection(_position) -> void:
|
||||||
|
|
||||||
|
|
||||||
func lasso_selection(
|
func lasso_selection(
|
||||||
points: Array[Vector2i], selection_map: SelectionMap, previous_selection_map: SelectionMap
|
points: Array[Vector2i], project: Project, previous_selection_map: SelectionMap
|
||||||
) -> void:
|
) -> void:
|
||||||
|
var selection_map := project.selection_map
|
||||||
var selection_size := selection_map.get_size()
|
var selection_size := selection_map.get_size()
|
||||||
var bounding_rect := Rect2i(points[0], Vector2i.ZERO)
|
var bounding_rect := Rect2i(points[0], Vector2i.ZERO)
|
||||||
for point in points:
|
for point in points:
|
||||||
|
@ -95,9 +96,9 @@ func lasso_selection(
|
||||||
bounding_rect = bounding_rect.expand(point)
|
bounding_rect = bounding_rect.expand(point)
|
||||||
if _intersect:
|
if _intersect:
|
||||||
if previous_selection_map.is_pixel_selected(point):
|
if previous_selection_map.is_pixel_selected(point):
|
||||||
selection_map.select_pixel(point, true)
|
select_pixel(point, project, true)
|
||||||
else:
|
else:
|
||||||
selection_map.select_pixel(point, !_subtract)
|
select_pixel(point, project, !_subtract)
|
||||||
|
|
||||||
var v := Vector2i()
|
var v := Vector2i()
|
||||||
for x in bounding_rect.size.x:
|
for x in bounding_rect.size.x:
|
||||||
|
@ -107,9 +108,17 @@ func lasso_selection(
|
||||||
if Geometry2D.is_point_in_polygon(v, points):
|
if Geometry2D.is_point_in_polygon(v, points):
|
||||||
if _intersect:
|
if _intersect:
|
||||||
if previous_selection_map.is_pixel_selected(v):
|
if previous_selection_map.is_pixel_selected(v):
|
||||||
selection_map.select_pixel(v, true)
|
select_pixel(v, project, true)
|
||||||
else:
|
else:
|
||||||
selection_map.select_pixel(v, !_subtract)
|
select_pixel(v, project, !_subtract)
|
||||||
|
|
||||||
|
|
||||||
|
func select_pixel(point: Vector2i, project: Project, select: bool) -> void:
|
||||||
|
if Tools.is_placing_tiles():
|
||||||
|
var tilemap := project.get_current_cel() as CelTileMap
|
||||||
|
var cell_position := tilemap.get_cell_position(point)
|
||||||
|
select_tilemap_cell(tilemap, cell_position, project.selection_map, select)
|
||||||
|
project.selection_map.select_pixel(point, select)
|
||||||
|
|
||||||
|
|
||||||
# Bresenham's Algorithm
|
# Bresenham's Algorithm
|
||||||
|
|
|
@ -107,9 +107,9 @@ func apply_selection(pos: Vector2i) -> void:
|
||||||
if _draw_points.size() > 3:
|
if _draw_points.size() > 3:
|
||||||
if _intersect:
|
if _intersect:
|
||||||
project.selection_map.clear()
|
project.selection_map.clear()
|
||||||
lasso_selection(_draw_points, project.selection_map, previous_selection_map)
|
lasso_selection(_draw_points, project, previous_selection_map)
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
var callable := lasso_selection.bind(project.selection_map, previous_selection_map)
|
var callable := lasso_selection.bind(project, previous_selection_map)
|
||||||
mirror_array(_draw_points, callable)
|
mirror_array(_draw_points, callable)
|
||||||
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
|
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
|
||||||
else:
|
else:
|
||||||
|
@ -128,8 +128,9 @@ func _clear() -> void:
|
||||||
|
|
||||||
|
|
||||||
func lasso_selection(
|
func lasso_selection(
|
||||||
points: Array[Vector2i], selection_map: SelectionMap, previous_selection_map: SelectionMap
|
points: Array[Vector2i], project: Project, previous_selection_map: SelectionMap
|
||||||
) -> void:
|
) -> void:
|
||||||
|
var selection_map := project.selection_map
|
||||||
var selection_size := selection_map.get_size()
|
var selection_size := selection_map.get_size()
|
||||||
var bounding_rect := Rect2i(points[0], Vector2i.ZERO)
|
var bounding_rect := Rect2i(points[0], Vector2i.ZERO)
|
||||||
for point in points:
|
for point in points:
|
||||||
|
@ -138,9 +139,9 @@ func lasso_selection(
|
||||||
bounding_rect = bounding_rect.expand(point)
|
bounding_rect = bounding_rect.expand(point)
|
||||||
if _intersect:
|
if _intersect:
|
||||||
if previous_selection_map.is_pixel_selected(point):
|
if previous_selection_map.is_pixel_selected(point):
|
||||||
selection_map.select_pixel(point, true)
|
select_pixel(point, project, true)
|
||||||
else:
|
else:
|
||||||
selection_map.select_pixel(point, !_subtract)
|
select_pixel(point, project, !_subtract)
|
||||||
|
|
||||||
var v := Vector2i()
|
var v := Vector2i()
|
||||||
for x in bounding_rect.size.x:
|
for x in bounding_rect.size.x:
|
||||||
|
@ -150,9 +151,17 @@ func lasso_selection(
|
||||||
if Geometry2D.is_point_in_polygon(v, points):
|
if Geometry2D.is_point_in_polygon(v, points):
|
||||||
if _intersect:
|
if _intersect:
|
||||||
if previous_selection_map.is_pixel_selected(v):
|
if previous_selection_map.is_pixel_selected(v):
|
||||||
selection_map.select_pixel(v, true)
|
select_pixel(v, project, true)
|
||||||
else:
|
else:
|
||||||
selection_map.select_pixel(v, !_subtract)
|
select_pixel(v, project, !_subtract)
|
||||||
|
|
||||||
|
|
||||||
|
func select_pixel(point: Vector2i, project: Project, select: bool) -> void:
|
||||||
|
if Tools.is_placing_tiles():
|
||||||
|
var tilemap := project.get_current_cel() as CelTileMap
|
||||||
|
var cell_position := tilemap.get_cell_position(point)
|
||||||
|
select_tilemap_cell(tilemap, cell_position, project.selection_map, select)
|
||||||
|
project.selection_map.select_pixel(point, select)
|
||||||
|
|
||||||
|
|
||||||
# Bresenham's Algorithm
|
# Bresenham's Algorithm
|
||||||
|
|
Loading…
Reference in a new issue