1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Mirror the preview of the elliptical selection tool

This commit is contained in:
Emmanouil Papadeas 2024-07-31 21:29:05 +03:00
parent 6c016697d9
commit 3011d8469f
5 changed files with 41 additions and 50 deletions

View file

@ -202,6 +202,22 @@ func snap_position(pos: Vector2) -> Vector2:
return pos
func mirror_array(array: Array[Vector2i], h: bool, v: bool) -> Array[Vector2i]:
var new_array: Array[Vector2i] = []
var project := Global.current_project
for point in array:
if h and v:
new_array.append(
Vector2i(project.x_symmetry_point - point.x, project.y_symmetry_point - point.y)
)
elif h:
new_array.append(Vector2i(project.x_symmetry_point - point.x, point.y))
elif v:
new_array.append(Vector2i(point.x, project.y_symmetry_point - point.y))
return new_array
func _get_closest_point_to_grid(pos: Vector2, distance: float, grid_pos: Vector2) -> Vector2:
# If the cursor is close to the start/origin of a grid cell, snap to that
var snap_distance := distance * Vector2.ONE

View file

@ -56,12 +56,35 @@ func draw_preview() -> void:
var image := Image.create(
Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_LA8
)
for point in points:
var draw_point := point + temp_rect.position
for i in points.size():
points[i] += temp_rect.position
var draw_point := points[i]
if Global.mirror_view: # This fixes previewing in mirror mode
draw_point.x = image.get_width() - draw_point.x - 1
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
image.set_pixelv(draw_point, Color.WHITE)
# Handle mirroring
if Tools.horizontal_mirror:
for point in mirror_array(points, true, false):
var draw_point := point
if Global.mirror_view: # This fixes previewing in mirror mode
draw_point.x = image.get_width() - draw_point.x - 1
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
image.set_pixelv(draw_point, Color.WHITE)
if Tools.vertical_mirror:
for point in mirror_array(points, true, true):
var draw_point := point
if Global.mirror_view: # This fixes previewing in mirror mode
draw_point.x = image.get_width() - draw_point.x - 1
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
image.set_pixelv(draw_point, Color.WHITE)
if Tools.vertical_mirror:
for point in mirror_array(points, false, true):
var draw_point := point
if Global.mirror_view: # This fixes previewing in mirror mode
draw_point.x = image.get_width() - draw_point.x - 1
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
image.set_pixelv(draw_point, Color.WHITE)
var texture := ImageTexture.create_from_image(image)
canvas.texture = texture
else:

View file

@ -156,19 +156,3 @@ func append_gap(start: Vector2i, end: Vector2i) -> void:
err += dx
y += sy
_draw_points.append(Vector2i(x, y))
func mirror_array(array: Array[Vector2i], h: bool, v: bool) -> Array[Vector2i]:
var new_array: Array[Vector2i] = []
var project := Global.current_project
for point in array:
if h and v:
new_array.append(
Vector2i(project.x_symmetry_point - point.x, project.y_symmetry_point - point.y)
)
elif h:
new_array.append(Vector2i(project.x_symmetry_point - point.x, point.y))
elif v:
new_array.append(Vector2i(point.x, project.y_symmetry_point - point.y))
return new_array

View file

@ -173,22 +173,6 @@ func append_gap(start: Vector2i, end: Vector2i) -> void:
_draw_points.append_array(draw_tool(Vector2i(x, y)))
func mirror_array(array: Array[Vector2i], h: bool, v: bool) -> Array[Vector2i]:
var new_array: Array[Vector2i] = []
var project := Global.current_project
for point in array:
if h and v:
new_array.append(
Vector2i(project.x_symmetry_point - point.x, project.y_symmetry_point - point.y)
)
elif h:
new_array.append(Vector2i(project.x_symmetry_point - point.x, point.y))
elif v:
new_array.append(Vector2i(point.x, project.y_symmetry_point - point.y))
return new_array
func draw_tool(pos: Vector2i) -> Array[Vector2i]:
_prepare_tool()
return _draw_tool(pos)

View file

@ -201,22 +201,6 @@ func append_gap(start: Vector2i, end: Vector2i, array: Array[Vector2i]) -> void:
array.append(Vector2i(x, y))
func mirror_array(array: Array[Vector2i], h: bool, v: bool) -> Array[Vector2i]:
var new_array: Array[Vector2i] = []
var project := Global.current_project
for point in array:
if h and v:
new_array.append(
Vector2i(project.x_symmetry_point - point.x, project.y_symmetry_point - point.y)
)
elif h:
new_array.append(Vector2i(project.x_symmetry_point - point.x, point.y))
elif v:
new_array.append(Vector2i(point.x, project.y_symmetry_point - point.y))
return new_array
# Thanks to
# https://www.reddit.com/r/godot/comments/3ktq39/drawing_empty_circles_and_curves/cv0f4eo/
func draw_empty_circle(