I have a Control. When the mouse cursor hovers over the Control it has the shape "Can Drop" (an open hand) that I configured with the inspector panel - so far so good. When the Control is clicked, I want the cursor to immediately change to to "Drag" (closed hand). And I'd like the reverse to happen immediately when the mouse button is released.
As far as I can tell, I can only change the cursor from script by calling set_default_cursor_shape(...)
. But it doesn't seem to take effect until the mouse moves. It's probably fine for now but I'd like the cursor shape to change right away. Is there some way to do that? Here's my Control's entire script:
extends Control
var start_mouse: Vector2
var start_pos: Vector2
var dragging = false
func _on_Item_gui_input(event):
if event is InputEventMouseButton:
dragging = event.pressed
if dragging:
start_pos = self.rect_position
start_mouse = get_global_mouse_position()
self.set_default_cursor_shape(Control.CURSOR_DRAG)
else:
self.set_default_cursor_shape(Control.CURSOR_CAN_DROP)
elif event is InputEventMouseMotion:
if dragging:
self.set_position(get_global_mouse_position() - start_mouse + start_pos)