From 6cd68f3599f2461a95d304a24d27c9b0b7e8e2de Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Mon, 21 Sep 2020 18:53:36 +0200 Subject: [PATCH] Allow both drag & drop as well as zooming in repositories --- node.gd | 13 ++++++++++++- node.tscn | 4 +++- repository.gd | 12 ++++++------ repository.tscn | 2 +- text_editor.tscn | 3 ++- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/node.gd b/node.gd index b66428f..5709d1a 100644 --- a/node.gd +++ b/node.gd @@ -8,6 +8,7 @@ var repository: Container var children = {} setget children_set var id_always_visible = false var held = false +var hovered = false var arrow = preload("res://arrow.tscn") @@ -84,14 +85,24 @@ func children_set(new_children): children = new_children func _on_hover(): + hovered = true $Content.visible = true $ID.visible = true func _on_unhover(): + hovered = false if not id_always_visible: $Content.visible = false $ID.visible = false - + +func _input(event): + if hovered: + if event.is_action_pressed("click"): + held = true + if event.is_action_released("click"): + held = false + + func _input_event(_viewport, event, _shape_idx): if event is InputEventMouseButton: if event.button_index == BUTTON_LEFT: diff --git a/node.tscn b/node.tscn index 37c85b7..585c7d0 100644 --- a/node.tscn +++ b/node.tscn @@ -15,7 +15,7 @@ margin_left = -29.0 margin_top = -28.0 margin_right = 29.0 margin_bottom = 30.0 -mouse_filter = 2 +mouse_filter = 1 color = Color( 0.984314, 0, 0, 1 ) __meta__ = { "_edit_use_anchors_": false @@ -53,6 +53,8 @@ __meta__ = { shape = SubResource( 1 ) [node name="Arrows" type="Node2D" parent="."] +[connection signal="mouse_entered" from="Rect" to="." method="_on_hover"] +[connection signal="mouse_exited" from="Rect" to="." method="_on_unhover"] [connection signal="input_event" from="Area" to="." method="_input_event"] [connection signal="mouse_entered" from="Area" to="." method="_on_hover"] [connection signal="mouse_exited" from="Area" to="." method="_on_unhover"] diff --git a/repository.gd b/repository.gd index 36d97ee..3941f03 100644 --- a/repository.gd +++ b/repository.gd @@ -18,12 +18,12 @@ 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 _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(): if shell.run("test -d .git && echo yes || echo no") == "yes\n": diff --git a/repository.tscn b/repository.tscn index 001f000..e443c5f 100644 --- a/repository.tscn +++ b/repository.tscn @@ -11,7 +11,7 @@ margin_left = 2.0 margin_top = 3.0 margin_right = -6.0 margin_bottom = -4.0 -mouse_filter = 2 +mouse_filter = 1 theme = ExtResource( 2 ) script = ExtResource( 1 ) __meta__ = { diff --git a/text_editor.tscn b/text_editor.tscn index f75acaa..68ccab6 100644 --- a/text_editor.tscn +++ b/text_editor.tscn @@ -6,7 +6,6 @@ [node name="TextEditor" type="TextEdit"] anchor_right = 1.0 anchor_bottom = 1.0 -custom_fonts/font = ExtResource( 1 ) custom_colors/background_color = Color( 0, 0, 0, 1 ) text = "Text here" syntax_highlighting = true @@ -24,7 +23,9 @@ margin_left = -117.279 margin_top = -59.399 margin_right = -17.2788 margin_bottom = -14.399 +focus_mode = 0 custom_fonts/font = ExtResource( 1 ) +enabled_focus_mode = 0 text = "Save" __meta__ = { "_edit_use_anchors_": false