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

Add partial logic for diagonal mirroring

Still WIP, no buttons and guides exposed yet.
This commit is contained in:
Emmanouil Papadeas 2024-11-21 03:25:41 +02:00
parent 849b815562
commit 558140b309
3 changed files with 70 additions and 21 deletions

View file

@ -9,9 +9,14 @@ signal options_reset
enum Dynamics { NONE, PRESSURE, VELOCITY } enum Dynamics { NONE, PRESSURE, VELOCITY }
const XY_LINE := Vector2(-0.707107, 0.707107)
const X_MINUS_Y_LINE := Vector2(0.707107, 0.707107)
var picking_color_for := MOUSE_BUTTON_LEFT var picking_color_for := MOUSE_BUTTON_LEFT
var horizontal_mirror := false var horizontal_mirror := false
var vertical_mirror := false var vertical_mirror := false
var diagonal_mirror := false
var diagonal_opposite_mirror := false
var pixel_perfect := false var pixel_perfect := false
var alpha_locked := false var alpha_locked := false
@ -524,20 +529,48 @@ func get_mirrored_positions(
) -> Array[Vector2i]: ) -> Array[Vector2i]:
var positions: Array[Vector2i] = [] var positions: Array[Vector2i] = []
if horizontal_mirror: if horizontal_mirror:
var mirror_x := pos var mirror_x := calculate_mirror_horizontal(pos, project, offset)
mirror_x.x = project.x_symmetry_point - pos.x + offset
positions.append(mirror_x) positions.append(mirror_x)
if vertical_mirror: if vertical_mirror:
var mirror_xy := mirror_x positions.append(calculate_mirror_vertical(mirror_x, project, offset))
mirror_xy.y = project.y_symmetry_point - pos.y + offset else:
positions.append(mirror_xy) if diagonal_mirror:
positions.append(calculate_mirror_xy(mirror_x, project))
if diagonal_opposite_mirror:
positions.append(calculate_mirror_x_minus_y(mirror_x, project))
if vertical_mirror: if vertical_mirror:
var mirror_y := pos var mirror_y := calculate_mirror_vertical(pos, project, offset)
mirror_y.y = project.y_symmetry_point - pos.y + offset
positions.append(mirror_y) positions.append(mirror_y)
if diagonal_mirror:
positions.append(calculate_mirror_xy(mirror_y, project))
if diagonal_opposite_mirror:
positions.append(calculate_mirror_x_minus_y(mirror_y, project))
if diagonal_mirror:
var mirror_diagonal := calculate_mirror_xy(pos, project)
positions.append(mirror_diagonal)
if not horizontal_mirror and not vertical_mirror:
positions.append(calculate_mirror_x_minus_y(mirror_diagonal, project))
if diagonal_opposite_mirror:
positions.append(calculate_mirror_x_minus_y(pos, project))
return positions return positions
func calculate_mirror_horizontal(pos: Vector2i, project: Project, offset := 0) -> Vector2i:
return Vector2i(project.x_symmetry_point - pos.x + offset, pos.y)
func calculate_mirror_vertical(pos: Vector2i, project: Project, offset := 0) -> Vector2i:
return Vector2i(pos.x, project.y_symmetry_point - pos.y + offset)
func calculate_mirror_xy(pos: Vector2i, project: Project) -> Vector2i:
return Vector2i(Vector2(pos).reflect(XY_LINE).round()) + project.size - Vector2i.ONE
func calculate_mirror_x_minus_y(pos: Vector2i, _project: Project) -> Vector2i:
return Vector2i(Vector2(pos).reflect(X_MINUS_Y_LINE).round())
func set_button_size(button_size: int) -> void: func set_button_size(button_size: int) -> void:
var size := Vector2(24, 24) if button_size == Global.ButtonSize.SMALL else Vector2(32, 32) var size := Vector2(24, 24) if button_size == Global.ButtonSize.SMALL else Vector2(32, 32)
if not is_instance_valid(_tool_buttons): if not is_instance_valid(_tool_buttons):

View file

@ -1,22 +1,19 @@
class_name Drawer class_name Drawer
const NUMBER_OF_DRAWERS := 8
var pixel_perfect := false: var pixel_perfect := false:
set(value): set(value):
pixel_perfect = value pixel_perfect = value
if pixel_perfect: if pixel_perfect:
drawers = pixel_perfect_drawers.duplicate() drawers = pixel_perfect_drawers.duplicate()
else: else:
drawers = [simple_drawer, simple_drawer, simple_drawer, simple_drawer] _create_simple_drawers()
var color_op := ColorOp.new() var color_op := ColorOp.new()
var simple_drawer := SimpleDrawer.new() var simple_drawer := SimpleDrawer.new()
var pixel_perfect_drawers: Array[PixelPerfectDrawer] = [ var pixel_perfect_drawers: Array[PixelPerfectDrawer] = []
PixelPerfectDrawer.new(), var drawers := []
PixelPerfectDrawer.new(),
PixelPerfectDrawer.new(),
PixelPerfectDrawer.new()
]
var drawers := [simple_drawer, simple_drawer, simple_drawer, simple_drawer]
class ColorOp: class ColorOp:
@ -60,6 +57,21 @@ class PixelPerfectDrawer:
last_pixels[0] = corner last_pixels[0] = corner
func _init() -> void:
drawers.resize(NUMBER_OF_DRAWERS)
pixel_perfect_drawers.resize(NUMBER_OF_DRAWERS)
for i in NUMBER_OF_DRAWERS:
drawers[i] = simple_drawer
pixel_perfect_drawers[i] = PixelPerfectDrawer.new()
func _create_simple_drawers() -> void:
drawers = []
drawers.resize(NUMBER_OF_DRAWERS)
for i in NUMBER_OF_DRAWERS:
drawers[i] = simple_drawer
func reset() -> void: func reset() -> void:
for drawer in pixel_perfect_drawers: for drawer in pixel_perfect_drawers:
drawer.reset() drawer.reset()
@ -72,7 +84,12 @@ func set_pixel(image: Image, position: Vector2i, color: Color, ignore_mirroring
SteamManager.set_achievement("ACH_FIRST_PIXEL") SteamManager.set_achievement("ACH_FIRST_PIXEL")
if ignore_mirroring: if ignore_mirroring:
return return
if not Tools.horizontal_mirror and not Tools.vertical_mirror: if (
not Tools.horizontal_mirror
and not Tools.vertical_mirror
and not Tools.diagonal_mirror
and not Tools.diagonal_opposite_mirror
):
return return
# Handle mirroring # Handle mirroring
var mirrored_positions := Tools.get_mirrored_positions(position, project) var mirrored_positions := Tools.get_mirrored_positions(position, project)

View file

@ -213,23 +213,22 @@ func mirror_array(array: Array[Vector2i], callable := func(_array): pass) -> Arr
if Tools.horizontal_mirror and Tools.vertical_mirror: 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( var mirror_x := Tools.calculate_mirror_horizontal(point, project)
Vector2i(project.x_symmetry_point - point.x, project.y_symmetry_point - point.y) hv_array.append(Tools.calculate_mirror_vertical(mirror_x, project))
)
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 Tools.horizontal_mirror: 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(Tools.calculate_mirror_horizontal(point, project))
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 Tools.vertical_mirror: 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(Tools.calculate_mirror_vertical(point, project))
if callable.is_valid(): if callable.is_valid():
callable.call(v_array) callable.call(v_array)
new_array += v_array new_array += v_array