From 4e9b65707782a3c4eb43e13d3a2a88522a543f03 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Wed, 24 Jan 2024 03:14:11 +0200 Subject: [PATCH] Remove Global.has_focus completely Might be a risky change, but I haven't noticed any bugs so far --- src/Autoload/Global.gd | 2 -- src/Main.gd | 7 ------- src/UI/ToolsPanel/ToolButtons.gd | 8 +++++++- src/UI/ViewportContainer.gd | 2 -- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 4bdff4a1d..fd0b9096a 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -117,8 +117,6 @@ var current_project_index := 0: var can_draw := false ## (Intended to be used as getter only) Tells if the user allowed to move the guide while on canvas. var move_guides_on_canvas := true -## Tells if the canvas in currently in focus. -var has_focus := false var play_only_tags := true ## If [code]true[/code], animation plays only on frames of the same tag. ## (Intended to be used as getter only) Tells if the x-symmetry guide ( -- ) is visible. diff --git a/src/Main.gd b/src/Main.gd index d48bfdcdb..b1bf082a3 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -206,7 +206,6 @@ func _notification(what: int) -> void: # If the mouse exits the window and another application has the focus, # pause the application NOTIFICATION_APPLICATION_FOCUS_OUT: - Global.has_focus = false if Global.pause_when_unfocused: get_tree().paused = true NOTIFICATION_WM_MOUSE_EXIT: @@ -217,12 +216,6 @@ func _notification(what: int) -> void: get_tree().paused = false NOTIFICATION_APPLICATION_FOCUS_IN: get_tree().paused = false - var mouse_pos := get_global_mouse_position() - var viewport_rect := Rect2( - Global.main_viewport.global_position, Global.main_viewport.size - ) - if viewport_rect.has_point(mouse_pos): - Global.has_focus = true func _on_files_dropped(files: PackedStringArray) -> void: diff --git a/src/UI/ToolsPanel/ToolButtons.gd b/src/UI/ToolsPanel/ToolButtons.gd index f1b794898..200e4e631 100644 --- a/src/UI/ToolsPanel/ToolButtons.gd +++ b/src/UI/ToolsPanel/ToolButtons.gd @@ -3,11 +3,17 @@ extends FlowContainer var pen_inverted := false +func _ready() -> void: + # Ensure to only call _input() if the cursor is inside the main canvas viewport + Global.main_viewport.mouse_entered.connect(set_process_input.bind(true)) + Global.main_viewport.mouse_exited.connect(set_process_input.bind(false)) + + func _input(event: InputEvent) -> void: if event is InputEventMouseMotion: pen_inverted = event.pen_inverted return - if not Global.has_focus or not Global.can_draw: + if not Global.can_draw: return for action in ["undo", "redo"]: if event.is_action_pressed(action): diff --git a/src/UI/ViewportContainer.gd b/src/UI/ViewportContainer.gd index d1822f873..1110ef470 100644 --- a/src/UI/ViewportContainer.gd +++ b/src/UI/ViewportContainer.gd @@ -12,13 +12,11 @@ func _ready() -> void: func _on_ViewportContainer_mouse_entered() -> void: camera.set_process_input(true) - Global.has_focus = true Global.control.left_cursor.visible = Global.show_left_tool_icon Global.control.right_cursor.visible = Global.show_right_tool_icon func _on_ViewportContainer_mouse_exited() -> void: camera.set_process_input(false) - Global.has_focus = false Global.control.left_cursor.visible = false Global.control.right_cursor.visible = false