You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm relatively new to GUT, but I made a minimal project explaining what I tried to do, why it didn't work, and what I had to do to work around it: GUTInputHandling.zip
This project has a TextureRect with basic code to set the drag data and preview:
and two unit tests, test_drag_using_input_sender and test_drag_using_input_factory:
extendsGutTest# _drag_node spawns in the top-left corner with the size 128x128var_drag_node: Controlvar_senderfuncbefore_all():
_drag_node=preload("res://DragTest.tscn").instantiate()
add_child(_drag_node)
_sender=InputSender.new(Input)
print(_drag_node)
funcafter_each():
_sender.clear()
funcafter_all():
_drag_node.queue_free()
# This test tries to use exclusively InputSender to press, drag,# and release the control.functest_drag_using_input_sender():
await (_sender.mouse_set_position(Vector2(64,64)) # Set position to middle of control
.mouse_left_button_down().wait_secs(1) # Begin click
.mouse_relative_motion(Vector2(128,0)) # Move to the right to begin drag
).wait_secs(1).idleassert_not_null(get_viewport().gui_get_drag_data(), "Control is being dragged")
await_sender.mouse_left_button_up().wait_frames(1).idle# Release the mouseassert_null(get_viewport().gui_get_drag_data(), "Control is no longer being dragged")
# This test uses InputSender to press and release the mouse button,# but generates a drag event with InputFactoryfunctest_drag_using_input_factory():
await_sender.mouse_left_button_down(Vector2(64,64)).wait_secs(1) # Mouse down on controlvarevent=InputFactory.mouse_motion(Vector2(196,64)) # Create a mouse motion event at the destinationevent.relative=Vector2i(128,0) # Set the relative motionevent.button_mask=MOUSE_BUTTON_MASK_LEFT# Indicate we are holding left clickawait_sender.send_event(event).wait_secs(1).idle# Drag eventassert_not_null(get_viewport().gui_get_drag_data(), "Control is being dragged")
await_sender.mouse_left_button_up(Vector2(196,64)).wait_frames(1).idle# Release the mouseassert_null(get_viewport().gui_get_drag_data(), "Control is no longer being dragged")
In test_drag_using_input_sender, the test tries to perform a drag exclusively through InputSender's relative events. It does not end up working, and the console shows that the InputEventMouseMotion event has the button_index set to 0, which means the left mouse button isn't held down.
In test_drag_using_input_factory, I create a InputEventMouseMotion event manually, set the relative to simulate the mouse dragging to the right, and set button_index to indicate that the left mouse button is down. This results in the drag event occurring, as seen by the preview node appearing and the test passing.
input_factory.mp4
It could also be possible that I'm using InputSender incorrectly. Like I said, I'm basically brand new to GUT.
I'm relatively new to GUT, but I made a minimal project explaining what I tried to do, why it didn't work, and what I had to do to work around it: GUTInputHandling.zip
This project has a TextureRect with basic code to set the drag data and preview:
and two unit tests,
test_drag_using_input_sender
andtest_drag_using_input_factory
:In
test_drag_using_input_sender
, the test tries to perform a drag exclusively through InputSender's relative events. It does not end up working, and the console shows that theInputEventMouseMotion
event has thebutton_index
set to 0, which means the left mouse button isn't held down.input_sender.mp4
In
test_drag_using_input_factory
, I create aInputEventMouseMotion
event manually, set therelative
to simulate the mouse dragging to the right, and setbutton_index
to indicate that the left mouse button is down. This results in the drag event occurring, as seen by the preview node appearing and the test passing.input_factory.mp4
It could also be possible that I'm using InputSender incorrectly. Like I said, I'm basically brand new to GUT.
Originally posted by @TGRCdev in #608 (comment)
The text was updated successfully, but these errors were encountered: