Fill transform is now functional.
This commit is contained in:
parent
221f4547aa
commit
3fc488996f
|
@ -17,5 +17,3 @@ margin_left = 12.0
|
|||
margin_top = 12.0
|
||||
margin_right = -12.0
|
||||
margin_bottom = -12.0
|
||||
|
||||
[connection signal="resized" from="Canvas" to="Canvas" method="_on_Canvas_resized"]
|
||||
|
|
|
@ -16,8 +16,8 @@ var view_transform := Transform2D.IDENTITY # fill_transform * canvas_transform
|
|||
|
||||
|
||||
func _ready():
|
||||
#connect("resized", self, "_size_changed")
|
||||
pass
|
||||
connect("view_transform_changed",
|
||||
$BackgroundLayer/EmptyCanvasLayer, "_on_view_transform_changed")
|
||||
|
||||
|
||||
func _gui_input(event):
|
||||
|
@ -30,13 +30,18 @@ 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")
|
||||
scene.connect("aspect_ratio_changed",
|
||||
self, "_on_scene_aspect_ratio_changed")
|
||||
$Label.text = str(scene) + "\n" + str(scene.aspect_ratio)
|
||||
|
||||
|
||||
func _on_Canvas_resized():
|
||||
_update_fill_transform()
|
||||
range(-1, 1, 2)
|
||||
|
||||
|
||||
func _on_scene_aspect_ratio_changed(new_aspect_ratio):
|
||||
$BackgroundLayer/EmptyCanvasLayer._update_size(new_aspect_ratio)
|
||||
_update_fill_transform()
|
||||
|
||||
|
||||
func _update_fill_transform():
|
||||
|
@ -51,13 +56,22 @@ func _update_fill_transform():
|
|||
var translation = Vector2.ZERO
|
||||
if aspect_ratio <= size_ratio:
|
||||
scale = rect_size.y
|
||||
print(rect_size.y)
|
||||
translation.x = rect_size.x * 0.5 - aspect_ratio * scale * 0.5
|
||||
print(rect_size.x * 0.5)
|
||||
print(aspect_ratio * scale * 0.5)
|
||||
print(translation)
|
||||
else:
|
||||
scale = rect_size.x / aspect_ratio
|
||||
translation.y = rect_size.y * 0.5 - scale * 0.5
|
||||
|
||||
fill_transform = Transform2D.IDENTITY.scaled(Vector2(scale, scale))
|
||||
fill_transform = fill_transform.translated(translation)
|
||||
fill_transform = Transform2D(
|
||||
Vector2(scale, 0.0),
|
||||
Vector2(0.0, scale),
|
||||
translation
|
||||
)
|
||||
print(fill_transform)
|
||||
emit_signal("fill_transform_changed", fill_transform)
|
||||
|
||||
|
@ -65,20 +79,3 @@ 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
|
||||
|
|
|
@ -2,26 +2,7 @@
|
|||
|
||||
[ext_resource path="res://addons/summer_day/tool/canvas/canvas.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Main.tscn" type="PackedScene" id=2]
|
||||
|
||||
[sub_resource type="GDScript" id=4]
|
||||
script/source = "tool
|
||||
extends Polygon2D
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = \"text\"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
"
|
||||
[ext_resource path="res://addons/summer_day/tool/canvas/empty_canvas_layer.gd" type="Script" id=3]
|
||||
|
||||
[sub_resource type="Environment" id=1]
|
||||
ambient_light_color = Color( 1, 1, 1, 1 )
|
||||
|
@ -61,10 +42,8 @@ handle_input_locally = false
|
|||
usage = 0
|
||||
render_target_update_mode = 3
|
||||
|
||||
[node name="CanvasLayer" type="Polygon2D" parent="BackgroundLayer"]
|
||||
scale = Vector2( 55, 55 )
|
||||
polygon = PoolVector2Array( -0.8, -0.8, 0.8, -0.8, 0.8, 0.8, -0.8, 0.8 )
|
||||
script = SubResource( 4 )
|
||||
[node name="EmptyCanvasLayer" type="Polygon2D" parent="BackgroundLayer"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="RenderLayer" type="Viewport" parent="."]
|
||||
size = Vector2( 1024, 600 )
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
tool
|
||||
extends Polygon2D
|
||||
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
|
||||
func _update_size(new_aspect_ratio):
|
||||
print("We got here")
|
||||
var calculated_aspect_ratio = new_aspect_ratio.x / new_aspect_ratio.y
|
||||
polygon = PoolVector2Array(
|
||||
[
|
||||
Vector2.ZERO,
|
||||
Vector2(calculated_aspect_ratio, 0.0),
|
||||
Vector2(calculated_aspect_ratio, 1.0),
|
||||
Vector2(0.0, 1.0)
|
||||
]
|
||||
)
|
||||
|
||||
func _on_view_transform_changed(new_view_transform):
|
||||
transform = new_view_transform
|
Loading…
Reference in New Issue