Skip to content

Commit 94a4d60

Browse files
authored
Merge pull request #275 from DoomTas3r/zoom-in-and-out-buttons
Zoom in and out buttons
2 parents ebeae59 + 7ac9caa commit 94a4d60

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ const ZOOM_FACTOR: float = 1.1
3333
@onready var _replace_block_code_button: Button = %ReplaceBlockCodeButton
3434

3535
@onready var _open_scene_icon = _open_scene_button.get_theme_icon("Load", "EditorIcons")
36+
@onready var _icon_zoom_out := EditorInterface.get_editor_theme().get_icon("ZoomLess", "EditorIcons")
37+
@onready var _icon_zoom_in := EditorInterface.get_editor_theme().get_icon("ZoomMore", "EditorIcons")
3638

3739
@onready var _mouse_override: Control = %MouseOverride
40+
@onready var _zoom_buttons: HBoxContainer = %ZoomButtons
41+
@onready var _zoom_out_button: Button = %ZoomOutButton
3842
@onready var _zoom_button: Button = %ZoomButton
43+
@onready var _zoom_in_button: Button = %ZoomInButton
3944

4045
var _current_block_script: BlockScriptSerialization
4146
var _current_ast_list: ASTList
@@ -58,6 +63,10 @@ func _ready():
5863

5964
if not _open_scene_button.icon and not Util.node_is_part_of_edited_scene(self):
6065
_open_scene_button.icon = _open_scene_icon
66+
if not _zoom_out_button.icon:
67+
_zoom_out_button.icon = _icon_zoom_out
68+
if not _zoom_in_button.icon:
69+
_zoom_in_button.icon = _icon_zoom_in
6170

6271

6372
func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
@@ -140,7 +149,7 @@ func _on_context_changed():
140149
zoom = 1
141150

142151
_window.visible = false
143-
_zoom_button.visible = false
152+
_zoom_buttons.visible = false
144153

145154
_empty_box.visible = false
146155
_selected_node_box.visible = false
@@ -152,7 +161,7 @@ func _on_context_changed():
152161
if _context.block_script != null:
153162
_load_block_script(_context.block_script)
154163
_window.visible = true
155-
_zoom_button.visible = true
164+
_zoom_buttons.visible = true
156165

157166
if _context.block_script != _current_block_script:
158167
reset_window_position()
@@ -437,6 +446,16 @@ func generate_script_from_current_window() -> String:
437446
return ScriptGenerator.generate_script(_current_ast_list, _context.block_script)
438447

439448

449+
func _on_zoom_out_button_pressed() -> void:
450+
if zoom > 0.2:
451+
zoom /= ZOOM_FACTOR
452+
453+
440454
func _on_zoom_button_pressed():
441455
zoom = 1.0
442456
reset_window_position()
457+
458+
459+
func _on_zoom_in_button_pressed() -> void:
460+
if zoom < 2:
461+
zoom *= ZOOM_FACTOR

addons/block_code/ui/block_canvas/block_canvas.tscn

Lines changed: 27 additions & 2 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
@@ -60,9 +61,31 @@ theme_override_constants/margin_top = 4
6061
theme_override_constants/margin_right = 4
6162
theme_override_constants/margin_bottom = 4
6263

63-
[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer"]
64+
[node name="ZoomButtons" type="HBoxContainer" parent="WindowContainer/Overlay/MarginContainer"]
65+
unique_name_in_owner = true
66+
visible = false
67+
layout_mode = 2
68+
69+
[node name="ZoomOutButton" type="Button" parent="WindowContainer/Overlay/MarginContainer/ZoomButtons"]
70+
unique_name_in_owner = true
71+
modulate = Color(1, 1, 1, 0.470588)
72+
custom_minimum_size = Vector2(25, 0)
73+
layout_mode = 2
74+
focus_mode = 0
75+
theme_override_font_sizes/font_size = 24
76+
77+
[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer/ZoomButtons"]
78+
unique_name_in_owner = true
79+
modulate = Color(1, 1, 1, 0.470588)
80+
layout_mode = 2
81+
focus_mode = 0
82+
theme_override_font_sizes/font_size = 24
83+
text = "1.0x"
84+
85+
[node name="ZoomInButton" type="Button" parent="WindowContainer/Overlay/MarginContainer/ZoomButtons"]
6486
unique_name_in_owner = true
6587
modulate = Color(1, 1, 1, 0.470588)
88+
custom_minimum_size = Vector2(25, 0)
6689
layout_mode = 2
6790
focus_mode = 0
6891
theme_override_font_sizes/font_size = 24
@@ -140,7 +163,9 @@ theme_type_variation = &"InspectorActionButton"
140163
text = "Override Block Code"
141164
icon = ExtResource("2_710vn")
142165

143-
[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButton" to="." method="_on_zoom_button_pressed"]
166+
[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButtons/ZoomOutButton" to="." method="_on_zoom_out_button_pressed"]
167+
[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButtons/ZoomButton" to="." method="_on_zoom_button_pressed"]
168+
[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButtons/ZoomInButton" to="." method="_on_zoom_in_button_pressed"]
144169
[connection signal="pressed" from="SelectedNodeBox/ButtonsBox/AddBlockCodeButton" to="." method="_on_add_block_code_button_pressed"]
145170
[connection signal="pressed" from="SelectedNodeWithBlockCodeBox/ButtonsBox/OpenSceneButton" to="." method="_on_open_scene_button_pressed"]
146171
[connection signal="pressed" from="SelectedNodeWithBlockCodeBox/ButtonsBox/ReplaceBlockCodeButton" to="." method="_on_replace_block_code_button_pressed"]

0 commit comments

Comments
 (0)