From a07deac051ce89ec0341620cd65faff63b2b0a1a Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Tue, 15 Sep 2020 18:41:06 +0200 Subject: [PATCH] Mouse Zoom Essentials --- node.gd | 5 +++-- project.godot | 10 ++++++++++ repository.gd | 22 +++++++++++++++++++--- repository.tscn | 7 +++++++ terminal.tscn | 8 ++++---- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/node.gd b/node.gd index 122f100..e7bd125 100644 --- a/node.gd +++ b/node.gd @@ -11,6 +11,7 @@ var held = false var arrow = preload("res://arrow.tscn") + func _ready(): pass @@ -25,8 +26,8 @@ func apply_forces(): var offset = Vector2(0, 80) for c in children.keys(): - if get_node("..").objects.has(c): - var other = get_node("..").objects[c] + if repository.objects.has(c): + var other = repository.objects[c] if other.visible: var d = other.position.distance_to(position+offset) var dir = (other.position - (position+offset)).normalized() diff --git a/project.godot b/project.godot index 6c84ce5..afa8255 100644 --- a/project.godot +++ b/project.godot @@ -65,6 +65,16 @@ click={ "events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null) ] } +zoom_in={ +"deadzone": 0.5, +"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":4,"pressed":false,"doubleclick":false,"script":null) + ] +} +zoom_out={ +"deadzone": 0.5, +"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null) + ] +} [network] diff --git a/repository.gd b/repository.gd index 61a6112..0ffc14a 100644 --- a/repository.gd +++ b/repository.gd @@ -7,16 +7,26 @@ var node = preload("res://node.tscn") var shell = Shell.new() var objects = {} +var mouse_inside = false var _simplified_view = false func _ready(): + $Nodes.rect_pivot_offset = $Nodes.rect_size / 2 + print($Nodes.rect_pivot_offset) pass func _process(_delta): if path: apply_forces() +func _input(event): + if mouse_inside: + if event.is_action_pressed("zoom_out") and $Nodes.rect_scale.x > 0.3: + $Nodes.rect_scale -= Vector2(0.05, 0.05) + if event.is_action_pressed("zoom_in") and $Nodes.rect_scale.x < 2: + $Nodes.rect_scale += Vector2(0.05, 0.05) + func update_everything(): update_head() update_refs() @@ -79,7 +89,7 @@ func update_objects(): n.children = tag_target(o) n.position = find_position(n) - add_child(n) + $Nodes.add_child(n) objects[o] = n func update_refs(): @@ -93,7 +103,7 @@ func update_refs(): objects[r] = n n.children = {ref_target(r): ""} n.position = find_position(n) - add_child(n) + $Nodes.add_child(n) var n = objects[r] n.children = {ref_target(r): ""} @@ -151,7 +161,7 @@ func update_head(): n.position = find_position(n) objects["HEAD"] = n - add_child(n) + $Nodes.add_child(n) var n = objects["HEAD"] n.children = {ref_target("HEAD"): ""} @@ -244,3 +254,9 @@ func remove_gone_stuff(): if not all.has(o): objects[o].queue_free() objects.erase(o) + +func _on_mouse_entered(): + mouse_inside = true + +func _on_mouse_exited(): + mouse_inside = false diff --git a/repository.tscn b/repository.tscn index 3e15bb3..5d02db9 100644 --- a/repository.tscn +++ b/repository.tscn @@ -64,5 +64,12 @@ margin_right = 24.0 margin_bottom = 24.0 custom_fonts/font = ExtResource( 2 ) text = "Hide trees and blobs" + +[node name="Nodes" type="Control" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] +[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] [connection signal="pressed" from="Button" to="." method="update_everything"] [connection signal="toggled" from="SimplifyCheckbox" to="." method="simplify_view"] diff --git a/terminal.tscn b/terminal.tscn index 920a183..fce310d 100644 --- a/terminal.tscn +++ b/terminal.tscn @@ -4,10 +4,10 @@ [ext_resource path="res://terminal.gd" type="Script" id=2] [ext_resource path="res://styles/terminal_input.tres" type="StyleBox" id=3] -[sub_resource type="StyleBoxFlat" id=2] +[sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0, 0, 0, 1 ) -[sub_resource type="StyleBoxFlat" id=1] +[sub_resource type="StyleBoxFlat" id=2] content_margin_left = 10.0 content_margin_right = 10.0 content_margin_top = 10.0 @@ -35,8 +35,8 @@ margin_right = 1920.0 margin_bottom = 1039.0 focus_mode = 2 size_flags_vertical = 3 -custom_styles/focus = SubResource( 2 ) -custom_styles/normal = SubResource( 1 ) +custom_styles/focus = SubResource( 1 ) +custom_styles/normal = SubResource( 2 ) custom_fonts/normal_font = ExtResource( 1 ) custom_colors/selection_color = Color( 0.14902, 0.368627, 0.168627, 0.690196 ) scroll_following = true