Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the Perspective editor #806

Merged
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
53b2b82
Added Perspective Editor
Variable-ind Jan 6, 2023
c2d626b
removed unintended changes
Variable-ind Jan 6, 2023
38e9628
Removed unintended changes
Variable-ind Jan 6, 2023
9286f06
removed un-intended changes
Variable-ind Jan 6, 2023
6ad4d64
Delete Axes.tscn
Variable-ind Jan 6, 2023
1d0fcfc
Delete Axis.gd
Variable-ind Jan 6, 2023
4575264
Removed MouseGuides from editor
Variable-ind Jan 6, 2023
6bfbfd7
Added MouseGuides
Variable-ind Jan 6, 2023
fffd7be
Some changes
Variable-ind Jan 6, 2023
c31b886
Fixed some things
Variable-ind Jan 6, 2023
c36422b
added mouse guide
Variable-ind Jan 6, 2023
91cc349
make MouseGuides remember last setting
Variable-ind Jan 6, 2023
2f3bdbf
don't move if dialog is open
Variable-ind Jan 6, 2023
7e8be03
Dont move tracker guides if dialog is open
Variable-ind Jan 6, 2023
26aaca7
UI improvement to editor
Variable-ind Jan 6, 2023
6f0363b
Update VanishingPoint.gd
Variable-ind Jan 6, 2023
45a64a3
UI Improvement
Variable-ind Jan 6, 2023
51fac63
Minor Color Improvements
Variable-ind Jan 6, 2023
66787bf
fixed a bug
Variable-ind Jan 6, 2023
eeb9e97
Some UI Changes
Variable-ind Jan 6, 2023
6c953ca
Improve UI some more
Variable-ind Jan 6, 2023
52266d4
fix typo
Variable-ind Jan 6, 2023
c225e5f
Added Undo/Redo and improved UI
Variable-ind Jan 6, 2023
c503684
Formatting
Variable-ind Jan 6, 2023
06e330f
formatting
Variable-ind Jan 6, 2023
f47e7f0
formatting
Variable-ind Jan 6, 2023
605a2f7
formatting
Variable-ind Jan 6, 2023
11f7ee3
Fix Definition out of order
Variable-ind Jan 6, 2023
34a3bf0
Fix Definition out of order
Variable-ind Jan 6, 2023
c31815c
formatting
Variable-ind Jan 6, 2023
254f7d7
formatting
Variable-ind Jan 6, 2023
29c4dfc
fix Duplicate error
Variable-ind Jan 6, 2023
b7c23c9
Fix some things
Variable-ind Jan 6, 2023
f5773ae
Some UI Changes
Variable-ind Jan 6, 2023
ee888c9
Some code refinement
Variable-ind Jan 6, 2023
0b31c22
Removed un-needed lines
Variable-ind Jan 6, 2023
fadfded
Some code refinement
Variable-ind Jan 6, 2023
427a93d
Some more UI Changes
Variable-ind Jan 6, 2023
f00d0bd
Changes, Changes and Changes
Variable-ind Jan 6, 2023
f6793aa
Delete LineButton.gd
Variable-ind Jan 7, 2023
1072113
Delete LineButton.tscn
Variable-ind Jan 7, 2023
9b2dc6c
Delete PerspectiveEditor.gd
Variable-ind Jan 7, 2023
38f7465
Delete PerspectiveEditor.tscn
Variable-ind Jan 7, 2023
e706917
Delete PointCollapseContainer.gd
Variable-ind Jan 7, 2023
337ec62
Delete PerspectiveLine.tscn
Variable-ind Jan 7, 2023
9460b0c
Delete PerspectiveLine.gd
Variable-ind Jan 7, 2023
b4083f6
Changed boundary separators to ColorRects
Variable-ind Jan 7, 2023
135c456
make the guide update more frequently
Variable-ind Jan 7, 2023
808af18
make default color have full alpha
Variable-ind Jan 7, 2023
f6ebbc5
Dim the boundaries based on luminance
Variable-ind Jan 7, 2023
0d6cadb
typo
Variable-ind Jan 7, 2023
f6aa133
Formatting
Variable-ind Jan 8, 2023
ff53d54
Formatting
Variable-ind Jan 8, 2023
97513ba
formatting i forgot to do
Variable-ind Jan 8, 2023
9fa72cc
Merge branch 'Orama-Interactive:master' into Perspective-Editor
Variable-ind Jan 14, 2023
253f124
Merge branch 'Orama-Interactive:master' into Perspective-Editor
Variable-ind Jan 17, 2023
d5ed7a5
Delete VanishingPoint.gd
Variable-ind Jan 17, 2023
391aaf9
Delete VanishingPoint.tscn
Variable-ind Jan 17, 2023
e3c6392
Merge branch 'Orama-Interactive:master' into Perspective-Editor
Variable-ind Jan 20, 2023
6af9bb0
Merge branch 'master' into Perspective-Editor
OverloadedOrama Feb 2, 2023
70d613a
Merge branch 'Orama-Interactive:master' into Perspective-Editor
Variable-ind Feb 5, 2023
494a9f1
Merge branch 'Orama-Interactive:master' into Perspective-Editor
Variable-ind Feb 12, 2023
41f038e
Fixed rouge collapsible container
Variable-ind Feb 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://src/UI/Buttons/PatternsPopup.gd"
}, {
"base": "Line2D",
"class": "PerspectiveLine",
"language": "GDScript",
"path": "res://src/UI/PerspectiveEditor/PerspectiveLine.gd"
}, {
"base": "BaseCel",
"class": "PixelCel",
"language": "GDScript",
Expand Down Expand Up @@ -250,6 +255,7 @@ _global_script_class_icons={
"PalettePanel": "",
"PaletteSwatch": "",
"Patterns": "",
"PerspectiveLine": "",
"PixelCel": "",
"PixelLayer": "",
"Project": "",
Expand Down
3 changes: 3 additions & 0 deletions src/Autoload/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum ViewMenu {
SHOW_PIXEL_GRID,
SHOW_RULERS,
SHOW_GUIDES,
SHOW_MOUSE_GUIDES,
SNAP_TO,
}
enum WindowMenu { WINDOW_OPACITY, PANELS, LAYOUTS, MOVABLE_PANELS, ZEN_MODE, FULLSCREEN_MODE }
Expand Down Expand Up @@ -138,6 +139,7 @@ var draw_grid := false
var draw_pixel_grid := false
var show_rulers := true
var show_guides := true
var show_mouse_guides := false
var snapping_distance := 10.0
var snap_to_rectangular_grid := false
var snap_to_guides := false
Expand Down Expand Up @@ -181,6 +183,7 @@ onready var patterns_popup: Popup = control.find_node("PatternsPopup")
onready var palette_panel: PalettePanel = control.find_node("Palettes")

onready var references_panel: ReferencesPanel = control.find_node("Reference Images")
onready var perspective_editor := control.find_node("Perspective Editor")

onready var top_menu_container: Panel = control.find_node("TopMenuContainer")
onready var rotation_level_button: Button = control.find_node("RotationLevel")
Expand Down
12 changes: 12 additions & 0 deletions src/Classes/Project.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var animation_tags := [] setget _animation_tags_changed # Array of AnimationTag
var guides := [] # Array of Guides
var brushes := [] # Array of Images
var reference_images := [] # Array of ReferenceImages
var vanishing_points := [] # Array of Vanishing Points
var fps := 6.0

var x_symmetry_point
Expand Down Expand Up @@ -91,6 +92,12 @@ func remove() -> void:
undo_redo.free()
for ri in reference_images:
ri.queue_free()
if self == Global.current_project:
# If the project is not current_project then the points need not be removed
for point_idx in vanishing_points.size():
var editor = Global.perspective_editor
for c in editor.vanishing_point_container.get_children():
c.queue_free()
for guide in guides:
guide.queue_free()
# Prevents memory leak (due to the layers' project reference stopping ref counting from freeing)
Expand Down Expand Up @@ -186,6 +193,7 @@ func change_project() -> void:
Global.horizontal_ruler.update()
Global.vertical_ruler.update()
Global.references_panel.project_changed()
Global.perspective_editor.update()
Global.cursor_position_label.text = "[%s×%s]" % [size.x, size.y]

Global.window_title = "%s - Pixelorama %s" % [name, Global.current_version]
Expand Down Expand Up @@ -325,6 +333,7 @@ func serialize() -> Dictionary:
"frames": frame_data,
"brushes": brush_data,
"reference_images": reference_image_data,
"vanishing_points": vanishing_points,
"export_directory_path": directory_path,
"export_file_name": file_name,
"export_file_format": file_format,
Expand Down Expand Up @@ -412,6 +421,9 @@ func deserialize(dict: Dictionary) -> void:
ri.project = self
ri.deserialize(g)
Global.canvas.add_child(ri)
if dict.has("vanishing_points"):
vanishing_points = dict.vanishing_points
Global.perspective_editor.update()
if dict.has("symmetry_points"):
x_symmetry_point = dict.symmetry_points[0]
y_symmetry_point = dict.symmetry_points[1]
Expand Down
1 change: 1 addition & 0 deletions src/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ func _exit_tree() -> void:
Global.config_cache.set_value("view_menu", "draw_pixel_grid", Global.draw_pixel_grid)
Global.config_cache.set_value("view_menu", "show_rulers", Global.show_rulers)
Global.config_cache.set_value("view_menu", "show_guides", Global.show_guides)
Global.config_cache.set_value("view_menu", "show_mouse_guides", Global.show_mouse_guides)
Global.config_cache.save("user://cache.ini")

var i := 0
Expand Down
1 change: 1 addition & 0 deletions src/UI/Canvas/Canvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ onready var grid = $Grid
onready var selection = $Selection
onready var indicators = $Indicators
onready var previews = $Previews
onready var mouse_guide_container = $MouseGuideContainer


func _ready() -> void:
Expand Down
5 changes: 4 additions & 1 deletion src/UI/Canvas/Canvas.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=2]
[gd_scene load_steps=16 format=2]

[ext_resource path="res://src/UI/Canvas/Canvas.gd" type="Script" id=1]
[ext_resource path="res://src/UI/Canvas/Grid.gd" type="Script" id=2]
Expand All @@ -10,6 +10,7 @@
[ext_resource path="res://src/UI/Canvas/Selection.gd" type="Script" id=8]
[ext_resource path="res://src/Shaders/MarchingAntsOutline.shader" type="Shader" id=9]
[ext_resource path="res://src/Shaders/AutoInvertColors.shader" type="Shader" id=10]
[ext_resource path="res://src/UI/Canvas/MouseGuideContainer.tscn" type="PackedScene" id=11]
[ext_resource path="res://src/UI/Canvas/OnionSkinning.gd" type="Script" id=12]

[sub_resource type="CanvasItemMaterial" id=1]
Expand Down Expand Up @@ -72,3 +73,5 @@ script = ExtResource( 12 )

[node name="OnionFuture" type="Node2D" parent="."]
script = ExtResource( 12 )

[node name="MouseGuideContainer" parent="." instance=ExtResource( 11 )]
77 changes: 77 additions & 0 deletions src/UI/Canvas/MouseGuide.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
extends Line2D

enum Types { VERTICAL, HORIZONTAL }
const INPUT_WIDTH := 4
export var type := 0
var track_mouse := true


func _ready() -> void:
# Add a subtle difference to the normal guide color by mixing in some green
default_color = Global.guide_color.linear_interpolate(Color(0.2, 0.92, 0.2), .6)
width = Global.camera.zoom.x * 2
draw_guide_line()


func draw_guide_line():
if type == Types.HORIZONTAL:
points[0] = Vector2(-19999, 0)
points[1] = Vector2(19999, 0)
else:
points[0] = Vector2(0, 19999)
points[1] = Vector2(0, -19999)


func _input(event: InputEvent) -> void:
if !Global.show_mouse_guides or !Global.can_draw or !Global.has_focus:
visible = false
return
visible = true
if event is InputEventMouseMotion:
var tmp_transform = get_canvas_transform().affine_inverse()
var tmp_position = Global.main_viewport.get_local_mouse_position()
var mouse_point = (tmp_transform.basis_xform(tmp_position) + tmp_transform.origin).snapped(
Vector2(0.5, 0.5)
)

var project_size = Global.current_project.size
if Rect2(Vector2.ZERO, project_size).has_point(mouse_point):
visible = true
else:
visible = false
return
if type == Types.HORIZONTAL:
points[0].y = mouse_point.y
points[1].y = mouse_point.y
else:
points[0].x = mouse_point.x
points[1].x = mouse_point.x
update()


func _draw() -> void:
width = Global.camera.zoom.x * 2
var viewport_size: Vector2 = Global.main_viewport.rect_size
var zoom: Vector2 = Global.camera.zoom

# viewport_poly is an array of the points that make up the corners of the viewport
var viewport_poly := [
Vector2.ZERO, Vector2(viewport_size.x, 0), viewport_size, Vector2(0, viewport_size.y)
]
# Adjusting viewport_poly to take into account the camera offset, zoom, and rotation
for p in range(viewport_poly.size()):
viewport_poly[p] = (
viewport_poly[p].rotated(Global.camera.rotation) * zoom
+ Vector2(
(
Global.camera.offset.x
- (viewport_size.rotated(Global.camera.rotation).x / 2) * zoom.x
),
(
Global.camera.offset.y
- (viewport_size.rotated(Global.camera.rotation).y / 2) * zoom.y
)
)
)

draw_set_transform(viewport_poly[0], Global.camera.rotation, zoom * 2)
31 changes: 31 additions & 0 deletions src/UI/Canvas/MouseGuideContainer.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://assets/graphics/dotted_line.png" type="Texture" id=1]
[ext_resource path="res://src/UI/Canvas/MouseGuide.gd" type="Script" id=2]

[sub_resource type="AtlasTexture" id=1]
flags = 2
atlas = ExtResource( 1 )
region = Rect2( 0, 0, 8, 1 )

[node name="MouseGuideContainer" type="Node2D"]

[node name="Vertical" type="Line2D" parent="."]
visible = false
points = PoolVector2Array( 0, 19999, 0, -19999 )
default_color = Color( 1, 1, 1, 1 )
texture = SubResource( 1 )
texture_mode = 1
script = ExtResource( 2 )

[node name="Horizontal" type="Line2D" parent="."]
visible = false
points = PoolVector2Array( -19999, 0, 19999, 0 )
default_color = Color( 1, 1, 1, 1 )
texture = SubResource( 1 )
texture_mode = 1
script = ExtResource( 2 )
__meta__ = {
"_editor_description_": ""
}
type = 1
9 changes: 9 additions & 0 deletions src/UI/PerspectiveEditor/LineButton.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends Button

onready var length_slider = $"%LengthSlider"


func _ready():
var p_size = Global.current_project.size
var suitable_length = sqrt(pow(p_size.x, 2) + pow(p_size.y, 2))
length_slider.max_value = suitable_length
89 changes: 89 additions & 0 deletions src/UI/PerspectiveEditor/LineButton.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://src/UI/Nodes/ValueSlider.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/graphics/misc/value_arrow.svg" type="Texture" id=2]
[ext_resource path="res://src/UI/Nodes/CollapsibleContainer.gd" type="Script" id=3]
[ext_resource path="res://src/UI/PerspectiveEditor/LineButton.gd" type="Script" id=4]

[node name="LineButton" type="VBoxContainer"]
margin_right = 159.0
margin_bottom = 20.0
script = ExtResource( 3 )

[node name="Button" type="Button" parent="."]
margin_right = 159.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
theme_type_variation = "CollapsibleCheckBox"
toggle_mode = true
script = ExtResource( 4 )

[node name="TextureRect" type="TextureRect" parent="Button" groups=["UIButtons"]]
anchor_top = 0.5
anchor_bottom = 0.5
margin_left = 2.0
margin_top = -6.0
margin_right = 14.0
margin_bottom = 6.0
rect_rotation = -90.0
rect_pivot_offset = Vector2( 6, 6 )
texture = ExtResource( 2 )

[node name="Label" type="Label" parent="Button"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 14.0
valign = 1

[node name="HBoxContainer" type="HBoxContainer" parent="."]
visible = false
margin_top = 24.0
margin_right = 159.0
margin_bottom = 76.0

[node name="Spacer" type="Control" parent="HBoxContainer"]
margin_right = 20.0
margin_bottom = 52.0
rect_min_size = Vector2( 20, 0 )

[node name="VSeparator" type="VSeparator" parent="HBoxContainer"]
margin_left = 24.0
margin_right = 28.0
margin_bottom = 52.0

[node name="Properties" type="VBoxContainer" parent="HBoxContainer"]
margin_left = 32.0
margin_right = 83.0
margin_bottom = 52.0
size_flags_horizontal = 3

[node name="AngleSlider" parent="HBoxContainer/Properties" instance=ExtResource( 1 )]
margin_right = 51.0
max_value = 359.999
step = 0.001
prefix = "Angle:"
suffix = "°"

[node name="LengthSlider" parent="HBoxContainer/Properties" instance=ExtResource( 1 )]
unique_name_in_owner = true
margin_top = 28.0
margin_right = 51.0
margin_bottom = 52.0
max_value = 19999.0
value = 19999.0
allow_greater = true
prefix = "Length:"
suffix = "px"

[node name="Delete" type="Button" parent="HBoxContainer"]
margin_left = 87.0
margin_right = 151.0
margin_bottom = 52.0
text = "Remove"

[node name="VSeparator2" type="VSeparator" parent="HBoxContainer"]
margin_left = 155.0
margin_right = 159.0
margin_bottom = 52.0

[connection signal="toggled" from="Button" to="." method="_on_Button_toggled"]
Loading