Implemented Mouse Passthrough
Implemented Mouse Passthrough code to handle allowing/dis-allowing mouse passthrough, and adding exceptions for specific Control nodes.
This commit is contained in:
parent
cf3ee97bbb
commit
74a22f0792
1 changed files with 49 additions and 0 deletions
|
|
@ -3,6 +3,9 @@ extends Node
|
||||||
var twitcher: TwitcherExtended
|
var twitcher: TwitcherExtended
|
||||||
var context: OverlayContext
|
var context: OverlayContext
|
||||||
var settings: OverlaySettings
|
var settings: OverlaySettings
|
||||||
|
var _pt_except: Array[Control] = []
|
||||||
|
var _pt_mouse: bool = false
|
||||||
|
var _current_pt_mask: PackedVector2Array = []
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
|
@ -21,3 +24,49 @@ func _exit_tree() -> void:
|
||||||
|
|
||||||
func save_settings() -> void:
|
func save_settings() -> void:
|
||||||
ResourceSaver.save(settings, "user://settings.tres")
|
ResourceSaver.save(settings, "user://settings.tres")
|
||||||
|
|
||||||
|
|
||||||
|
func clear_mouse_passthrough() -> void:
|
||||||
|
DisplayServer.window_set_mouse_passthrough([])
|
||||||
|
|
||||||
|
func _update_mouse_passthrough() -> void:
|
||||||
|
var _pt_mask: PackedVector2Array = []
|
||||||
|
for node in _pt_except:
|
||||||
|
var rect := node.get_global_rect()
|
||||||
|
_pt_mask.append_array([
|
||||||
|
rect.position,
|
||||||
|
Vector2(rect.position.x + rect.size.x, rect.position.y),
|
||||||
|
rect.position + rect.size,
|
||||||
|
Vector2(rect.position.x, rect.position.y + rect.size.y)
|
||||||
|
])
|
||||||
|
|
||||||
|
if _pt_mask == _current_pt_mask:
|
||||||
|
print("No Changed made, returning.")
|
||||||
|
return
|
||||||
|
|
||||||
|
_current_pt_mask = _pt_mask
|
||||||
|
DisplayServer.window_set_mouse_passthrough(_current_pt_mask)
|
||||||
|
|
||||||
|
func add_to_passthrough_exception(control: Control) -> void:
|
||||||
|
if not _pt_except.has(control):
|
||||||
|
_pt_except.append(control)
|
||||||
|
control.item_rect_changed.connect(_update_mouse_passthrough)
|
||||||
|
|
||||||
|
func remove_from_passthrough_exceptioon(control: Control) -> void:
|
||||||
|
if _pt_except.has(control):
|
||||||
|
_pt_except.erase(control)
|
||||||
|
control.item_rect_changed.disconnect(_update_mouse_passthrough)
|
||||||
|
|
||||||
|
func enable_mouse_passthrough() -> void:
|
||||||
|
if _pt_mouse:
|
||||||
|
return
|
||||||
|
|
||||||
|
_pt_mouse = true
|
||||||
|
_update_mouse_passthrough()
|
||||||
|
|
||||||
|
func disable_mouse_passthrough() -> void:
|
||||||
|
if not _pt_mouse:
|
||||||
|
return
|
||||||
|
|
||||||
|
_pt_mouse = false
|
||||||
|
clear_mouse_passthrough()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue