godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

add a check if mouse is in control method #3956

Open dryluggage opened 2 years ago

dryluggage commented 2 years ago

Describe the project you are working on

slay the spire like card game

Describe the problem or limitation you are having in your project

when moving a control node and the mouse is stationary and the control moves under the mouse it doesnt send mouse_entered/exited signals

this also is the case with area2d nodes

Describe the feature / enhancement and how it helps to overcome the problem or limitation

a function that checks if the mouse is inside the control then i can just call this function manualy after the control move is over

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

a is_mouse_inside function inside the control node maybe ? or a better name

If this enhancement will not be used often, can it be worked around with a few lines of script?

you would need to get the controlrect ,transorm and the mouseposition and find a way to manually check the collision

Is there a reason why this should be core and not an add-on in the asset library?

since the control has a the mouse_exited/entered signals i think that such a function would already exist in the control node but isnt exposed yet

zinnschlag commented 2 years ago

Related to godotengine/godot#40012 ?

raulsntos commented 2 years ago

you would need to get the controlrect ,transorm and the mouseposition and find a way to manually check the collision

var rect = control.get_global_rect()
var mouse_position = control.get_global_mouse_position()
if rect.has_point(mouse_position):
    print("mouse is inside control")
else:
    print("mouse is NOT inside control")
deakcor commented 2 years ago

you would need to get the controlrect ,transorm and the mouseposition and find a way to manually check the collision

var rect = control.get_global_rect()
var mouse_position = control.get_global_mouse_position()
if rect.has_point(mouse_position):
  print("mouse is inside control")
else:
  print("mouse is NOT inside control")

This work in a lot of case but can be not enough because a position can be in the control but blocked by another control.

Sauermann commented 1 year ago

For Area2D-nodes this has been solved in https://github.com/godotengine/godot/pull/78017. Now you can listen for mouse_entered and mouse_exited signals in order to determine, if the mouse is over the node, even if it was causes by moving the node, while the mouse stands still.