diff options
Diffstat (limited to 'touch_vertical_container/touch_vertical_container.gd')
| -rw-r--r-- | touch_vertical_container/touch_vertical_container.gd | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/touch_vertical_container/touch_vertical_container.gd b/touch_vertical_container/touch_vertical_container.gd index 7c2ba84..1a7236c 100644 --- a/touch_vertical_container/touch_vertical_container.gd +++ b/touch_vertical_container/touch_vertical_container.gd @@ -26,9 +26,6 @@ func _ready(): sensor.connect("on_drag", self, "pointer_input_on_drag_handler") sensor.connect("on_end_drag", self, "pointer_input_on_end_drag_handler") sensor.connect("on_click", self, "pointer_input_on_click_handler") - -# it.connect("focus_entered", sensor, "set_visible", [false]) -# it.connect("focus_exited", sensor, "set_visible", [true]) func _process(delta: float): @@ -54,33 +51,45 @@ func pointer_input_on_end_drag_handler(pointer: PointerInputSensor.PointerInputD func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData): - propagate_click(pointer.target.get_parent(), pointer) - - -# @DAM Maybe replace this with a stack of next items to process approach. -func propagate_click(control: Control, pointer: PointerInputSensor.PointerInputData) -> bool: - if control is PointerInputSensor || control.mouse_filter == MOUSE_FILTER_IGNORE || control.visible == false: - return false - var click_processed := false - if control.get_global_rect().has_point(pointer.current_position): - var children = control.get_children() - children.invert() # @DAM Use inverted index for loop to avoid invert() operation. - for child in children: - if child is Control: - click_processed = click_processed || propagate_click(child, pointer) - if click_processed == true: - break - - if click_processed == false: - if control is CheckBox || control is CheckButton: - control.pressed = !control.pressed - control.grab_focus() - control.emit_signal("button_down") - control.emit_signal("pressed") - control.emit_signal("button_up") - click_processed = true - pointer.target.visible = false - control.connect("focus_exited", pointer.target, "set_visible", [true]) + # Get last leaf node. + var root := pointer.target.get_parent() as Control + var leaf := root as Node + while leaf.get_child_count() > 0: + leaf = leaf.get_child(leaf.get_child_count() - 1) - return click_processed + # Navigate backwards from leaf to root until we find a node accepting the input. + var tried_leaf_as_root := false + while leaf != root || tried_leaf_as_root == false: + tried_leaf_as_root = leaf == root # Allow a final iteration cycle when leaf reaches root. + var node := leaf + + if node is PointerInputSensor \ + || node is Control == false \ + || node.mouse_filter == MOUSE_FILTER_IGNORE \ + || node.visible == false \ + || node.get_global_rect().has_point(pointer.current_position) == false: + # Get next node to be processed. + var leaf_index_in_parent := leaf.get_position_in_parent() + var parent := leaf.get_parent() + if leaf_index_in_parent == 0: + leaf = parent + else: + leaf = parent.get_child(leaf_index_in_parent - 1) + # Drill down into the new tree branch. + while leaf.get_child_count() > 0: + leaf = leaf.get_child(leaf.get_child_count() - 1) + continue + + var control: Control = node + if control is CheckBox || control is CheckButton: + control.pressed = !control.pressed + + control.grab_focus() + control.emit_signal("button_down") + control.emit_signal("pressed") + control.emit_signal("button_up") + control.connect("focus_exited", pointer.target, "set_visible", [true], CONNECT_ONESHOT) + pointer.target.visible = false + break + |
