@@ -52,6 +52,10 @@ class TouchHandler(private val frameView: FrameView, private val dispatcher: Dis
52
52
return onHoverEvent(event) || handleStylusEvent(event) || handleMouseEvent(event)
53
53
}
54
54
55
+ fun onCapturedPointerEvent (event : MotionEvent ): Boolean {
56
+ return handleCapturedPointerEvent(event)
57
+ }
58
+
55
59
fun onHoverEvent (event : MotionEvent ): Boolean {
56
60
if (event.actionMasked == MotionEvent .ACTION_HOVER_MOVE ) {
57
61
lastHoverPoint = event.point()
@@ -102,6 +106,37 @@ class TouchHandler(private val frameView: FrameView, private val dispatcher: Dis
102
106
return ! (e.buttonState == 0 && e.getToolType(0 ) != MotionEvent .TOOL_TYPE_MOUSE )
103
107
}
104
108
109
+ private fun handleCapturedPointerEvent (e : MotionEvent ): Boolean {
110
+ if (Build .VERSION .SDK_INT < 26 )
111
+ return false
112
+
113
+ val screenDensity = frameView.context.resources.displayMetrics.density
114
+ val dx: Float
115
+ val dy: Float
116
+
117
+ if (e.isFromSource(InputDevice .SOURCE_MOUSE_RELATIVE )) {
118
+ dx = getTotalAxisValue(e, MotionEvent .AXIS_X ) * screenDensity
119
+ dy = getTotalAxisValue(e, MotionEvent .AXIS_Y ) * screenDensity
120
+ } else if (e.isFromSource(InputDevice .SOURCE_TOUCHPAD )) {
121
+ dx = getTotalAxisValue(e, MotionEvent .AXIS_RELATIVE_X )
122
+ dy = getTotalAxisValue(e, MotionEvent .AXIS_RELATIVE_Y )
123
+ } else
124
+ return false
125
+
126
+ when (e.actionMasked) {
127
+ MotionEvent .ACTION_BUTTON_PRESS -> dispatcher.onCapturedMouseButtonDown(convertButton(e.actionButton))
128
+ MotionEvent .ACTION_BUTTON_RELEASE -> dispatcher.onCapturedMouseButtonUp(convertButton(e.actionButton))
129
+ MotionEvent .ACTION_MOVE -> dispatcher.onCapturedMouseMove(dx, dy)
130
+ MotionEvent .ACTION_SCROLL -> {
131
+ val hs = e.getAxisValue(MotionEvent .AXIS_HSCROLL )
132
+ val vs = e.getAxisValue(MotionEvent .AXIS_VSCROLL )
133
+ dispatcher.onCapturedMouseScroll(hs, vs)
134
+ }
135
+ else -> return false
136
+ }
137
+ return true
138
+ }
139
+
105
140
/* *
106
141
* Convert from [MotionEvent] button to [PointerButton]
107
142
*/
@@ -112,6 +147,17 @@ class TouchHandler(private val frameView: FrameView, private val dispatcher: Dis
112
147
else -> PointerButton .None
113
148
}
114
149
150
+ /* *
151
+ * Returns value of given axis, added with historical values of the axis
152
+ */
153
+ private fun getTotalAxisValue (e : MotionEvent , axis : Int ): Float {
154
+ var v = e.getAxisValue(axis)
155
+ repeat(e.historySize) {
156
+ v + = e.getHistoricalAxisValue(axis, it)
157
+ }
158
+ return v
159
+ }
160
+
115
161
116
162
/* ***************************************************************************************
117
163
* Stylus
0 commit comments