1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
extends ScrollContainer
class_name TouchVerticalContainer
const POINTER_VELOCITY_DECAYING_FACTOR: float = 2.5
var is_pointer_dragging := false
var pointer_drag_velocity := 0.0
var exclude_controls := []
func _ready():
for it in get_node("controls").get_children():
it = it as Control
if exclude_controls.has(it.name):
continue
var sensor = PointerInputSensor.new()
it.add_child(sensor)
sensor.name = "sensor"
sensor.anchor_right = 1.0
sensor.anchor_bottom = 1.0
sensor.connect("on_press", self, "pointer_input_on_press_handler")
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_mouse_filter", [Control.MOUSE_FILTER_IGNORE])
it.connect("focus_entered", sensor, "mouse_default_cursor_shape", [Control.CURSOR_IBEAM])
it.connect("focus_exited", sensor, "set_mouse_filter", [Control.MOUSE_FILTER_STOP])
it.connect("focus_exited", sensor, "mouse_default_cursor_shape", [Control.CURSOR_ARROW])
if it is LineEdit:
it.connect("focus_exited", it, "deselect")
func _process(delta: float):
# Apply drag movement inertia.
if is_pointer_dragging == false && abs(pointer_drag_velocity) > 0.5:
pointer_drag_velocity *= clamp((1.0 - POINTER_VELOCITY_DECAYING_FACTOR * delta), 0.0, 1.0)
self.scroll_vertical -= pointer_drag_velocity * delta
func pointer_input_on_press_handler(pointer: PointerInputSensor.PointerInputData):
is_pointer_dragging = true
func pointer_input_on_drag_handler(pointer: PointerInputSensor.PointerInputData):
is_pointer_dragging = true
pointer_drag_velocity = pointer.velocity.y
self.scroll_vertical -= pointer.relative_position.y
func pointer_input_on_end_drag_handler(pointer: PointerInputSensor.PointerInputData):
is_pointer_dragging = false
func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData):
var target: Control = pointer.target.get_parent()
var position := target.get_global_mouse_position()
target.grab_focus()
var button: Button
if target is Button:
button = target
elif target.get_node("auto") is Button:
button = target.get_node("auto")
if button != null && button.get_global_rect().has_point(position):
if button is CheckBox || button is CheckButton:
button.pressed = !button.pressed
button.emit_signal("button_down")
button.emit_signal("pressed")
button.emit_signal("button_up")
|