diff options
| author | dam <dam@gudinoff> | 2022-03-04 00:07:40 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-03-04 00:07:40 +0000 |
| commit | 79cac2d7115e31987ff205b7b726b353014dd62b (patch) | |
| tree | 50ad0f8fbff58481cffb29da73b8ef2282cdf865 /touch_vertical_container/touch_vertical_container.gd | |
| parent | 9296ffd6ef1f8fcc1bbb12332fdc9480ff18c68b (diff) | |
| download | surgery-log-79cac2d7115e31987ff205b7b726b353014dd62b.tar.zst surgery-log-79cac2d7115e31987ff205b7b726b353014dd62b.zip | |
Improved touch scroll.
Diffstat (limited to 'touch_vertical_container/touch_vertical_container.gd')
| -rw-r--r-- | touch_vertical_container/touch_vertical_container.gd | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/touch_vertical_container/touch_vertical_container.gd b/touch_vertical_container/touch_vertical_container.gd index 07b8714..4633c64 100644 --- a/touch_vertical_container/touch_vertical_container.gd +++ b/touch_vertical_container/touch_vertical_container.gd @@ -1,11 +1,12 @@ extends ScrollContainer class_name TouchVerticalContainer -const POINTER_VELOCITY_DECAYING_FACTOR: float = 2.5 -const POINTER_VELOCITY_BOOST_FACTOR: float = 1.5 +const POINTER_VELOCITY_DECAYING_FACTOR: float = PI +const POINTER_VELOCITY_BOOST_FACTOR: float = 1.25 var is_pointer_dragging := false var pointer_drag_velocity := 0.0 +var when_last_dragged := 0 var exclude_controls := [] onready var controls = get_node("controls") @@ -34,6 +35,7 @@ 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") + sensor.connect("on_scroll", self, "pointer_input_on_scroll_handler") func _process(delta: float): @@ -53,13 +55,17 @@ func pointer_input_on_drag_handler(pointer: PointerInputSensor.PointerInputData) var reported_velocity_abs := abs(pointer.velocity.y) var relative_velocity := pointer.relative_position.y * Engine.get_frames_per_second() var relative_velocity_abs := abs(relative_velocity) - var max_velocity := pointer.velocity.y if reported_velocity_abs > relative_velocity_abs else relative_velocity - pointer_drag_velocity = max_velocity * POINTER_VELOCITY_BOOST_FACTOR + pointer_drag_velocity = pointer.velocity.y if reported_velocity_abs > relative_velocity_abs else relative_velocity self.scroll_vertical -= pointer.relative_position.y + when_last_dragged = OS.get_ticks_msec() func pointer_input_on_end_drag_handler(pointer: PointerInputSensor.PointerInputData): is_pointer_dragging = false + if OS.get_ticks_msec() - when_last_dragged > 20: + pointer_drag_velocity = 0.0 + else: + pointer_drag_velocity *= POINTER_VELOCITY_BOOST_FACTOR func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData): @@ -105,3 +111,8 @@ func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData break +func pointer_input_on_scroll_handler(pointer: PointerInputSensor.PointerInputData): + var target := self + target._gui_input(pointer.event) + + |
