Scoop API

scoop:scoop.ui:0.1.0

src/interaction/contact_taps.scoop

Selected production source · src/interaction/contact_taps.scoop

1package scoop.ui
3import scoop.graphics.Point
4import scoop.math.hypot
5import scoop.surface.InputArea
6import scoop.time.Duration
7import scoop.window.*
9/** Only a completed tap can seed the next tap on the same mounted target. */
10internal class ContactTapSequence(val start: ContactPressSample, val interval: Duration)
12internal fun contactTapCount(
13 area: InputArea,
14 previous: ContactTapSequence?,
15 value: ContactState,
16 threshold: Double,
17 interval: Duration
18): Int {
19 val sequence = previous ?: return 1
20 val start = sequence.start
21 if (start.contact.kind != value.kind || sequence.interval != interval)
22 return 1
23 val elapsed = value.pointer.time.mark() - start.contact.pointer.time.mark()
24 if (elapsed < Duration.ZERO || elapsed > interval)
25 return 1
26 val first = start.contact.pointer.logicalPosition
27 val next = value.pointer.logicalPosition
28 if (hypot(next.x - first.x, next.y - first.y) > threshold)
29 return 1
30 val origin = area.toLocal(Point(first.x, first.y)) ?: return 1
31 if (hypot(origin.x - start.position.x, origin.y - start.position.y) > threshold)
32 return 1
33 return if (start.count < 3)
34 start.count + 1
35 else
36 3