Skip to content

Commit

Permalink
Merge pull request #275 from DoomTas3r/zoom-in-and-out-buttons
Browse files Browse the repository at this point in the history
Zoom in and out buttons
  • Loading branch information
manuq authored Oct 22, 2024
2 parents ebeae59 + 7ac9caa commit 94a4d60
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
23 changes: 21 additions & 2 deletions addons/block_code/ui/block_canvas/block_canvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ const ZOOM_FACTOR: float = 1.1
@onready var _replace_block_code_button: Button = %ReplaceBlockCodeButton

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

@onready var _mouse_override: Control = %MouseOverride
@onready var _zoom_buttons: HBoxContainer = %ZoomButtons
@onready var _zoom_out_button: Button = %ZoomOutButton
@onready var _zoom_button: Button = %ZoomButton
@onready var _zoom_in_button: Button = %ZoomInButton

var _current_block_script: BlockScriptSerialization
var _current_ast_list: ASTList
Expand All @@ -58,6 +63,10 @@ func _ready():

if not _open_scene_button.icon and not Util.node_is_part_of_edited_scene(self):
_open_scene_button.icon = _open_scene_icon
if not _zoom_out_button.icon:
_zoom_out_button.icon = _icon_zoom_out
if not _zoom_in_button.icon:
_zoom_in_button.icon = _icon_zoom_in


func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
Expand Down Expand Up @@ -140,7 +149,7 @@ func _on_context_changed():
zoom = 1

_window.visible = false
_zoom_button.visible = false
_zoom_buttons.visible = false

_empty_box.visible = false
_selected_node_box.visible = false
Expand All @@ -152,7 +161,7 @@ func _on_context_changed():
if _context.block_script != null:
_load_block_script(_context.block_script)
_window.visible = true
_zoom_button.visible = true
_zoom_buttons.visible = true

if _context.block_script != _current_block_script:
reset_window_position()
Expand Down Expand Up @@ -437,6 +446,16 @@ func generate_script_from_current_window() -> String:
return ScriptGenerator.generate_script(_current_ast_list, _context.block_script)


func _on_zoom_out_button_pressed() -> void:
if zoom > 0.2:
zoom /= ZOOM_FACTOR


func _on_zoom_button_pressed():
zoom = 1.0
reset_window_position()


func _on_zoom_in_button_pressed() -> void:
if zoom < 2:
zoom *= ZOOM_FACTOR
29 changes: 27 additions & 2 deletions addons/block_code/ui/block_canvas/block_canvas.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mouse_filter = 2

[node name="Window" type="Control" parent="WindowContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
anchors_preset = 0
offset_right = 1152.0
Expand Down Expand Up @@ -60,9 +61,31 @@ theme_override_constants/margin_top = 4
theme_override_constants/margin_right = 4
theme_override_constants/margin_bottom = 4

[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer"]
[node name="ZoomButtons" type="HBoxContainer" parent="WindowContainer/Overlay/MarginContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2

[node name="ZoomOutButton" type="Button" parent="WindowContainer/Overlay/MarginContainer/ZoomButtons"]
unique_name_in_owner = true
modulate = Color(1, 1, 1, 0.470588)
custom_minimum_size = Vector2(25, 0)
layout_mode = 2
focus_mode = 0
theme_override_font_sizes/font_size = 24

[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer/ZoomButtons"]
unique_name_in_owner = true
modulate = Color(1, 1, 1, 0.470588)
layout_mode = 2
focus_mode = 0
theme_override_font_sizes/font_size = 24
text = "1.0x"

[node name="ZoomInButton" type="Button" parent="WindowContainer/Overlay/MarginContainer/ZoomButtons"]
unique_name_in_owner = true
modulate = Color(1, 1, 1, 0.470588)
custom_minimum_size = Vector2(25, 0)
layout_mode = 2
focus_mode = 0
theme_override_font_sizes/font_size = 24
Expand Down Expand Up @@ -140,7 +163,9 @@ theme_type_variation = &"InspectorActionButton"
text = "Override Block Code"
icon = ExtResource("2_710vn")

[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButton" to="." method="_on_zoom_button_pressed"]
[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButtons/ZoomOutButton" to="." method="_on_zoom_out_button_pressed"]
[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButtons/ZoomButton" to="." method="_on_zoom_button_pressed"]
[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButtons/ZoomInButton" to="." method="_on_zoom_in_button_pressed"]
[connection signal="pressed" from="SelectedNodeBox/ButtonsBox/AddBlockCodeButton" to="." method="_on_add_block_code_button_pressed"]
[connection signal="pressed" from="SelectedNodeWithBlockCodeBox/ButtonsBox/OpenSceneButton" to="." method="_on_open_scene_button_pressed"]
[connection signal="pressed" from="SelectedNodeWithBlockCodeBox/ButtonsBox/ReplaceBlockCodeButton" to="." method="_on_replace_block_code_button_pressed"]

0 comments on commit 94a4d60

Please sign in to comment.