Skip to content

Commit 03721f5

Browse files
authored
Adds zoom in and out buttons
1 parent 2dc28d5 commit 03721f5

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const ZOOM_FACTOR: float = 1.1
3535
@onready var _open_scene_icon = _open_scene_button.get_theme_icon("Load", "EditorIcons")
3636

3737
@onready var _mouse_override: Control = %MouseOverride
38+
@onready var _zoom_buttons: HBoxContainer = %ZoomButtons
3839
@onready var _zoom_button: Button = %ZoomButton
3940

4041
var _current_block_script: BlockScriptSerialization
@@ -140,7 +141,7 @@ func _on_context_changed():
140141
zoom = 1
141142

142143
_window.visible = false
143-
_zoom_button.visible = false
144+
_zoom_buttons.visible = false
144145

145146
_empty_box.visible = false
146147
_selected_node_box.visible = false
@@ -152,7 +153,7 @@ func _on_context_changed():
152153
if _context.block_script != null:
153154
_load_block_script(_context.block_script)
154155
_window.visible = true
155-
_zoom_button.visible = true
156+
_zoom_buttons.visible = true
156157

157158
if _context.block_script != _current_block_script:
158159
reset_window_position()
@@ -437,6 +438,16 @@ func generate_script_from_current_window() -> String:
437438
return ScriptGenerator.generate_script(_current_ast_list, _context.block_script)
438439

439440

441+
func _on_zoom_out_button_pressed() -> void:
442+
if zoom > 0.2:
443+
zoom /= ZOOM_FACTOR
444+
445+
440446
func _on_zoom_button_pressed():
441447
zoom = 1.0
442448
reset_window_position()
449+
450+
451+
func _on_zoom_in_button_pressed() -> void:
452+
if zoom < 2:
453+
zoom *= ZOOM_FACTOR

addons/block_code/ui/block_canvas/block_canvas.tscn

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mouse_filter = 2
2424

2525
[node name="Window" type="Control" parent="WindowContainer"]
2626
unique_name_in_owner = true
27+
visible = false
2728
layout_mode = 2
2829
anchors_preset = 0
2930
offset_right = 1152.0
@@ -43,7 +44,9 @@ grow_horizontal = 0
4344
grow_vertical = 0
4445
mouse_filter = 2
4546

46-
[node name="MarginContainer" type="MarginContainer" parent="WindowContainer/Overlay"]
47+
[node name="ZoomButtons" type="HBoxContainer" parent="WindowContainer/Overlay"]
48+
unique_name_in_owner = true
49+
visible = false
4750
layout_mode = 1
4851
anchors_preset = 3
4952
anchor_left = 1.0
@@ -55,17 +58,30 @@ offset_top = -40.0
5558
grow_horizontal = 0
5659
grow_vertical = 0
5760
mouse_filter = 2
58-
theme_override_constants/margin_left = 4
59-
theme_override_constants/margin_top = 4
60-
theme_override_constants/margin_right = 4
61-
theme_override_constants/margin_bottom = 4
6261

63-
[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer"]
62+
[node name="ZoomOutButton" type="Button" parent="WindowContainer/Overlay/ZoomButtons"]
63+
modulate = Color(1, 1, 1, 0.470588)
64+
custom_minimum_size = Vector2(25, 0)
65+
layout_mode = 2
66+
focus_mode = 0
67+
theme_override_font_sizes/font_size = 24
68+
text = "-"
69+
70+
[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/ZoomButtons"]
6471
unique_name_in_owner = true
6572
modulate = Color(1, 1, 1, 0.470588)
6673
layout_mode = 2
6774
focus_mode = 0
6875
theme_override_font_sizes/font_size = 24
76+
text = "1.0x"
77+
78+
[node name="ZoomInButton" type="Button" parent="WindowContainer/Overlay/ZoomButtons"]
79+
modulate = Color(1, 1, 1, 0.470588)
80+
custom_minimum_size = Vector2(25, 0)
81+
layout_mode = 2
82+
focus_mode = 0
83+
theme_override_font_sizes/font_size = 24
84+
text = "+"
6985

7086
[node name="MouseOverride" type="MarginContainer" parent="."]
7187
unique_name_in_owner = true
@@ -85,14 +101,13 @@ horizontal_alignment = 1
85101

86102
[node name="SelectedNodeBox" type="VBoxContainer" parent="."]
87103
unique_name_in_owner = true
88-
visible = false
89104
layout_mode = 2
90105
size_flags_vertical = 4
91106

92107
[node name="Label" type="Label" parent="SelectedNodeBox"]
93108
custom_minimum_size = Vector2(200, 0)
94109
layout_mode = 2
95-
text = "Use block coding to create custom behavior and game mechanics for \"{node}\"."
110+
text = "Use block coding to create custom behavior and game mechanics for \"ZoomOutButton\"."
96111
horizontal_alignment = 1
97112
autowrap_mode = 2
98113

@@ -130,17 +145,21 @@ unique_name_in_owner = true
130145
layout_mode = 2
131146
size_flags_horizontal = 4
132147
theme_type_variation = &"InspectorActionButton"
148+
disabled = true
133149
text = "Open in Editor"
134150

135151
[node name="ReplaceBlockCodeButton" type="Button" parent="SelectedNodeWithBlockCodeBox/ButtonsBox"]
136152
unique_name_in_owner = true
137153
layout_mode = 2
138154
size_flags_horizontal = 4
139155
theme_type_variation = &"InspectorActionButton"
156+
disabled = true
140157
text = "Override Block Code"
141158
icon = ExtResource("2_710vn")
142159

143-
[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButton" to="." method="_on_zoom_button_pressed"]
160+
[connection signal="pressed" from="WindowContainer/Overlay/ZoomButtons/ZoomOutButton" to="." method="_on_zoom_out_button_pressed"]
161+
[connection signal="pressed" from="WindowContainer/Overlay/ZoomButtons/ZoomButton" to="." method="_on_zoom_button_pressed"]
162+
[connection signal="pressed" from="WindowContainer/Overlay/ZoomButtons/ZoomInButton" to="." method="_on_zoom_in_button_pressed"]
144163
[connection signal="pressed" from="SelectedNodeBox/ButtonsBox/AddBlockCodeButton" to="." method="_on_add_block_code_button_pressed"]
145164
[connection signal="pressed" from="SelectedNodeWithBlockCodeBox/ButtonsBox/OpenSceneButton" to="." method="_on_open_scene_button_pressed"]
146165
[connection signal="pressed" from="SelectedNodeWithBlockCodeBox/ButtonsBox/ReplaceBlockCodeButton" to="." method="_on_replace_block_code_button_pressed"]

0 commit comments

Comments
 (0)