1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

The world_2d of the preview viewports is no longer the same as the main viewport's

A "CanvasPreview" Node2D has been added to every preview viewport, where it draws the current frame. This solves #205.
This commit is contained in:
OverloadedOrama 2020-06-12 02:27:21 +03:00
parent 2371238ec0
commit e6aea97f1b
7 changed files with 55 additions and 27 deletions

View file

@ -133,6 +133,7 @@ var canvas : Canvas
var tabs : Tabs
var main_viewport : ViewportContainer
var second_viewport : ViewportContainer
var small_preview_viewport : ViewportContainer
var camera : Camera2D
var camera2 : Camera2D
var camera_preview : Camera2D
@ -251,6 +252,7 @@ func _ready() -> void:
tabs = find_node_by_name(root, "Tabs")
main_viewport = find_node_by_name(root, "ViewportContainer")
second_viewport = find_node_by_name(root, "ViewportContainer2")
small_preview_viewport = find_node_by_name(root, "PreviewViewportContainer")
camera = find_node_by_name(main_viewport, "Camera2D")
camera2 = find_node_by_name(root, "Camera2D2")
camera_preview = find_node_by_name(root, "CameraPreview")

View file

@ -27,6 +27,8 @@ func _ready() -> void:
func _draw() -> void:
Global.second_viewport.get_child(0).get_node("CanvasPreview").update()
Global.small_preview_viewport.get_child(0).get_node("CanvasPreview").update()
var current_cels : Array = Global.current_project.frames[Global.current_project.current_frame].cels
var size : Vector2 = Global.current_project.size
if Global.onion_skinning:

13
src/UI/CanvasPreview.gd Normal file
View file

@ -0,0 +1,13 @@
extends Node2D
func _draw() -> void:
var current_project : Project = Global.current_project
var frame : int = current_project.current_frame
var current_cels : Array = current_project.frames[frame].cels
# Draw current frame layers
for i in range(current_cels.size()):
var modulate_color := Color(1, 1, 1, current_cels[i].opacity)
if current_project.layers[i].visible: # if it's visible
draw_texture(current_cels[i].image_texture, Vector2.ZERO, modulate_color)

View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UI/CanvasPreview.gd" type="Script" id=1]
[node name="CanvasPreview" type="Node2D"]
script = ExtResource( 1 )

View file

@ -1,6 +0,0 @@
extends Viewport
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
world_2d = Global.canvas.get_parent().world_2d

View file

