mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Further simplify mirror_array()
This commit is contained in:
parent
3615ce087c
commit
849b815562
|
@ -168,7 +168,7 @@ func draw_preview() -> void:
|
||||||
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(points[i]):
|
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(points[i]):
|
||||||
image.set_pixelv(points[i], Color.WHITE)
|
image.set_pixelv(points[i], Color.WHITE)
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
for point in mirror_array(points, Tools.horizontal_mirror, Tools.vertical_mirror):
|
for point in mirror_array(points):
|
||||||
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
||||||
image.set_pixelv(point, Color.WHITE)
|
image.set_pixelv(point, Color.WHITE)
|
||||||
var texture := ImageTexture.create_from_image(image)
|
var texture := ImageTexture.create_from_image(image)
|
||||||
|
|
|
@ -205,14 +205,12 @@ func snap_position(pos: Vector2) -> Vector2:
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
|
|
||||||
## Returns an array that mirrors each point of the [param array], based on [param h] and [param v].
|
## Returns an array that mirrors each point of the [param array].
|
||||||
## An optional [param callable] can be passed, which gets called for each type of symmetry.
|
## An optional [param callable] can be passed, which gets called for each type of symmetry.
|
||||||
func mirror_array(
|
func mirror_array(array: Array[Vector2i], callable := func(_array): pass) -> Array[Vector2i]:
|
||||||
array: Array[Vector2i], h: bool, v: bool, callable := func(_array): pass
|
|
||||||
) -> Array[Vector2i]:
|
|
||||||
var new_array: Array[Vector2i] = []
|
var new_array: Array[Vector2i] = []
|
||||||
var project := Global.current_project
|
var project := Global.current_project
|
||||||
if h and v:
|
if Tools.horizontal_mirror and Tools.vertical_mirror:
|
||||||
var hv_array: Array[Vector2i] = []
|
var hv_array: Array[Vector2i] = []
|
||||||
for point in array:
|
for point in array:
|
||||||
hv_array.append(
|
hv_array.append(
|
||||||
|
@ -221,14 +219,14 @@ func mirror_array(
|
||||||
if callable.is_valid():
|
if callable.is_valid():
|
||||||
callable.call(hv_array)
|
callable.call(hv_array)
|
||||||
new_array += hv_array
|
new_array += hv_array
|
||||||
if h:
|
if Tools.horizontal_mirror:
|
||||||
var h_array: Array[Vector2i] = []
|
var h_array: Array[Vector2i] = []
|
||||||
for point in array:
|
for point in array:
|
||||||
h_array.append(Vector2i(project.x_symmetry_point - point.x, point.y))
|
h_array.append(Vector2i(project.x_symmetry_point - point.x, point.y))
|
||||||
if callable.is_valid():
|
if callable.is_valid():
|
||||||
callable.call(h_array)
|
callable.call(h_array)
|
||||||
new_array += h_array
|
new_array += h_array
|
||||||
if v:
|
if Tools.vertical_mirror:
|
||||||
var v_array: Array[Vector2i] = []
|
var v_array: Array[Vector2i] = []
|
||||||
for point in array:
|
for point in array:
|
||||||
v_array.append(Vector2i(point.x, project.y_symmetry_point - point.y))
|
v_array.append(Vector2i(point.x, project.y_symmetry_point - point.y))
|
||||||
|
|
|
@ -141,7 +141,7 @@ func draw_preview() -> void:
|
||||||
image.set_pixelv(points[i], Color.WHITE)
|
image.set_pixelv(points[i], Color.WHITE)
|
||||||
|
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
for point in mirror_array(points, Tools.horizontal_mirror, Tools.vertical_mirror):
|
for point in mirror_array(points):
|
||||||
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
||||||
image.set_pixelv(point, Color.WHITE)
|
image.set_pixelv(point, Color.WHITE)
|
||||||
var texture := ImageTexture.create_from_image(image)
|
var texture := ImageTexture.create_from_image(image)
|
||||||
|
|
|
@ -157,7 +157,7 @@ func draw_preview() -> void:
|
||||||
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
||||||
image.set_pixelv(point, Color.WHITE)
|
image.set_pixelv(point, Color.WHITE)
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
for point in mirror_array(points, Tools.horizontal_mirror, Tools.vertical_mirror):
|
for point in mirror_array(points):
|
||||||
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
||||||
image.set_pixelv(point, Color.WHITE)
|
image.set_pixelv(point, Color.WHITE)
|
||||||
var texture := ImageTexture.create_from_image(image)
|
var texture := ImageTexture.create_from_image(image)
|
||||||
|
|
|
@ -63,7 +63,7 @@ func draw_preview() -> void:
|
||||||
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(points[i]):
|
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(points[i]):
|
||||||
image.set_pixelv(points[i], Color.WHITE)
|
image.set_pixelv(points[i], Color.WHITE)
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
for point in mirror_array(points, Tools.horizontal_mirror, Tools.vertical_mirror):
|
for point in mirror_array(points):
|
||||||
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point):
|
||||||
image.set_pixelv(point, Color.WHITE)
|
image.set_pixelv(point, Color.WHITE)
|
||||||
var texture := ImageTexture.create_from_image(image)
|
var texture := ImageTexture.create_from_image(image)
|
||||||
|
|
|
@ -46,7 +46,7 @@ func draw_preview() -> void:
|
||||||
image.set_pixelv(draw_point, Color.WHITE)
|
image.set_pixelv(draw_point, Color.WHITE)
|
||||||
|
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
for point in mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror):
|
for point in mirror_array(_draw_points):
|
||||||
var draw_point := point
|
var draw_point := point
|
||||||
if Global.mirror_view: # This fixes previewing in mirror mode
|
if Global.mirror_view: # This fixes previewing in mirror mode
|
||||||
draw_point.x = image.get_width() - draw_point.x - 1
|
draw_point.x = image.get_width() - draw_point.x - 1
|
||||||
|
@ -73,7 +73,7 @@ func apply_selection(_position) -> void:
|
||||||
lasso_selection(_draw_points, project.selection_map, previous_selection_map)
|
lasso_selection(_draw_points, project.selection_map, previous_selection_map)
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
var callable := lasso_selection.bind(project.selection_map, previous_selection_map)
|
var callable := lasso_selection.bind(project.selection_map, previous_selection_map)
|
||||||
mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror, 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:
|
||||||
if !cleared:
|
if !cleared:
|
||||||
|
|
|
@ -74,7 +74,7 @@ func draw_preview() -> void:
|
||||||
image.set_pixelv(draw_point, Color.WHITE)
|
image.set_pixelv(draw_point, Color.WHITE)
|
||||||
|
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
for point in mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror):
|
for point in mirror_array(_draw_points):
|
||||||
var draw_point := point
|
var draw_point := point
|
||||||
if Global.mirror_view: # This fixes previewing in mirror mode
|
if Global.mirror_view: # This fixes previewing in mirror mode
|
||||||
draw_point.x = image.get_width() - draw_point.x - 1
|
draw_point.x = image.get_width() - draw_point.x - 1
|
||||||
|
@ -101,7 +101,7 @@ func apply_selection(pos: Vector2i) -> void:
|
||||||
project.selection_map.clear()
|
project.selection_map.clear()
|
||||||
paint_selection(project.selection_map, previous_selection_map, _draw_points)
|
paint_selection(project.selection_map, previous_selection_map, _draw_points)
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
var mirror := mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror)
|
var mirror := mirror_array(_draw_points)
|
||||||
paint_selection(project.selection_map, previous_selection_map, mirror)
|
paint_selection(project.selection_map, previous_selection_map, mirror)
|
||||||
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:
|
||||||
|
|
|
@ -81,9 +81,7 @@ func draw_preview() -> void:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
for point in mirror_array(
|
for point in mirror_array(preview_draw_points):
|
||||||
preview_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror
|
|
||||||
):
|
|
||||||
var draw_point := point
|
var draw_point := point
|
||||||
if Global.mirror_view: # This fixes previewing in mirror mode
|
if Global.mirror_view: # This fixes previewing in mirror mode
|
||||||
draw_point.x = image.get_width() - draw_point.x - 1
|
draw_point.x = image.get_width() - draw_point.x - 1
|
||||||
|
@ -112,7 +110,7 @@ func apply_selection(pos: Vector2i) -> void:
|
||||||
lasso_selection(_draw_points, project.selection_map, previous_selection_map)
|
lasso_selection(_draw_points, project.selection_map, previous_selection_map)
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
var callable := lasso_selection.bind(project.selection_map, previous_selection_map)
|
var callable := lasso_selection.bind(project.selection_map, previous_selection_map)
|
||||||
mirror_array(_draw_points, Tools.horizontal_mirror, Tools.vertical_mirror, 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:
|
||||||
if !cleared:
|
if !cleared:
|
||||||
|
|
Loading…
Reference in a new issue