Scoop API

scoop:scoop.window:0.1.0

src/native/input/contacts.scoop

Selected production source · src/native/input/contacts.scoop

1package scoop.window
3@CLayout
4internal struct NativeContactData(
5 val id: Long,
6 val device: Long,
7 val modifiers: Long,
8 val kind: Int,
9 val phase: Int,
10 val cancelReason: Int,
11 val hasDevice: Int,
12 val hasPressure: Int,
13 val x: Double,
14 val y: Double,
15 val physicalX: Double,
16 val physicalY: Double,
17 val scale: Double,
18 val pressure: Double
21@Extern(name = "scoop_window_event_contact")
22internal fun nativeEventContact(event: Ptr<Unit>): NativeContactData
24internal fun copyContactEvent(header: NativeEventHeader, data: NativeContactData): ContactEvent {
25 val id = ContactId(data.id)
26 val time = copyInputTime(header)
27 if (data.phase == 3)
28 return ContactEvent.Cancelled(id, copyPointerCancelReason(data.cancelReason), time)
29 val kind =
30 when (data.kind) {
31 0 -> ContactKind.Touch
32 1 -> ContactKind.Pen
33 else -> throw WindowException(
34 "unknown native contact kind",
35 WindowErrorKind.NativeFailure
36 )
37 }
38 val pointer =
39 PointerState(
40 LogicalPosition(data.x, data.y),
41 PhysicalPosition(data.physicalX, data.physicalY),
42 data.scale,
43 platformModifiers(data.modifiers),
44 time,
45 if (data.hasDevice != 0)
46 Some(DeviceId(data.device))
47 else
48 None
49 )
50 val value =
51 ContactState(
52 id,
53 kind,
54 pointer,
55 if (data.hasPressure != 0)
56 Some(data.pressure)
57 else
58 None
59 )
60 return when (data.phase) {
61 0 -> ContactEvent.Began(value)
62 1 -> ContactEvent.Moved(value)
63 2 -> ContactEvent.Ended(value)
64 else -> throw WindowException("unknown native contact phase", WindowErrorKind.NativeFailure)
65 }