Added SymmetryGuides

Two special guides - one horizontal and one vertical - that let you change the axis of symmetry for mirroring. On the next commit(s) I will make them visible only if mirroring is toggled on. Almost solves #133
This commit is contained in:
OverloadedOrama 2020-07-16 04:25:59 +03:00
parent 7529e967e3
commit 9fa91ffd8e
7 changed files with 77 additions and 18 deletions

View file

@ -5,19 +5,21 @@ enum Types {HORIZONTAL, VERTICAL}
var font := preload("res://assets/fonts/Roboto-Regular.tres")
var has_focus := true
var mouse_pos := Vector2.ZERO
var previous_points := points
var type = Types.HORIZONTAL
var project = Global.current_project
func _ready() -> void:
width = 0.1
default_color = Global.guide_color
Global.current_project.guides.append(self)
project.guides.append(self)
func _input(_event : InputEvent):
width = Global.camera.zoom.x * 2
mouse_pos = get_local_mouse_position()
if points.size() < 2:
return
var point0 := points[0]
var point1 := points[1]
if type == Types.HORIZONTAL:
@ -27,13 +29,11 @@ func _input(_event : InputEvent):
point0.x -= width * 3
point1.x += width * 3
if Global.can_draw and Global.has_focus and point_in_rectangle(mouse_pos, point0, point1) and Input.is_action_just_pressed("left_mouse"):
if !point_in_rectangle(Global.canvas.current_pixel, Global.canvas.location, Global.canvas.location + Global.current_project.size):
if !point_in_rectangle(Global.canvas.current_pixel, Global.canvas.location, Global.canvas.location + project.size):
has_focus = true
Global.has_focus = false
update()
if has_focus and visible:
if Input.is_action_just_pressed("left_mouse"):
previous_points = points
if Input.is_action_pressed("left_mouse"):
if type == Types.HORIZONTAL:
points[0].y = round(mouse_pos.y)
@ -62,11 +62,11 @@ func _draw() -> void:
func outside_canvas() -> bool:
if type == Types.HORIZONTAL:
if points[0].y < 0 || points[0].y > Global.current_project.size.y:
if points[0].y < 0 || points[0].y > project.size.y:
queue_free()
return true
else:
if points[0].x < 0 || points[0].x > Global.current_project.size.x:
if points[0].x < 0 || points[0].x > project.size.x:
queue_free()
return true
return false

View file

@ -0,0 +1,25 @@
class_name SymmetryGuide extends Guide
func _ready() -> void:
._ready()
has_focus = false
func _input(_event : InputEvent) -> void:
._input(_event)
if type == Types.HORIZONTAL:
project.y_symmetry_point = points[0].y * 2 - 1
elif type == Types.VERTICAL:
project.x_symmetry_point = points[0].x * 2 - 1
func outside_canvas() -> bool:
if type == Types.HORIZONTAL:
points[0].y = clamp(points[0].y, 0, Global.current_project.size.y)
points[1].y = clamp(points[1].y, 0, Global.current_project.size.y)
elif type == Types.VERTICAL:
points[0].x = clamp(points[0].x, 0, Global.current_project.size.x)
points[1].x = clamp(points[1].x, 0, Global.current_project.size.x)
return false