aboutsummaryrefslogtreecommitdiff
path: root/touch_item_list
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-01-10 17:56:30 +0000
committerdam <dam@gudinoff>2022-01-10 17:56:30 +0000
commit81b602620412fbad0429e841051c30c537a1b461 (patch)
tree780bf47204aa13e41bd5c22e527f7c69f05e5bcc /touch_item_list
parent5ba40857cdc770841d216a27e2a9e8bb3ebf3186 (diff)
downloadsurgery-log-81b602620412fbad0429e841051c30c537a1b461.tar.zst
surgery-log-81b602620412fbad0429e841051c30c537a1b461.zip
Split touch logic from stage
Diffstat (limited to 'touch_item_list')
-rw-r--r--touch_item_list/touch_item_list.gd96
-rw-r--r--touch_item_list/touch_item_list.tscn2
2 files changed, 50 insertions, 48 deletions
diff --git a/touch_item_list/touch_item_list.gd b/touch_item_list/touch_item_list.gd
index d2d0d37..0534bb2 100644
--- a/touch_item_list/touch_item_list.gd
+++ b/touch_item_list/touch_item_list.gd
@@ -6,16 +6,16 @@ const POINTER_VELOCITY_DECAYING_FACTOR: float = 2.5
var is_pointer_dragging := false
var pointer_drag_velocity := 0.0
-onready var drag_sensor := get_node("drag_sensor") as PointerInputSensor
+onready var sensor := get_node("sensor") as PointerInputSensor
onready var v_scroll_bar := get_v_scroll() as ScrollBar
func _ready():
- drag_sensor.connect("on_press", self, "pointer_input_handler")
- drag_sensor.connect("on_drag", self, "pointer_input_handler")
- drag_sensor.connect("on_end_drag", self, "pointer_input_handler")
- drag_sensor.connect("on_click", self, "pointer_input_handler")
- drag_sensor.connect("on_scroll", self, "pointer_input_handler")
+ 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")
+ sensor.connect("on_scroll", self, "pointer_input_on_scroll_handler")
func _process(delta: float):
@@ -25,46 +25,48 @@ func _process(delta: float):
v_scroll_bar.value -= pointer_drag_velocity * delta
-func pointer_input_handler(pointer: PointerInputSensor.PointerInputData):
- match pointer.action:
- PointerInputSensor.PointerInputAction.ON_PRESS:
- is_pointer_dragging = true
-
- PointerInputSensor.PointerInputAction.ON_DRAG:
- is_pointer_dragging = true
- pointer_drag_velocity = pointer.velocity.y
- v_scroll_bar.value -= pointer.relative_position.y
-
- PointerInputSensor.PointerInputAction.ON_END_DRAG:
- is_pointer_dragging = false
-
- PointerInputSensor.PointerInputAction.ON_SCROLL:
- var target := self
- target._gui_input(pointer.event)
-
- PointerInputSensor.PointerInputAction.ON_CLICK:
- var target := self
- var position := target.get_global_mouse_position() - target.rect_global_position
-
- var event_touch := InputEventScreenTouch.new()
- event_touch.index = 0
- event_touch.position = position
-
- var event_mouse := InputEventMouseButton.new()
- event_mouse.button_index = BUTTON_LEFT
- event_mouse.button_mask = BUTTON_MASK_LEFT
- event_mouse.position = position
-
- event_mouse.pressed = true
- event_touch.pressed = true
- target._gui_input(event_mouse)
- target._gui_input(event_touch)
-
- target.grab_focus()
-
- event_mouse.pressed = false
- event_touch.pressed = false
- target._gui_input(event_mouse)
- target._gui_input(event_touch)
+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
+ v_scroll_bar.value -= 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 := self
+ var position := target.get_global_mouse_position() - target.rect_global_position
+
+ var event_touch := InputEventScreenTouch.new()
+ event_touch.index = 0
+ event_touch.position = position
+
+ var event_mouse := InputEventMouseButton.new()
+ event_mouse.button_index = BUTTON_LEFT
+ event_mouse.button_mask = BUTTON_MASK_LEFT
+ event_mouse.position = position
+
+ event_mouse.pressed = true
+ event_touch.pressed = true
+ target._gui_input(event_mouse)
+ target._gui_input(event_touch)
+
+ target.grab_focus()
+
+ event_mouse.pressed = false
+ event_touch.pressed = false
+ target._gui_input(event_mouse)
+ target._gui_input(event_touch)
+
+
+func pointer_input_on_scroll_handler(pointer: PointerInputSensor.PointerInputData):
+ var target := self
+ target._gui_input(pointer.event)
diff --git a/touch_item_list/touch_item_list.tscn b/touch_item_list/touch_item_list.tscn
index 6022ed4..6207e7d 100644
--- a/touch_item_list/touch_item_list.tscn
+++ b/touch_item_list/touch_item_list.tscn
@@ -13,7 +13,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="drag_sensor" type="Control" parent="."]
+[node name="sensor" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -8.0