aboutsummaryrefslogtreecommitdiff
path: root/date_picker/scroll_picker.gd
diff options
context:
space:
mode:
Diffstat (limited to 'date_picker/scroll_picker.gd')
-rw-r--r--date_picker/scroll_picker.gd28
1 files changed, 17 insertions, 11 deletions
diff --git a/date_picker/scroll_picker.gd b/date_picker/scroll_picker.gd
index ba70084..1d184b9 100644
--- a/date_picker/scroll_picker.gd
+++ b/date_picker/scroll_picker.gd
@@ -9,6 +9,10 @@ var pointer_id: int = -1
var start_pos: float = 0.0
var pos: float = 0.0
+var value_base_position: float
+var value_next_base_position: float
+var value_previous_base_position: float
+
func _ready():
pointer = {
@@ -20,19 +24,23 @@ func _ready():
is_active = false,
timestamp = 0
}
+ value_base_position = ($value as Label).rect_position.y
+ value_next_base_position = ($value_next as Label).rect_position.y
+ value_previous_base_position = ($value_previous as Label).rect_position.y
func _process(delta: float):
-# $label.text = "%s" % pointer.index
- pointer.velocity *= clamp((1.0 - 5.5 * delta), 0.0, 1.0) # pow(1.0-0.995, delta)
+
+ var max_value := 10
+ var scroll_unit_height := ($value as Label).rect_size.y
+
+ pointer.velocity *= clamp((1.0 - 5.5 * delta), 0.0, 1.0)
if pointer.is_active:
value = anchor + (pointer.current_position.y - pointer.initial_position.y)
elif is_zero_approx(pointer.velocity.y) == false:
value += pointer.velocity.y * delta
if abs(pointer.velocity.y) < 50.0:
- var max_value := 10
- var scroll_unit_height := 80
var normalized_value := -value / scroll_unit_height
var normalized_int_value := round(normalized_value) as int
var logic_value := fposmod(normalized_int_value, max_value)
@@ -43,24 +51,22 @@ func _process(delta: float):
# ($test as TextureRect).rect_global_position.y = value
# $debug.text = "value: %s\nvelocity: %s\n%s" % [value, pointer.velocity, pointer.relative]
var current_pos = value
- var turn_over := 800
+ var turn_over := scroll_unit_height * max_value
if current_pos >= turn_over || current_pos < 0.0:
value = fposmod(current_pos, turn_over)
# elif current_pos < 0:
# value = 800 - current_pos
- var max_value := 10
- var scroll_unit_height := 40
var normalized_value := -value / scroll_unit_height
var normalized_int_value := round(normalized_value) as int
var logic_value := fposmod(normalized_int_value, max_value)
var logic_next_value := fposmod(normalized_int_value + 1, max_value)
var logic_previous_value := fposmod(normalized_int_value - 1, max_value)
- var value_base_position := 140.0 # 180.0
- var value_next_base_position := 180.0 # 260.0
- var value_previous_base_position := 100.0
+# var value_base_position := ($value_previous as Label).rect_position.y # 140.0 # 180.0
+# var value_next_base_position := ($value_next as Label).rect_position.y #180.0 # 260.0
+# var value_previous_base_position := ($value as Label).rect_position.y #100.0
$value.text = "%d" % logic_value
$value_next.text = "%d" % logic_next_value
@@ -106,7 +112,7 @@ func _gui_input(event: InputEvent):
# if pointer.is_active == false:
# $output.text += "%10d: touch %d\n" % [abs(pointer.timestamp - time), touch.index]
- if event is InputEventScreenDrag: # && pointer.index == event.index:
+ if event is InputEventScreenDrag && event.index == pointer.index:
var drag := event as InputEventScreenDrag
pointer.current_position = drag.position
pointer.velocity = drag.speed