From 221f4547aaa5353406445fbb10f82138b0302f9d Mon Sep 17 00:00:00 2001 From: Mono Date: Fri, 19 Nov 2021 11:10:04 +0100 Subject: [PATCH] Added canvas background layer creation functionality. --- Main.tscn | 19 +++++++++++++++++-- addons/summer_day/tool/canvas/canvas.gd | 18 ++++++++++++++++++ project.godot | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Main.tscn b/Main.tscn index 790554e..3267a7a 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=2] +[gd_scene load_steps=19 format=2] [ext_resource path="res://TryingOutSomethingNew.gd" type="Script" id=1] [ext_resource path="res://Node2D.gd" type="Script" id=2] @@ -107,9 +107,24 @@ void fragment() { ALBEDO = texture(table, UV).rgb; }" +[sub_resource type="Image" id=18] +data = { +"data": PoolByteArray( 0, 0, 128, 62, 0, 0, 0, 0, 0, 0, 0, 0, 154, 153, 25, 62, 0, 0, 0, 0, 0, 0, 128, 62, 0, 0, 0, 0, 154, 153, 25, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 128, 62, 0, 0, 0, 0, 0, 0, 0, 0, 154, 153, 25, 190, 0, 0, 0, 0, 0, 0, 128, 62, 0, 0, 0, 0, 154, 153, 25, 190, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63 ), +"format": "RGBAFloat", +"height": 1, +"mipmaps": false, +"width": 8 +} + +[sub_resource type="ImageTexture" id=19] +flags = 0 +flags = 0 +image = SubResource( 18 ) +size = Vector2( 8, 1 ) + [sub_resource type="ShaderMaterial" id=7] shader = SubResource( 6 ) -shader_param/table = SubResource( 16 ) +shader_param/table = SubResource( 19 ) [sub_resource type="QuadMesh" id=8] diff --git a/addons/summer_day/tool/canvas/canvas.gd b/addons/summer_day/tool/canvas/canvas.gd index 8b96353..bb174e3 100644 --- a/addons/summer_day/tool/canvas/canvas.gd +++ b/addons/summer_day/tool/canvas/canvas.gd @@ -30,6 +30,7 @@ func _gui_input(event): func _on_SummerDay_scene_changed(new_scene): scene = new_scene _update_fill_transform() + scene.connect("aspect_ratio_changed", self, "_update_CanvasLayer") $Label.text = str(scene) + "\n" + str(scene.aspect_ratio) @@ -64,3 +65,20 @@ func _update_fill_transform(): func _update_view_transformation(transform): view_transform = fill_transform * canvas_transform emit_signal("view_transform_changed", view_transform) + + +func _update_CanvasLayer(new_aspect_ratio): + var new_polygon + if scene == null: + new_polygon = PoolVector2Array() + else: + new_polygon = PoolVector2Array( + [ + Vector2.ZERO, + Vector2(scene.internal_width, 0.0), + Vector2(scene.internal_width, scene.internal_height), + Vector2(0.0, scene.internal_height) + ] + ) + + $BackgroundLayer/CanvasLayer.polygon = new_polygon diff --git a/project.godot b/project.godot index a124fa9..8b19113 100644 --- a/project.godot +++ b/project.godot @@ -87,7 +87,7 @@ _global_script_class_icons={ [application] config/name="CGMationSomeday" -run/main_scene="res://Main.tscn" +run/main_scene="res://addons/summer_day/main_screen.tscn" config/icon="res://icon.png" [autoload]