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:
parent
849b815562
commit
558140b309
|
@ -9,9 +9,14 @@ signal options_reset
|
|||
|
||||
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 horizontal_mirror := false
|
||||
var vertical_mirror := false
|
||||
var diagonal_mirror := false
|
||||
var diagonal_opposite_mirror := false
|
||||
var pixel_perfect := false
|
||||
var alpha_locked := false
|
||||
|
||||
|
@ -524,20 +529,48 @@ func get_mirrored_positions(
|
|||
) -> Array[Vector2i]:
|
||||
var positions: Array[Vector2i] = []
|
||||
if horizontal_mirror:
|
||||
var mirror_x := pos
|
||||
mirror_x.x = project.x_symmetry_point - pos.x + offset
|
||||
var mirror_x := calculate_mirror_horizontal(pos, project, offset)
|
||||
positions.append(mirror_x)
|
||||
if vertical_mirror:
|
||||
var mirror_xy := mirror_x
|
||||
mirror_xy.y = project.y_symmetry_point - pos.y + offset
|
||||
positions.append(mirror_xy)
|
||||
positions.append(calculate_mirror_vertical(mirror_x, project, offset))
|
||||
else:
|
||||
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:
|
||||
var mirror_y := pos
|
||||
mirror_y.y = project.y_symmetry_point - pos.y + offset
|
||||
var mirror_y := calculate_mirror_vertical(pos, project, offset)
|
||||
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
|
||||
|
||||
|
||||
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:
|
||||
var size := Vector2(24, 24) if button_size == Global.ButtonSize.SMALL else Vector2(32, 32)
|
||||
if not is_instance_valid(_tool_buttons):
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
class_name Drawer
|
||||
|
||||
const NUMBER_OF_DRAWERS := 8
|
||||
|
||||
var pixel_perfect := false:
|
||||
set(value):
|
||||
pixel_perfect = value
|
||||
if pixel_perfect:
|
||||
drawers = pixel_perfect_drawers.duplicate()
|
||||
else:
|
||||
drawers = [simple_drawer, simple_drawer, simple_drawer, simple_drawer]
|
||||
_create_simple_drawers()
|
||||
var color_op := ColorOp.new()
|
||||
|
||||
var simple_drawer := SimpleDrawer.new()
|
||||
var pixel_perfect_drawers: Array[PixelPerfectDrawer] = [
|
||||
PixelPerfectDrawer.new(),
|
||||
PixelPerfectDrawer.new(),
|
||||
PixelPerfectDrawer.new(),
|
||||
PixelPerfectDrawer.new()
|
||||
]
|
||||
var drawers := [simple_drawer, simple_drawer, simple_drawer, simple_drawer]
|
||||
var pixel_perfect_drawers: Array[PixelPerfectDrawer] = []
|
||||
var drawers := []
|
||||
|
||||
|
||||
class ColorOp:
|
||||
|
@ -60,6 +57,21 @@ class PixelPerfectDrawer:
|
|||
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:
|
||||
for drawer in pixel_perfect_drawers:
|
||||
drawer.reset()
|
||||
|
@ -72,7 +84,12 @@ func set_pixel(image: Image, position: Vector2i, color: Color, ignore_mirroring
|
|||
SteamManager.set_achievement("ACH_FIRST_PIXEL")
|
||||
if ignore_mirroring:
|
||||
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
|
||||
# Handle mirroring
|
||||
var mirrored_positions := Tools.get_mirrored_positions(position, project)
|
||||
|
|
|
@ -213,23 +213,22 @@ func mirror_array(array: Array[Vector2i], callable := func(_array): pass) -> Arr
|
|||
if Tools.horizontal_mirror and Tools.vertical_mirror:
|
||||
var hv_array: Array[Vector2i] = []
|
||||
for point in array:
|
||||
hv_array.append(
|
||||
Vector2i(project.x_symmetry_point - point.x, project.y_symmetry_point - point.y)
|
||||
)
|
||||
var mirror_x := Tools.calculate_mirror_horizontal(point, project)
|
||||
hv_array.append(Tools.calculate_mirror_vertical(mirror_x, project))
|
||||
if callable.is_valid():
|
||||
callable.call(hv_array)
|
||||
new_array += hv_array
|
||||
if Tools.horizontal_mirror:
|
||||
var h_array: Array[Vector2i] = []
|
||||
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():
|
||||
callable.call(h_array)
|
||||
new_array += h_array
|
||||
if Tools.vertical_mirror:
|
||||
var v_array: Array[Vector2i] = []
|
||||
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():
|
||||
callable.call(v_array)
|
||||
new_array += v_array
|
||||
|
|
Loading…
Reference in a new issue