scoop:scoop.ui:0.1.0
src/interaction/contact_taps.scoop
Selected production source · src/interaction/contact_taps.scoop
1
package scoop.ui3
import scoop.graphics.Point4
import scoop.math.hypot5
import scoop.surface.InputArea6
import scoop.time.Duration7
import scoop.window.*9
/** Only a completed tap can seed the next tap on the same mounted target. */10
internal class ContactTapSequence(val start: ContactPressSample, val interval: Duration)12
internal fun contactTapCount(13
area: InputArea,14
previous: ContactTapSequence?,15
value: ContactState,16
threshold: Double,17
interval: Duration18
): Int {19
val sequence = previous ?: return 120
val start = sequence.start21
if (start.contact.kind != value.kind || sequence.interval != interval)22
return 123
val elapsed = value.pointer.time.mark() - start.contact.pointer.time.mark()24
if (elapsed < Duration.ZERO || elapsed > interval)25
return 126
val first = start.contact.pointer.logicalPosition27
val next = value.pointer.logicalPosition28
if (hypot(next.x - first.x, next.y - first.y) > threshold)29
return 130
val origin = area.toLocal(Point(first.x, first.y)) ?: return 131
if (hypot(origin.x - start.position.x, origin.y - start.position.y) > threshold)32
return 133
return if (start.count < 3)34
start.count + 135
else36
337
}