14
14
// by masking bits from the `Source`.
15
15
16
16
use num_enum:: { IntoPrimitive , TryFromPrimitive } ;
17
- use std:: { convert:: TryInto , ops :: Deref } ;
17
+ use std:: convert:: TryInto ;
18
18
19
19
use crate :: game_activity:: ffi:: { GameActivityKeyEvent , GameActivityMotionEvent } ;
20
20
use crate :: input:: { Class , Source } ;
@@ -114,14 +114,6 @@ pub struct MotionEvent<'a> {
114
114
ga_event : & ' a GameActivityMotionEvent ,
115
115
}
116
116
117
- impl < ' a > Deref for MotionEvent < ' a > {
118
- type Target = GameActivityMotionEvent ;
119
-
120
- fn deref ( & self ) -> & Self :: Target {
121
- self . ga_event
122
- }
123
- }
124
-
125
117
/// A motion action.
126
118
///
127
119
/// See [the NDK
@@ -295,7 +287,7 @@ impl<'a> MotionEvent<'a> {
295
287
///
296
288
#[ inline]
297
289
pub fn source ( & self ) -> Source {
298
- let source = self . source as u32 ;
290
+ let source = self . ga_event . source as u32 ;
299
291
source. try_into ( ) . unwrap_or ( Source :: Unknown )
300
292
}
301
293
@@ -310,15 +302,15 @@ impl<'a> MotionEvent<'a> {
310
302
///
311
303
#[ inline]
312
304
pub fn device_id ( & self ) -> i32 {
313
- self . deviceId
305
+ self . ga_event . deviceId
314
306
}
315
307
316
308
/// Returns the motion action associated with the event.
317
309
///
318
310
/// See [the MotionEvent docs](https://developer.android.com/reference/android/view/MotionEvent#getActionMasked())
319
311
#[ inline]
320
312
pub fn action ( & self ) -> MotionAction {
321
- let action = self . action as u32 & ndk_sys:: AMOTION_EVENT_ACTION_MASK ;
313
+ let action = self . ga_event . action as u32 & ndk_sys:: AMOTION_EVENT_ACTION_MASK ;
322
314
action. try_into ( ) . unwrap ( )
323
315
}
324
316
@@ -327,12 +319,12 @@ impl<'a> MotionEvent<'a> {
327
319
/// Pointer indices can change per motion event. For an identifier that stays the same, see
328
320
/// [`Pointer::pointer_id()`].
329
321
///
330
- /// This only has a meaning when the [action](Self ::action) is one of [`Up`](MotionAction::Up),
322
+ /// This only has a meaning when the [action](self ::action) is one of [`Up`](MotionAction::Up),
331
323
/// [`Down`](MotionAction::Down), [`PointerUp`](MotionAction::PointerUp),
332
324
/// or [`PointerDown`](MotionAction::PointerDown).
333
325
#[ inline]
334
326
pub fn pointer_index ( & self ) -> usize {
335
- let action = self . action as u32 ;
327
+ let action = self . ga_event . action as u32 ;
336
328
let index = ( action & ndk_sys:: AMOTION_EVENT_ACTION_POINTER_INDEX_MASK )
337
329
>> ndk_sys:: AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT ;
338
330
index as usize
@@ -345,8 +337,8 @@ impl<'a> MotionEvent<'a> {
345
337
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getpointerid)
346
338
// TODO: look at output with out-of-range pointer index
347
339
// Probably -1 though
348
- pub fn pointer_id_for(&self, pointer_index: usize) -> i32 {
349
- unsafe { ndk_sys::AMotionEvent_getPointerId(self.ptr.as_ptr(), pointer_index) }
340
+ pub fn pointer_id_for(&self.ga_event , pointer_index: usize) -> i32 {
341
+ unsafe { ndk_sys::AMotionEvent_getPointerId(self.ga_event. ptr.as_ptr(), pointer_index) }
350
342
}
351
343
*/
352
344
@@ -355,7 +347,7 @@ impl<'a> MotionEvent<'a> {
355
347
/// See [the MotionEvent docs](https://developer.android.com/reference/android/view/MotionEvent#getPointerCount())
356
348
#[ inline]
357
349
pub fn pointer_count ( & self ) -> usize {
358
- self . pointerCount as usize
350
+ self . ga_event . pointerCount as usize
359
351
}
360
352
361
353
/// An iterator over the pointers in this motion event
@@ -370,7 +362,7 @@ impl<'a> MotionEvent<'a> {
370
362
371
363
/// The pointer at a given pointer index. Panics if the pointer index is out of bounds.
372
364
///
373
- /// If you need to loop over all the pointers, prefer the [`pointers()`](Self ::pointers) method.
365
+ /// If you need to loop over all the pointers, prefer the [`pointers()`](self ::pointers) method.
374
366
#[ inline]
375
367
pub fn pointer_at_index ( & self , index : usize ) -> Pointer < ' _ > {
376
368
if index >= self . pointer_count ( ) {
@@ -386,14 +378,14 @@ impl<'a> MotionEvent<'a> {
386
378
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_gethistorysize)
387
379
#[inline]
388
380
pub fn history_size(&self) -> usize {
389
- unsafe { ndk_sys::AMotionEvent_getHistorySize(self.ptr.as_ptr()) as usize }
381
+ unsafe { ndk_sys::AMotionEvent_getHistorySize(self.ga_event. ptr.as_ptr()) as usize }
390
382
}
391
383
392
384
/// An iterator over the historical events contained in this event.
393
385
#[inline]
394
386
pub fn history(&self) -> HistoricalMotionEventsIter<'_> {
395
387
HistoricalMotionEventsIter {
396
- event: self.ptr,
388
+ event: self.ga_event. ptr,
397
389
next_history_index: 0,
398
390
history_size: self.history_size(),
399
391
_marker: std::marker::PhantomData,
@@ -407,7 +399,7 @@ impl<'a> MotionEvent<'a> {
407
399
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getmetastate)
408
400
#[ inline]
409
401
pub fn meta_state ( & self ) -> MetaState {
410
- MetaState ( self . metaState as u32 )
402
+ MetaState ( self . ga_event . metaState as u32 )
411
403
}
412
404
413
405
/// Returns the button state during this event, as a bitfield.
@@ -416,7 +408,7 @@ impl<'a> MotionEvent<'a> {
416
408
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getbuttonstate)
417
409
#[ inline]
418
410
pub fn button_state ( & self ) -> ButtonState {
419
- ButtonState ( self . buttonState as u32 )
411
+ ButtonState ( self . ga_event . buttonState as u32 )
420
412
}
421
413
422
414
/// Returns the time of the start of this gesture, in the `java.lang.System.nanoTime()` time
@@ -426,7 +418,7 @@ impl<'a> MotionEvent<'a> {
426
418
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getdowntime)
427
419
#[ inline]
428
420
pub fn down_time ( & self ) -> i64 {
429
- self . downTime
421
+ self . ga_event . downTime
430
422
}
431
423
432
424
/// Returns a bitfield indicating which edges were touched by this event.
@@ -435,7 +427,7 @@ impl<'a> MotionEvent<'a> {
435
427
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getedgeflags)
436
428
#[ inline]
437
429
pub fn edge_flags ( & self ) -> EdgeFlags {
438
- EdgeFlags ( self . edgeFlags as u32 )
430
+ EdgeFlags ( self . ga_event . edgeFlags as u32 )
439
431
}
440
432
441
433
/// Returns the time of this event, in the `java.lang.System.nanoTime()` time base
@@ -444,7 +436,7 @@ impl<'a> MotionEvent<'a> {
444
436
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_geteventtime)
445
437
#[ inline]
446
438
pub fn event_time ( & self ) -> i64 {
447
- self . eventTime
439
+ self . ga_event . eventTime
448
440
}
449
441
450
442
/// The flags associated with a motion event.
@@ -453,7 +445,7 @@ impl<'a> MotionEvent<'a> {
453
445
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getflags)
454
446
#[ inline]
455
447
pub fn flags ( & self ) -> MotionEventFlags {
456
- MotionEventFlags ( self . flags as u32 )
448
+ MotionEventFlags ( self . ga_event . flags as u32 )
457
449
}
458
450
459
451
/* Missing from GameActivity currently...
@@ -462,17 +454,17 @@ impl<'a> MotionEvent<'a> {
462
454
/// See [the NDK
463
455
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getxoffset)
464
456
#[inline]
465
- pub fn x_offset(&self) -> f32 {
466
- self.x_offset
457
+ pub fn x_offset(&self.ga_event ) -> f32 {
458
+ self.ga_event. x_offset
467
459
}
468
460
469
461
/// Returns the offset in the y direction between the coordinates and the raw coordinates
470
462
///
471
463
/// See [the NDK
472
464
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getyoffset)
473
465
#[inline]
474
- pub fn y_offset(&self) -> f32 {
475
- self.y_offset
466
+ pub fn y_offset(&self.ga_event ) -> f32 {
467
+ self.ga_event. y_offset
476
468
}
477
469
*/
478
470
@@ -482,7 +474,7 @@ impl<'a> MotionEvent<'a> {
482
474
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getxprecision)
483
475
#[ inline]
484
476
pub fn x_precision ( & self ) -> f32 {
485
- self . precisionX
477
+ self . ga_event . precisionX
486
478
}
487
479
488
480
/// Returns the precision of the y value of the coordinates
@@ -491,7 +483,7 @@ impl<'a> MotionEvent<'a> {
491
483
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getyprecision)
492
484
#[ inline]
493
485
pub fn y_precision ( & self ) -> f32 {
494
- self . precisionY
486
+ self . ga_event . precisionY
495
487
}
496
488
}
497
489
@@ -510,13 +502,13 @@ impl<'a> Pointer<'a> {
510
502
511
503
#[ inline]
512
504
pub fn pointer_id ( & self ) -> i32 {
513
- let pointer = & self . event . pointers [ self . index ] ;
505
+ let pointer = & self . event . ga_event . pointers [ self . index ] ;
514
506
pointer. id
515
507
}
516
508
517
509
#[ inline]
518
510
pub fn axis_value ( & self , axis : Axis ) -> f32 {
519
- let pointer = & self . event . pointers [ self . index ] ;
511
+ let pointer = & self . event . ga_event . pointers [ self . index ] ;
520
512
pointer. axisValues [ axis as u32 as usize ]
521
513
}
522
514
@@ -532,13 +524,13 @@ impl<'a> Pointer<'a> {
532
524
533
525
#[ inline]
534
526
pub fn raw_x ( & self ) -> f32 {
535
- let pointer = & self . event . pointers [ self . index ] ;
527
+ let pointer = & self . event . ga_event . pointers [ self . index ] ;
536
528
pointer. rawX
537
529
}
538
530
539
531
#[ inline]
540
532
pub fn raw_y ( & self ) -> f32 {
541
- let pointer = & self . event . pointers [ self . index ] ;
533
+ let pointer = & self . event . ga_event . pointers [ self . index ] ;
542
534
pointer. rawY
543
535
}
544
536
@@ -579,7 +571,7 @@ impl<'a> Pointer<'a> {
579
571
580
572
#[ inline]
581
573
pub fn tool_type ( & self ) -> ToolType {
582
- let pointer = & self . event . pointers [ self . index ] ;
574
+ let pointer = & self . event . ga_event . pointers [ self . index ] ;
583
575
let tool_type = pointer. toolType as u32 ;
584
576
tool_type. try_into ( ) . unwrap ( )
585
577
}
@@ -937,14 +929,6 @@ pub struct KeyEvent<'a> {
937
929
ga_event : & ' a GameActivityKeyEvent ,
938
930
}
939
931
940
- impl < ' a > Deref for KeyEvent < ' a > {
941
- type Target = GameActivityKeyEvent ;
942
-
943
- fn deref ( & self ) -> & Self :: Target {
944
- self . ga_event
945
- }
946
- }
947
-
948
932
/// Key actions.
949
933
///
950
934
/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-27)
@@ -1262,7 +1246,7 @@ impl<'a> KeyEvent<'a> {
1262
1246
///
1263
1247
#[ inline]
1264
1248
pub fn source ( & self ) -> Source {
1265
- let source = self . source as u32 ;
1249
+ let source = self . ga_event . source as u32 ;
1266
1250
source. try_into ( ) . unwrap_or ( Source :: Unknown )
1267
1251
}
1268
1252
@@ -1277,15 +1261,15 @@ impl<'a> KeyEvent<'a> {
1277
1261
///
1278
1262
#[ inline]
1279
1263
pub fn device_id ( & self ) -> i32 {
1280
- self . deviceId
1264
+ self . ga_event . deviceId
1281
1265
}
1282
1266
1283
1267
/// Returns the key action associated with the event.
1284
1268
///
1285
1269
/// See [the KeyEvent docs](https://developer.android.com/reference/android/view/KeyEvent#getAction())
1286
1270
#[ inline]
1287
1271
pub fn action ( & self ) -> KeyAction {
1288
- let action = self . action as u32 ;
1272
+ let action = self . ga_event . action as u32 ;
1289
1273
action. try_into ( ) . unwrap ( )
1290
1274
}
1291
1275
@@ -1296,7 +1280,7 @@ impl<'a> KeyEvent<'a> {
1296
1280
/// docs](https://developer.android.com/ndk/reference/group/input#akeyevent_getdowntime)
1297
1281
#[ inline]
1298
1282
pub fn down_time ( & self ) -> i64 {
1299
- self . downTime
1283
+ self . ga_event . downTime
1300
1284
}
1301
1285
1302
1286
/// Returns the time this event occured. This is on the scale of
@@ -1306,7 +1290,7 @@ impl<'a> KeyEvent<'a> {
1306
1290
/// docs](https://developer.android.com/ndk/reference/group/input#akeyevent_geteventtime)
1307
1291
#[ inline]
1308
1292
pub fn event_time ( & self ) -> i64 {
1309
- self . eventTime
1293
+ self . ga_event . eventTime
1310
1294
}
1311
1295
1312
1296
/// Returns the keycode associated with this key event
@@ -1315,7 +1299,7 @@ impl<'a> KeyEvent<'a> {
1315
1299
/// docs](https://developer.android.com/ndk/reference/group/input#akeyevent_getkeycode)
1316
1300
#[ inline]
1317
1301
pub fn key_code ( & self ) -> Keycode {
1318
- let keycode = self . keyCode as u32 ;
1302
+ let keycode = self . ga_event . keyCode as u32 ;
1319
1303
keycode. try_into ( ) . unwrap_or ( Keycode :: Unknown )
1320
1304
}
1321
1305
@@ -1325,7 +1309,7 @@ impl<'a> KeyEvent<'a> {
1325
1309
/// docs](https://developer.android.com/ndk/reference/group/input#akeyevent_getrepeatcount)
1326
1310
#[ inline]
1327
1311
pub fn repeat_count ( & self ) -> i32 {
1328
- self . repeatCount
1312
+ self . ga_event . repeatCount
1329
1313
}
1330
1314
1331
1315
/// Returns the hardware keycode of a key. This varies from device to device.
@@ -1334,7 +1318,7 @@ impl<'a> KeyEvent<'a> {
1334
1318
/// docs](https://developer.android.com/ndk/reference/group/input#akeyevent_getscancode)
1335
1319
#[ inline]
1336
1320
pub fn scan_code ( & self ) -> i32 {
1337
- self . scanCode
1321
+ self . ga_event . scanCode
1338
1322
}
1339
1323
}
1340
1324
@@ -1397,7 +1381,7 @@ impl<'a> KeyEvent<'a> {
1397
1381
/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#akeyevent_getflags)
1398
1382
#[ inline]
1399
1383
pub fn flags ( & self ) -> KeyEventFlags {
1400
- KeyEventFlags ( self . flags as u32 )
1384
+ KeyEventFlags ( self . ga_event . flags as u32 )
1401
1385
}
1402
1386
1403
1387
/// Returns the state of the modifiers during this key event, represented by a bitmask.
@@ -1406,6 +1390,6 @@ impl<'a> KeyEvent<'a> {
1406
1390
/// docs](https://developer.android.com/ndk/reference/group/input#akeyevent_getmetastate)
1407
1391
#[ inline]
1408
1392
pub fn meta_state ( & self ) -> MetaState {
1409
- MetaState ( self . metaState as u32 )
1393
+ MetaState ( self . ga_event . metaState as u32 )
1410
1394
}
1411
1395
}
0 commit comments