diff options
| author | dam <dam@gudinoff> | 2022-01-02 03:04:48 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-01-02 03:04:48 +0000 |
| commit | 88f355c29987c39b01727a08d3dfef8a312bd9ec (patch) | |
| tree | 5559d27940295dff1cf24399e992bf19f389d411 /pointer_input_sensor.gd | |
| parent | c59f89e99c90c0e756cdf780bcbf04d782eb3e6f (diff) | |
| download | surgery-log-88f355c29987c39b01727a08d3dfef8a312bd9ec.tar.zst surgery-log-88f355c29987c39b01727a08d3dfef8a312bd9ec.zip | |
Implement scroll by dragging on database and stage screens.
Diffstat (limited to 'pointer_input_sensor.gd')
| -rw-r--r-- | pointer_input_sensor.gd | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/pointer_input_sensor.gd b/pointer_input_sensor.gd index 95e1b4b..27f257c 100644 --- a/pointer_input_sensor.gd +++ b/pointer_input_sensor.gd @@ -1,8 +1,7 @@ extends Control class_name PointerInputSensor -export var drag_threshold_cm: float = 0.250 - +# All on_ACTION signals have a single argument of type PointerInputData. signal on_press signal on_release #signal on_release_outside @@ -14,19 +13,35 @@ signal on_begin_drag signal on_drag signal on_end_drag +enum PointerInputAction { + UNDEFINED, + ON_PRESS, + ON_RELEASE, +# ON_RELEASE_OUTSIDE, + ON_CLICK, + ON_ENTER, + ON_EXIT, +# ON_EXIT_APP_WINDOW, + ON_BEGIN_DRAG, + ON_DRAG, + ON_END_DRAG, +} + class PointerInputData: var target: PointerInputSensor var index := -1 var initial_position := Vector2.ZERO var current_position := Vector2.ZERO - var relative_position = Vector2.ZERO + var relative_position := Vector2.ZERO var velocity := Vector2.ZERO var was_dragged := false var is_pressed := false + var action: int = PointerInputAction.UNDEFINED + +export var drag_threshold_cm: float = 0.250 var pointer: PointerInputData var screen_dpcm: float -var on_process: FuncRef func _ready(): @@ -37,12 +52,8 @@ func _ready(): connect("mouse_entered", self, "_on_enter_exit", [false]) -func _process(delta: float): - if on_process != null && on_process.is_valid(): - on_process.call_func(delta, self) - - func _on_enter_exit(is_inside: bool): + pointer.action = PointerInputAction.ON_ENTER if is_inside else PointerInputAction.ON_EXIT emit_signal("on_enter" if is_inside else "on_exit", pointer) @@ -60,12 +71,16 @@ func _gui_input(event: InputEvent): if pointer.is_pressed: pointer.index = touch.index pointer.initial_position = get_global_mouse_position() + pointer.action = PointerInputAction.ON_PRESS emit_signal("on_press", pointer) else: + pointer.action = PointerInputAction.ON_RELEASE emit_signal("on_release", pointer) if pointer.was_dragged == false: + pointer.action = PointerInputAction.ON_CLICK emit_signal("on_click", pointer) else: + pointer.action = PointerInputAction.ON_END_DRAG emit_signal("on_end_drag", pointer) pointer.index = -1 pointer.was_dragged = false @@ -75,10 +90,11 @@ func _gui_input(event: InputEvent): pointer.current_position = get_global_mouse_position() pointer.velocity = drag.speed pointer.relative_position = drag.relative - # @DAM Instead of constantly converting the pointer distance to cm... just conver the drag_threshold_cm to pixels - if pointer.was_dragged == false && pointer.current_position.distance_to(pointer.initial_position) / screen_dpcm > drag_threshold_cm: + if pointer.was_dragged == false && pointer.current_position.distance_to(pointer.initial_position) > drag_threshold_cm * screen_dpcm: pointer.was_dragged = true + pointer.action = PointerInputAction.ON_BEGIN_DRAG emit_signal("on_begin_drag", pointer) + pointer.action = PointerInputAction.ON_DRAG emit_signal("on_drag", pointer) |