@ -0,0 +1,17 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://src/Shaders/TransparentChecker.shader" type="Shader" id=1]
[ext_resource path="res://src/UI/TransparentChecker.gd" type="Script" id=2]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 1 )
shader_param/size = 10.0
shader_param/color1 = Color( 0.7, 0.7, 0.7, 1 )
shader_param/color2 = Color( 1, 1, 1, 1 )
[node name="TransparentChecker" type="ColorRect"]
material = SubResource( 1 )
margin_right = 40.0
margin_bottom = 40.0
mouse_filter = 2
script = ExtResource( 2 )

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=25 format=2]
[gd_scene load_steps=23 format=2]
[ext_resource path="res://src/UI/ToolButtons.gd" type="Script" id=1]
[ext_resource path="res://src/UI/SecondViewport.gd" type="Script" id=2]
[ext_resource path="res://src/UI/CanvasPreview.tscn" type="PackedScene" id=2]
[ext_resource path="res://src/UI/Tabs.gd" type="Script" id=3]
[ext_resource path="res://src/UI/Rulers/VerticalRuler.gd" type="Script" id=4]
[ext_resource path="res://src/UI/TransparentChecker.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/UI/Rulers/HorizontalRuler.gd" type="Script" id=6]
[ext_resource path="res://src/CameraMovement.gd" type="Script" id=7]
[ext_resource path="res://src/SelectionRectangle.gd" type="Script" id=8]
@ -14,21 +15,13 @@
[ext_resource path="res://assets/graphics/dark_themes/tools/eraser_r.png" type="Texture" id=13]
[ext_resource path="res://assets/graphics/dark_themes/tools/pencil_l.png" type="Texture" id=14]
[ext_resource path="res://assets/graphics/dark_themes/tools/lightendarken.png" type="Texture" id=15]
[ext_resource path="res://src/Shaders/TransparentChecker.shader" type="Shader" id=16]
[ext_resource path="res://src/UI/ColorAndToolOptions.tscn" type="PackedScene" id=17]
[ext_resource path="res://src/UI/Timeline/AnimationTimeline.tscn" type="PackedScene" id=18]
[ext_resource path="res://src/Canvas.tscn" type="PackedScene" id=19]
[ext_resource path="res://src/Palette/PalettePanelContainer.tscn" type="PackedScene" id=20]
[ext_resource path="res://assets/graphics/dark_themes/tools/zoom.png" type="Texture" id=21]
[ext_resource path="res://src/UI/TransparentChecker.gd" type="Script" id=22]
[ext_resource path="res://src/UI/ViewportContainer.gd" type="Script" id=23]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 16 )
shader_param/size = 10.0
shader_param/color1 = Color( 0.7, 0.7, 0.7, 1 )
shader_param/color2 = Color( 1, 1, 1, 1 )
[sub_resource type="StyleBoxFlat" id=2]
bg_color = Color( 0.0627451, 0.0627451, 0.0627451, 1 )
expand_margin_top = 6.0
@ -284,12 +277,7 @@ handle_input_locally = false
usage = 0
render_target_update_mode = 3
[node name="TransparentChecker" type="ColorRect" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportandVerticalRuler/ViewportContainer/Viewport"]
material = SubResource( 1 )
margin_right = 40.0
margin_bottom = 40.0
mouse_filter = 2
script = ExtResource( 22 )
[node name="TransparentChecker" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportandVerticalRuler/ViewportContainer/Viewport" instance=ExtResource( 5 )]
[node name="Canvas" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportandVerticalRuler/ViewportContainer/Viewport" instance=ExtResource( 19 )]
@ -319,7 +307,10 @@ script = ExtResource( 23 )
size = Vector2( 0, 426 )
handle_input_locally = false
render_target_update_mode = 3
script = ExtResource( 2 )
[node name="TransparentChecker" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportContainer2/Viewport" instance=ExtResource( 5 )]
[node name="CanvasPreview" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportContainer2/Viewport" instance=ExtResource( 2 )]
[node name="Camera2D2" type="Camera2D" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportContainer2/Viewport"]
current = true
@ -353,21 +344,24 @@ margin_right = 322.0
margin_bottom = 164.0
size_flags_horizontal = 4
[node name="CanvasPreview" type="ViewportContainer" parent="RightPanel/PreviewAndPalettes/PanelContainer"]
[node name="PreviewViewportContainer" type="ViewportContainer" parent="RightPanel/PreviewAndPalettes/PanelContainer"]
margin_left = 7.0
margin_top = 7.0
margin_right = 307.0
margin_bottom = 157.0
rect_min_size = Vector2( 0, 150 )
[node name="Viewport" type="Viewport" parent="RightPanel/PreviewAndPalettes/PanelContainer/CanvasPreview"]
[node name="Viewport" type="Viewport" parent="RightPanel/PreviewAndPalettes/PanelContainer/PreviewViewportContainer"]
size = Vector2( 300, 150 )
transparent_bg = true
handle_input_locally = false
render_target_update_mode = 3
script = ExtResource( 2 )
[node name="CameraPreview" type="Camera2D" parent="RightPanel/PreviewAndPalettes/PanelContainer/CanvasPreview/Viewport"]
[node name="TransparentChecker" parent="RightPanel/PreviewAndPalettes/PanelContainer/PreviewViewportContainer/Viewport" instance=ExtResource( 5 )]
[node name="CanvasPreview" parent="RightPanel/PreviewAndPalettes/PanelContainer/PreviewViewportContainer/Viewport" instance=ExtResource( 2 )]
[node name="CameraPreview" type="Camera2D" parent="RightPanel/PreviewAndPalettes/PanelContainer/PreviewViewportContainer/Viewport"]
offset = Vector2( 32, 32 )
current = true
zoom = Vector2( 0.15, 0.15 )