85 lines
2.1 KiB
GDScript
85 lines
2.1 KiB
GDScript
tool
|
|
extends Control
|
|
class_name SummerDayCanvas
|
|
|
|
|
|
signal fill_transform_changed(fill_transform)
|
|
signal canvas_transform_changed(canvas_transform)
|
|
signal view_transform_changed(view_transform)
|
|
|
|
|
|
var scene: SummerDayScene
|
|
|
|
var fill_transform := Transform2D.IDENTITY
|
|
var canvas_transform := Transform2D.IDENTITY
|
|
var view_transform := Transform2D.IDENTITY # fill_transform * canvas_transform
|
|
|
|
|
|
func _ready():
|
|
#connect("resized", self, "_size_changed")
|
|
pass
|
|
|
|
|
|
func _gui_input(event):
|
|
if event is InputEventMagnifyGesture:
|
|
print(event.factor)
|
|
if event is InputEventMouseButton:
|
|
print(event.pressed)
|
|
|
|
|
|
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)
|
|
|
|
|
|
func _on_Canvas_resized():
|
|
_update_fill_transform()
|
|
range(-1, 1, 2)
|
|
|
|
|
|
func _update_fill_transform():
|
|
if scene == null:
|
|
fill_transform = Transform2D.IDENTITY
|
|
else:
|
|
var aspect_ratio = scene.aspect_ratio.x / scene.aspect_ratio.y
|
|
|
|
var size_ratio = rect_size.x / rect_size.y
|
|
|
|
var scale
|
|
var translation = Vector2.ZERO
|
|
if aspect_ratio <= size_ratio:
|
|
scale = rect_size.y
|
|
translation.x = rect_size.x * 0.5 - aspect_ratio * scale * 0.5
|
|
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)
|
|
print(fill_transform)
|
|
emit_signal("fill_transform_changed", 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
|