diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 24ee555f7..2e504068d 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -561,7 +561,10 @@ var draw_grid := false ## If [code]true[/code], the pixel grid is visible. var draw_pixel_grid := false ## If [code]true[/code], the rulers are visible. -var show_rulers := true +var show_rulers := true: + set(value): + show_rulers = value + get_tree().set_group(&"CanvasRulers", "visible", value) ## If [code]true[/code], the guides are visible. var show_guides := true ## If [code]true[/code], the mouse guides are visible. @@ -612,10 +615,6 @@ var cel_button_scene: PackedScene = load("res://src/UI/Timeline/CelButton.tscn") @onready var global_tool_options: PanelContainer = control.find_child("Global Tool Options") ## Camera of the main canvas. @onready var camera: CanvasCamera = main_viewport.find_child("Camera2D") -## Horizontal ruler of the main canvas. It has the [param HorizontalRuler.gd] script attached. -@onready var horizontal_ruler: BaseButton = control.find_child("HorizontalRuler") -## Vertical ruler of the main canvas. It has the [param VerticalRuler.gd] script attached. -@onready var vertical_ruler: BaseButton = control.find_child("VerticalRuler") ## Transparent checker of the main canvas. It has the [param TransparentChecker.gd] script attached. @onready var transparent_checker: ColorRect = control.find_child("TransparentChecker") diff --git a/src/UI/Canvas/Rulers/HorizontalRuler.gd b/src/UI/Canvas/Rulers/HorizontalRuler.gd index e08ef25d2..b60ca19aa 100644 --- a/src/UI/Canvas/Rulers/HorizontalRuler.gd +++ b/src/UI/Canvas/Rulers/HorizontalRuler.gd @@ -8,6 +8,8 @@ var minor_subdivision := 4 var first: Vector2 var last: Vector2 +@onready var vertical_ruler := $"../ViewportandVerticalRuler/VerticalRuler" as Button + func _ready() -> void: Global.project_switched.connect(queue_redraw) @@ -120,7 +122,7 @@ func create_guide() -> void: return var mouse_pos := get_local_mouse_position() if mouse_pos.x < RULER_WIDTH: # For double guides - Global.vertical_ruler.create_guide() + vertical_ruler.create_guide() var guide := Guide.new() if absf(Global.camera.rotation_degrees) < 45 or absf(Global.camera.rotation_degrees) > 135: guide.type = guide.Types.HORIZONTAL diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index cb5d0dd17..9b3c6534a 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -735,8 +735,6 @@ func _toggle_show_pixel_grid() -> void: func _toggle_show_rulers() -> void: Global.show_rulers = !Global.show_rulers view_menu.set_item_checked(Global.ViewMenu.SHOW_RULERS, Global.show_rulers) - Global.horizontal_ruler.visible = Global.show_rulers - Global.vertical_ruler.visible = Global.show_rulers func _toggle_show_guides() -> void: diff --git a/src/UI/UI.tscn b/src/UI/UI.tscn index c4406b0c2..1700b0868 100644 --- a/src/UI/UI.tscn +++ b/src/UI/UI.tscn @@ -275,7 +275,7 @@ tab_close_display_policy = 2 drag_to_rearrange_enabled = true script = ExtResource("3") -[node name="HorizontalRuler" type="Button" parent="DockableContainer/Main Canvas"] +[node name="HorizontalRuler" type="Button" parent="DockableContainer/Main Canvas" groups=["CanvasRulers"]] clip_contents = true custom_minimum_size = Vector2(0, 16) layout_mode = 2 @@ -291,7 +291,7 @@ size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_constants/separation = 0 -[node name="VerticalRuler" type="Button" parent="DockableContainer/Main Canvas/ViewportandVerticalRuler"] +[node name="VerticalRuler" type="Button" parent="DockableContainer/Main Canvas/ViewportandVerticalRuler" groups=["CanvasRulers"]] clip_contents = true custom_minimum_size = Vector2(16, 0) layout_mode = 2