mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
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:
parent
7529e967e3
commit
9fa91ffd8e
|
@ -42,7 +42,7 @@ _global_script_classes=[ {
|
||||||
"base": "Line2D",
|
"base": "Line2D",
|
||||||
"class": "Guide",
|
"class": "Guide",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/UI/Rulers/Guides.gd"
|
"path": "res://src/UI/Rulers/Guide.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Reference",
|
"base": "Reference",
|
||||||
"class": "Layer",
|
"class": "Layer",
|
||||||
|
@ -73,6 +73,11 @@ _global_script_classes=[ {
|
||||||
"class": "Project",
|
"class": "Project",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Classes/Project.gd"
|
"path": "res://src/Classes/Project.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Guide",
|
||||||
|
"class": "SymmetryGuide",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://src/UI/Rulers/SymmetryGuide.gd"
|
||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
"AnimationTag": "",
|
"AnimationTag": "",
|
||||||
|
@ -87,7 +92,8 @@ _global_script_class_icons={
|
||||||
"Palette": "",
|
"Palette": "",
|
||||||
"PaletteColor": "",
|
"PaletteColor": "",
|
||||||
"Patterns": "",
|
"Patterns": "",
|
||||||
"Project": ""
|
"Project": "",
|
||||||
|
"SymmetryGuide": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
|
|
@ -69,8 +69,8 @@ func set_pixel_perfect(value: bool) -> void:
|
||||||
func set_pixel(image: Image, position: Vector2, color: Color) -> void:
|
func set_pixel(image: Image, position: Vector2, color: Color) -> void:
|
||||||
var project : Project = Global.current_project
|
var project : Project = Global.current_project
|
||||||
|
|
||||||
var mirror_x = project.size.x - project.x_symmetry_point - position.x
|
var mirror_x = project.x_symmetry_point - position.x
|
||||||
var mirror_y = project.size.y - project.y_symmetry_point - position.y
|
var mirror_y = project.y_symmetry_point - position.y
|
||||||
var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1
|
var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1
|
||||||
var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1
|
var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,10 @@ var guides := [] # Array of Guides
|
||||||
|
|
||||||
var brushes := [] # Array of Images
|
var brushes := [] # Array of Images
|
||||||
|
|
||||||
var x_symmetry_point := -1
|
var x_symmetry_point := size.x / 2 + 1
|
||||||
var y_symmetry_point := -1
|
var y_symmetry_point := size.y / 2 + 1
|
||||||
|
var x_symmetry_axis : SymmetryGuide
|
||||||
|
var y_symmetry_axis : SymmetryGuide
|
||||||
var x_min := 0
|
var x_min := 0
|
||||||
var x_max := 64
|
var x_max := 64
|
||||||
var y_min := 0
|
var y_min := 0
|
||||||
|
@ -41,6 +43,22 @@ func _init(_frames := [], _name := tr("untitled")) -> void:
|
||||||
OpenSave.current_save_paths.append("")
|
OpenSave.current_save_paths.append("")
|
||||||
OpenSave.backup_save_paths.append("")
|
OpenSave.backup_save_paths.append("")
|
||||||
|
|
||||||
|
if !x_symmetry_axis:
|
||||||
|
x_symmetry_axis = SymmetryGuide.new()
|
||||||
|
x_symmetry_axis.type = x_symmetry_axis.Types.HORIZONTAL
|
||||||
|
x_symmetry_axis.project = self
|
||||||
|
x_symmetry_axis.add_point(Vector2(-19999, y_symmetry_point))
|
||||||
|
x_symmetry_axis.add_point(Vector2(19999, y_symmetry_point))
|
||||||
|
Global.canvas.add_child(x_symmetry_axis)
|
||||||
|
|
||||||
|
if !y_symmetry_axis:
|
||||||
|
y_symmetry_axis = SymmetryGuide.new()
|
||||||
|
y_symmetry_axis.type = y_symmetry_axis.Types.VERTICAL
|
||||||
|
y_symmetry_axis.project = self
|
||||||
|
y_symmetry_axis.add_point(Vector2(x_symmetry_point, -19999))
|
||||||
|
y_symmetry_axis.add_point(Vector2(x_symmetry_point, 19999))
|
||||||
|
Global.canvas.add_child(y_symmetry_axis)
|
||||||
|
|
||||||
|
|
||||||
func _set_selected_rect(value : Rect2) -> void:
|
func _set_selected_rect(value : Rect2) -> void:
|
||||||
selected_rect = value
|
selected_rect = value
|
||||||
|
@ -167,6 +185,8 @@ func serialize() -> Dictionary:
|
||||||
|
|
||||||
var guide_data := []
|
var guide_data := []
|
||||||
for guide in guides:
|
for guide in guides:
|
||||||
|
if guide is SymmetryGuide:
|
||||||
|
continue
|
||||||
var coords = guide.points[0].x
|
var coords = guide.points[0].x
|
||||||
if guide.type == Guide.Types.HORIZONTAL:
|
if guide.type == Guide.Types.HORIZONTAL:
|
||||||
coords = guide.points[0].y
|
coords = guide.points[0].y
|
||||||
|
@ -200,6 +220,7 @@ func serialize() -> Dictionary:
|
||||||
"layers" : layer_data,
|
"layers" : layer_data,
|
||||||
"tags" : tag_data,
|
"tags" : tag_data,
|
||||||
"guides" : guide_data,
|
"guides" : guide_data,
|
||||||
|
"symmetry_points" : [x_symmetry_point, y_symmetry_point],
|
||||||
"frames" : frame_data,
|
"frames" : frame_data,
|
||||||
"brushes" : brush_data,
|
"brushes" : brush_data,
|
||||||
}
|
}
|
||||||
|
@ -250,6 +271,13 @@ func deserialize(dict : Dictionary) -> void:
|
||||||
guide.has_focus = false
|
guide.has_focus = false
|
||||||
Global.canvas.add_child(guide)
|
Global.canvas.add_child(guide)
|
||||||
guides.append(guide)
|
guides.append(guide)
|
||||||
|
if dict.has("symmetry_points"):
|
||||||
|
x_symmetry_point = dict.symmetry_points[0]
|
||||||
|
y_symmetry_point = dict.symmetry_points[1]
|
||||||
|
x_symmetry_axis.points[0].y = floor(y_symmetry_point / 2 + 1)
|
||||||
|
x_symmetry_axis.points[1].y = floor(y_symmetry_point / 2 + 1)
|
||||||
|
y_symmetry_axis.points[0].x = floor(x_symmetry_point / 2 + 1)
|
||||||
|
y_symmetry_axis.points[1].x = floor(x_symmetry_point / 2 + 1)
|
||||||
|
|
||||||
|
|
||||||
func name_changed(value : String) -> void:
|
func name_changed(value : String) -> void:
|
||||||
|
|
|
@ -129,8 +129,8 @@ func fill_in_color(position : Vector2) -> void:
|
||||||
|
|
||||||
func fill_in_area(position : Vector2) -> void:
|
func fill_in_area(position : Vector2) -> void:
|
||||||
var project : Project = Global.current_project
|
var project : Project = Global.current_project
|
||||||
var mirror_x = project.size.x - project.x_symmetry_point - position.x
|
var mirror_x = project.x_symmetry_point - position.x
|
||||||
var mirror_y = project.size.y - project.y_symmetry_point - position.y
|
var mirror_y = project.y_symmetry_point - position.y
|
||||||
var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1
|
var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1
|
||||||
var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1
|
var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1
|
||||||
|
|
||||||
|
|
|
@ -269,8 +269,8 @@ func draw_tool_brush(position : Vector2) -> void:
|
||||||
dst = dst_rect.position
|
dst = dst_rect.position
|
||||||
|
|
||||||
var project : Project = Global.current_project
|
var project : Project = Global.current_project
|
||||||
var mirror_x = project.size.x - (project.x_symmetry_point + 1) - dst.x - src_rect.size.x
|
var mirror_x = (project.x_symmetry_point + 1) - dst.x - src_rect.size.x
|
||||||
var mirror_y = project.size.y - (project.y_symmetry_point + 1) - dst.y - src_rect.size.y
|
var mirror_y = (project.y_symmetry_point + 1) - dst.y - src_rect.size.y
|
||||||
var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1
|
var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1
|
||||||
var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1
|
var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ func draw_tool_brush(position : Vector2) -> void:
|
||||||
_draw_brush_image(_mirror_brushes.x, _flip_rect(src_rect, size, true, false), Vector2(mirror_x, dst.y))
|
_draw_brush_image(_mirror_brushes.x, _flip_rect(src_rect, size, true, false), Vector2(mirror_x, dst.y))
|
||||||
if tool_slot.vertical_mirror and mirror_y_inside:
|
if tool_slot.vertical_mirror and mirror_y_inside:
|
||||||
_draw_brush_image(_mirror_brushes.xy, _flip_rect(src_rect, size, true, true), Vector2(mirror_x, mirror_y))
|
_draw_brush_image(_mirror_brushes.xy, _flip_rect(src_rect, size, true, true), Vector2(mirror_x, mirror_y))
|
||||||
if tool_slot.vertical_mirror and mirror_x_inside:
|
if tool_slot.vertical_mirror and mirror_y_inside:
|
||||||
_draw_brush_image(_mirror_brushes.y, _flip_rect(src_rect, size, false, true), Vector2(dst.x, mirror_y))
|
_draw_brush_image(_mirror_brushes.y, _flip_rect(src_rect, size, false, true), Vector2(dst.x, mirror_y))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,19 +5,21 @@ enum Types {HORIZONTAL, VERTICAL}
|
||||||
var font := preload("res://assets/fonts/Roboto-Regular.tres")
|
var font := preload("res://assets/fonts/Roboto-Regular.tres")
|
||||||
var has_focus := true
|
var has_focus := true
|
||||||
var mouse_pos := Vector2.ZERO
|
var mouse_pos := Vector2.ZERO
|
||||||
var previous_points := points
|
|
||||||
var type = Types.HORIZONTAL
|
var type = Types.HORIZONTAL
|
||||||
|
var project = Global.current_project
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
width = 0.1
|
width = 0.1
|
||||||
default_color = Global.guide_color
|
default_color = Global.guide_color
|
||||||
Global.current_project.guides.append(self)
|
project.guides.append(self)
|
||||||
|
|
||||||
|
|
||||||
func _input(_event : InputEvent):
|
func _input(_event : InputEvent):
|
||||||
width = Global.camera.zoom.x * 2
|
width = Global.camera.zoom.x * 2
|
||||||
mouse_pos = get_local_mouse_position()
|
mouse_pos = get_local_mouse_position()
|
||||||
|
if points.size() < 2:
|
||||||
|
return
|
||||||
var point0 := points[0]
|
var point0 := points[0]
|
||||||
var point1 := points[1]
|
var point1 := points[1]
|
||||||
if type == Types.HORIZONTAL:
|
if type == Types.HORIZONTAL:
|
||||||
|
@ -27,13 +29,11 @@ func _input(_event : InputEvent):
|
||||||
point0.x -= width * 3
|
point0.x -= width * 3
|
||||||
point1.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 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
|
has_focus = true
|
||||||
Global.has_focus = false
|
Global.has_focus = false
|
||||||
update()
|
update()
|
||||||
if has_focus and visible:
|
if has_focus and visible:
|
||||||
if Input.is_action_just_pressed("left_mouse"):
|
|
||||||
previous_points = points
|
|
||||||
if Input.is_action_pressed("left_mouse"):
|
if Input.is_action_pressed("left_mouse"):
|
||||||
if type == Types.HORIZONTAL:
|
if type == Types.HORIZONTAL:
|
||||||
points[0].y = round(mouse_pos.y)
|
points[0].y = round(mouse_pos.y)
|
||||||
|
@ -62,11 +62,11 @@ func _draw() -> void:
|
||||||
|
|
||||||
func outside_canvas() -> bool:
|
func outside_canvas() -> bool:
|
||||||
if type == Types.HORIZONTAL:
|
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()
|
queue_free()
|
||||||
return true
|
return true
|
||||||
else:
|
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()
|
queue_free()
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
25
src/UI/Rulers/SymmetryGuide.gd
Normal file
25
src/UI/Rulers/SymmetryGuide.gd
Normal 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
|
Loading…
Reference in a new issue