Seperated canvas and canvas_state for better tool implementation.
This commit is contained in:
parent
3fc488996f
commit
9814051fc4
|
@ -4,4 +4,4 @@
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
aspect_ratio = Vector2( 16, 9 )
|
aspect_ratio = Vector2( 20.169, 14.308 )
|
||||||
|
|
|
@ -2,21 +2,12 @@ tool
|
||||||
extends Control
|
extends Control
|
||||||
class_name SummerDayCanvas
|
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 scene: SummerDayScene
|
||||||
|
var canvas_state := SummerDayCanvasState.new()
|
||||||
var fill_transform := Transform2D.IDENTITY
|
|
||||||
var canvas_transform := Transform2D.IDENTITY
|
|
||||||
var view_transform := Transform2D.IDENTITY # fill_transform * canvas_transform
|
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
connect("view_transform_changed",
|
canvas_state.connect("view_transform_changed",
|
||||||
$BackgroundLayer/EmptyCanvasLayer, "_on_view_transform_changed")
|
$BackgroundLayer/EmptyCanvasLayer, "_on_view_transform_changed")
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,53 +20,17 @@ func _gui_input(event):
|
||||||
|
|
||||||
func _on_SummerDay_scene_changed(new_scene):
|
func _on_SummerDay_scene_changed(new_scene):
|
||||||
scene = new_scene
|
scene = new_scene
|
||||||
_update_fill_transform()
|
canvas_state.update_fill_transform(scene)
|
||||||
scene.connect("aspect_ratio_changed",
|
scene.connect("aspect_ratio_changed",
|
||||||
self, "_on_scene_aspect_ratio_changed")
|
self, "_on_scene_aspect_ratio_changed")
|
||||||
$Label.text = str(scene) + "\n" + str(scene.aspect_ratio)
|
$Label.text = str(scene) + "\n" + str(scene.aspect_ratio)
|
||||||
|
|
||||||
|
|
||||||
func _on_Canvas_resized():
|
func _on_Canvas_resized():
|
||||||
_update_fill_transform()
|
canvas_state.rect_size = rect_size
|
||||||
|
canvas_state.update_fill_transform(scene)
|
||||||
|
|
||||||
|
|
||||||
func _on_scene_aspect_ratio_changed(new_aspect_ratio):
|
func _on_scene_aspect_ratio_changed(new_aspect_ratio):
|
||||||
$BackgroundLayer/EmptyCanvasLayer._update_size(new_aspect_ratio)
|
$BackgroundLayer/EmptyCanvasLayer.update_size(scene)
|
||||||
_update_fill_transform()
|
canvas_state.update_fill_transform(scene)
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
func _update_view_transformation(transform):
|
|
||||||
view_transform = fill_transform * canvas_transform
|
|
||||||
emit_signal("view_transform_changed", view_transform)
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[ext_resource path="res://addons/summer_day/tool/canvas/canvas.gd" type="Script" id=1]
|
[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]
|
[ext_resource path="res://Main.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://addons/summer_day/tool/canvas/empty_canvas_layer.gd" type="Script" id=3]
|
[ext_resource path="res://addons/summer_day/tool/canvas/rendering/empty_canvas_layer.gd" type="Script" id=3]
|
||||||
|
|
||||||
[sub_resource type="Environment" id=1]
|
[sub_resource type="Environment" id=1]
|
||||||
ambient_light_color = Color( 1, 1, 1, 1 )
|
ambient_light_color = Color( 1, 1, 1, 1 )
|
||||||
|
@ -74,6 +74,4 @@ script = SubResource( 3 )
|
||||||
margin_right = 40.0
|
margin_right = 40.0
|
||||||
margin_bottom = 14.0
|
margin_bottom = 14.0
|
||||||
|
|
||||||
[connection signal="canvas_transform_changed" from="." to="." method="_update_view_transformation"]
|
|
||||||
[connection signal="fill_transform_changed" from="." to="." method="_update_view_transformation"]
|
|
||||||
[connection signal="resized" from="." to="." method="_on_Canvas_resized"]
|
[connection signal="resized" from="." to="." method="_on_Canvas_resized"]
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
extends Resource
|
||||||
|
class_name SummerDayCanvasState
|
||||||
|
|
||||||
|
signal fill_transform_changed(fill_transform)
|
||||||
|
signal canvas_transform_changed(canvas_transform)
|
||||||
|
signal view_transform_changed(view_transform)
|
||||||
|
|
||||||
|
var rect_size: Vector2
|
||||||
|
|
||||||
|
var fill_transform := Transform2D.IDENTITY
|
||||||
|
var canvas_transform := Transform2D.IDENTITY
|
||||||
|
var view_transform := Transform2D.IDENTITY # fill_transform * canvas_transform
|
||||||
|
|
||||||
|
|
||||||
|
func _init():
|
||||||
|
connect("fill_transform_changed", self, "_update_view_transformation")
|
||||||
|
connect("canvas_transform_changed", self, "_update_view_transformation")
|
||||||
|
|
||||||
|
|
||||||
|
func update_fill_transform(scene):
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
func _update_view_transformation(transform):
|
||||||
|
print("DoWeReach?")
|
||||||
|
view_transform = fill_transform * canvas_transform
|
||||||
|
emit_signal("view_transform_changed", view_transform)
|
|
@ -1,22 +0,0 @@
|
||||||
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
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
tool
|
||||||
|
extends Polygon2D
|
||||||
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func update_size(scene: SummerDayScene):
|
||||||
|
if scene == null:
|
||||||
|
polygon = PoolVector2Array()
|
||||||
|
return
|
||||||
|
polygon = PoolVector2Array(
|
||||||
|
[
|
||||||
|
Vector2.ZERO,
|
||||||
|
Vector2(scene.raw_aspect_ratio, 0.0),
|
||||||
|
Vector2(scene.raw_aspect_ratio, 1.0),
|
||||||
|
Vector2(0.0, 1.0)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
func _on_view_transform_changed(new_view_transform):
|
||||||
|
transform = new_view_transform
|
|
@ -0,0 +1,10 @@
|
||||||
|
extends Reference
|
||||||
|
class_name SummerDayBaseTool
|
||||||
|
|
||||||
|
|
||||||
|
func _check_if_chosen(input) -> int: # Virtual.
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
func _run(tool_context): # Virtual.
|
||||||
|
pass
|
|
@ -0,0 +1,4 @@
|
||||||
|
extends SummerDayBaseTool
|
||||||
|
class_name SummerDayHandTool
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
extends Reference
|
||||||
|
class_name SummerDayToolContext
|
||||||
|
|
||||||
|
|
||||||
|
var edited_scene: SummerDayScene
|
||||||
|
|
||||||
|
|
||||||
|
# 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
|
|
@ -44,11 +44,26 @@ _global_script_classes=[ {
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://Bullshit/ScriptEditTest.gd"
|
"path": "res://Bullshit/ScriptEditTest.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Reference",
|
||||||
|
"class": "SummerDayBaseTool",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://addons/summer_day/tool/canvas/tool_system/base_tool.gd"
|
||||||
|
}, {
|
||||||
"base": "Control",
|
"base": "Control",
|
||||||
"class": "SummerDayCanvas",
|
"class": "SummerDayCanvas",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://addons/summer_day/tool/canvas/canvas.gd"
|
"path": "res://addons/summer_day/tool/canvas/canvas.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Resource",
|
||||||
|
"class": "SummerDayCanvasState",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://addons/summer_day/tool/canvas/canvas_state.gd"
|
||||||
|
}, {
|
||||||
|
"base": "SummerDayBaseTool",
|
||||||
|
"class": "SummerDayHandTool",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://addons/summer_day/tool/canvas/tool_system/general_use/hand.gd"
|
||||||
|
}, {
|
||||||
"base": "Control",
|
"base": "Control",
|
||||||
"class": "SummerDayMainScreen",
|
"class": "SummerDayMainScreen",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
|
@ -64,6 +79,11 @@ _global_script_classes=[ {
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://addons/summer_day/tool/timeline/timeline.gd"
|
"path": "res://addons/summer_day/tool/timeline/timeline.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Reference",
|
||||||
|
"class": "SummerDayToolContext",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://addons/summer_day/tool/canvas/tool_system/tool_context.gd"
|
||||||
|
}, {
|
||||||
"base": "OH",
|
"base": "OH",
|
||||||
"class": "VeryWorse",
|
"class": "VeryWorse",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
|
@ -77,10 +97,14 @@ _global_script_class_icons={
|
||||||
"PremiumTexture": "",
|
"PremiumTexture": "",
|
||||||
"SDDisplay": "",
|
"SDDisplay": "",
|
||||||
"ScriptEditorTest": "",
|
"ScriptEditorTest": "",
|
||||||
|
"SummerDayBaseTool": "",
|
||||||
"SummerDayCanvas": "",
|
"SummerDayCanvas": "",
|
||||||
|
"SummerDayCanvasState": "",
|
||||||
|
"SummerDayHandTool": "",
|
||||||
"SummerDayMainScreen": "",
|
"SummerDayMainScreen": "",
|
||||||
"SummerDayScene": "",
|
"SummerDayScene": "",
|
||||||
"SummerDayTimeline": "",
|
"SummerDayTimeline": "",
|
||||||
|
"SummerDayToolContext": "",
|
||||||
"VeryWorse": ""
|
"VeryWorse": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user