-
Notifications
You must be signed in to change notification settings - Fork 27
ParameterInput: Ignore mouse events when not visible #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+124
−62
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 61 additions & 12 deletions
73
addons/block_code/ui/blocks/utilities/drag_drop_area/drag_drop_area.gd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,65 @@ | ||
@tool | ||
extends MarginContainer | ||
## Drag drop area. | ||
## | ||
## A Control which watches for click and drag gestures beginning from itself. | ||
## It propagates events up to its parent, so it is possible to place this | ||
## control inside a control which processes input events such as [LineEdit]. | ||
## If a drag occurs, it emits [signal drag_started]. | ||
extends Control | ||
|
||
signal mouse_down | ||
signal mouse_up | ||
const Constants = preload("res://addons/block_code/ui/constants.gd") | ||
|
||
signal drag_started | ||
|
||
func _on_gui_input(event): | ||
if event is InputEventMouseButton and get_global_rect().has_point(event.global_position): | ||
var mouse_event: InputEventMouseButton = event as InputEventMouseButton | ||
if mouse_event.button_index == MOUSE_BUTTON_LEFT and mouse_event.pressed: | ||
mouse_down.emit() | ||
get_viewport().set_input_as_handled() | ||
if mouse_event.button_index == MOUSE_BUTTON_LEFT and not mouse_event.pressed: | ||
mouse_up.emit() | ||
get_viewport().set_input_as_handled() | ||
## True to require that the mouse move outside of the component before | ||
## [signal drag_started] is emitted. | ||
@export var drag_outside: bool = false | ||
|
||
var _drag_start_position: Vector2 = Vector2.INF | ||
|
||
|
||
func _gui_input(event: InputEvent) -> void: | ||
# Watch for mouse clicks using _gui_input, so events are filtered based on | ||
# rules of the GUI system. | ||
|
||
if not event is InputEventMouseButton: | ||
return | ||
|
||
var button_event: InputEventMouseButton = event as InputEventMouseButton | ||
|
||
if button_event.button_index != MOUSE_BUTTON_LEFT: | ||
return | ||
|
||
if button_event.double_click: | ||
# Double click event (with the mouse released) has both pressed=true | ||
# and double_click=true, so ignore it as a special case. | ||
pass | ||
elif button_event.pressed: | ||
# Keep track of where the mouse click originated, but allow this | ||
# event to propagate to other nodes. | ||
_drag_start_position = event.global_position | ||
else: | ||
_drag_start_position = Vector2.INF | ||
|
||
|
||
func _input(event: InputEvent) -> void: | ||
# Watch for mouse movements using _input. This way, we receive mouse | ||
# movement events that occur outside of the component. | ||
|
||
if not event is InputEventMouseMotion: | ||
return | ||
|
||
if _drag_start_position == Vector2.INF: | ||
return | ||
|
||
var motion_event: InputEventMouseMotion = event as InputEventMouseMotion | ||
dbnicholson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if drag_outside and get_global_rect().has_point(motion_event.global_position): | ||
return | ||
|
||
if _drag_start_position.distance_to(motion_event.global_position) < Constants.MINIMUM_DRAG_THRESHOLD: | ||
return | ||
|
||
get_viewport().set_input_as_handled() | ||
drag_started.emit() | ||
_drag_start_position = Vector2.INF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.